Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created September 12, 2019 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhil/a08380ab84e68c2d8f1e22f3e484d894 to your computer and use it in GitHub Desktop.
Save nkhil/a08380ab84e68c2d8f1e22f3e484d894 to your computer and use it in GitHub Desktop.
Pick out a random number of items out of an array
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
a.sort(() => .5 - Math.random() ).slice(0, 4);
//=> [3, 1, 6, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment