Created
September 2, 2015 16:31
-
-
Save veltman/c7c7fc15887d8a03f9a4 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 headTails(arr){ | |
var breaks = [], | |
avg = mean(arr), | |
head = arr.filter(function(d){ | |
return d > avg; | |
}); | |
while (head.length && head.length < Math.floor(arr.length/2)) { | |
breaks.push(avg); | |
arr = head; | |
avg = mean(arr); | |
head = arr.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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment