Normalizing Data Using Javascript
<p>I have multiple arrays of size 262144, and I am trying to use the following code to set all the values of each array to between 0 and 1, inclusive. To be clear, each array will be normalized differently because each has different values.</p>

<pre><code>var i;
var max = Number.MIN_VALUE;
var min = Number.MAX_VALUE;
for (i = 0; i &lt; array.length; i++) {
    if(array[i]&gt;max) {
        max = array[i];
    }
}

for (i = 0; i &lt; array.length; i++){
    if(array[i]&lt;min) {
        min = array[i];
    }
}

for (i = 0; i &lt; array.length; i++) {
    var norm = (array[i]-min)/(max-min);
    array[i] = norm;
}
</code></pre>

<p>However, I know that it's not doing this correctly because when I do the following code, the numbers logged to the console are often  above 1.</p>

<pre><code>max = Number.MIN_VALUE;
min = Number.MAX_VALUE;
for (i = 0; i &lt; array.length; i++) {
    if(array[i]&gt;max) {
        max = array[i];
    }
}

for (i = 0; i &lt; array.length; i++) {
    if(array[i]&lt;min) {
        min = array[i];
    }
}

console.log(max);
console.log(min);
</code></pre>

<p>What am I doing wrong? Thank you!</p>