Skip to content

Instantly share code, notes, and snippets.

@sungchuni
Created October 28, 2020 09:04
Show Gist options
  • Save sungchuni/84eaff34974da514378820047500d565 to your computer and use it in GitHub Desktop.
Save sungchuni/84eaff34974da514378820047500d565 to your computer and use it in GitHub Desktop.
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