Last active
April 9, 2018 12:59
-
-
Save nabrown/4500f7cec8a065bce2fda0dc7d4b11e8 to your computer and use it in GitHub Desktop.
One working implementation of getRandosFromArray function
This file contains hidden or 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
export const getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let randos = [] | |
for (let i = 0; i < numRandos; i++){ | |
let rand = Math.floor(Math.random() * arrClone.length) | |
randos.push(arrClone.splice(rand,1)[0]) // splice returns a new array | |
} | |
return randos | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment