I'm trying to write a function that normalizes features (between 0 and 1) in a dataset. I want to iterate through all the features and replace values as I normalize them. Normalization works well, but I'm unable to overwrite the previous value.
Data.prototype.normalize = function(dataset) {
// Get the extent for each feature
for (var feature = 0; feature < this.featureCount; feature++) {
var extent = this.getExtent(feature, dataset),
min = extent[0],
max = extent[1];
// uses extent to normalize feature for all companies
for (var company = 0; company < this.companies.length; company++) {
var value = this.companies[company][dataset][feature],
normalized = this.normalizeValue(value, min, max);
value = normalized;
}
}
}
It all fails at
value = normalized;
If I console.log(value) after overwriting it everything seems to work, but only within the scope of the function. Outside of this scope the original value remains.
data.companies[n] = { features : [1, 2, 3, 4, 5], other properties... }
Here is an example of the feature array within my main object.
Any thoughts on how to fix this?
Thank you!