Last active
May 20, 2020 14:38
-
-
Save emorisse/68f031730c7ad70598a8db928f54c8c9 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 histogram(data, bins=5) { | |
const min = Math.min(...data) | |
const max = Math.max(...data) | |
const size = Math.ceil((max-min)/bins) | |
var histogram = new Array(bins).fill(0); | |
for (const item of data) { | |
index = Math.floor((item - min) / size) | |
if ( index > ( bins -1 ) ) { // total hack | |
index-- | |
} | |
histogram[index]++; | |
} | |
return histogram; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment