Created
April 28, 2018 04:48
-
-
Save auser/f289e1c4abef6d417060ab69a20cf4de 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
const splitTotal = (total, n) => { | |
let arr = []; | |
let i = 0; | |
while (i < n) { | |
arr.push(Math.floor(Math.random() * total) + 1) | |
i++; | |
} | |
const sorted = [0].concat(arr, [total]).sort((a, b) => a - b); | |
let out = []; | |
for (i = 0; i < sorted.length - 1; i++) { | |
out.push(sorted[i+1] - sorted[i]); | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment