Skip to content

Instantly share code, notes, and snippets.

@zxqx
Created May 27, 2014 17:21
Show Gist options
  • Save zxqx/0cd720cba5ecdea43060 to your computer and use it in GitHub Desktop.
Save zxqx/0cd720cba5ecdea43060 to your computer and use it in GitHub Desktop.
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