Skip to content

Instantly share code, notes, and snippets.

@1wheel
Last active September 2, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1wheel/21be932fa5d119cfa5ab to your computer and use it in GitHub Desktop.
Save 1wheel/21be932fa5d119cfa5ab to your computer and use it in GitHub Desktop.
Head Tails Breaks
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