Created
October 28, 2020 09:04
-
-
Save sungchuni/84eaff34974da514378820047500d565 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 getSamples(length) { | |
const array = Array.from(this || []); | |
const sampleLength = Math.min(length, array.length); | |
const result = []; | |
while (result.length < sampleLength) { | |
const draw = Math.random() * array.length; | |
const sample = array.splice(draw, 1).shift(); | |
result.push(sample); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment