Skip to content

Instantly share code, notes, and snippets.

@aedoran
Created June 4, 2012 20:10
Show Gist options
  • Save aedoran/2870581 to your computer and use it in GitHub Desktop.
Save aedoran/2870581 to your computer and use it in GitHub Desktop.
normally distribute data nd split them into 0-100 buckets
var data = [2,3,4,5,3,2,3,4,5,6,9,9,100,-100];
var avg = 0;
data.forEach(function(a) {
avg+= a;
});
avg = avg / data.length;
console.log("avg",avg);
var devs = 0;
data.forEach(function(a) {
devs += Math.pow(avg-a,2);
});
var standard_deviation = Math.sqrt(devs/(data.length-1));
console.log("std",standard_deviation);
//now put them into buckets of 0-100j
data.forEach(function(a) {
console.log(a,(100/2)+(100/8)*(a-avg)/standard_deviation);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment