Skip to content

Instantly share code, notes, and snippets.

@louicoder
Last active July 24, 2021 09:17
Show Gist options
  • Save louicoder/f34176e795bc2b6cdf9b75d1832e4eb9 to your computer and use it in GitHub Desktop.
Save louicoder/f34176e795bc2b6cdf9b75d1832e4eb9 to your computer and use it in GitHub Desktop.
Quiz functions to be added to animation quizzes
/**
* Function picks random number of specified elements in an array and will return
* random (n) numbers from the array length
*
* @param {Array} [arr=[...Array(100).fill().map((el,i) => i+1)]] - array of elements
* @param {Number} [count=7] - count of elements to be picked
*/
const pickRandomArrayElements = (arr, count = 7) => {
let _arr = [ ...arr ];
return [ ...Array(count) ].map(() => _arr.splice(Math.floor(Math.random() * _arr.length), 1)[0]);
};
// const pickRandomElement = (array, )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment