Last active
September 2, 2015 15:54
-
-
Save 1wheel/21be932fa5d119cfa5ab to your computer and use it in GitHub Desktop.
Head Tails Breaks
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 headTails(a, n){ | |
var breaks = [] | |
while(a.length){ | |
var avg = mean(a) | |
breaks.push(avg) | |
a = a.filter(function(d){ return d > avg }) | |
} | |
return breaks | |
} | |
function mean(a){ | |
var total = a.reduce(function(p, v){ return p + v}, 0) | |
return total/a.length | |
} | |
a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 3, 4, 10, 100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment