Created
May 27, 2014 17:21
-
-
Save zxqx/0cd720cba5ecdea43060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function normalize(array, field, max) | |
{ | |
var highValue = getHighValue(array, field); | |
var divisor = highValue / max; | |
return array.map(function(x) { | |
x[field] = x[field] / divisor; | |
return x; | |
}); | |
} | |
function getHighValue(array, field) { | |
return Math.max.apply(null, array.map(function(x) { | |
return x[field]; | |
})); | |
} | |
// EXAMPLE USAGE | |
var normalized = normalize(someData, 'value', 150); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment