DEV Community

Discussion on: 8 Best JavaScript One-Liners

Collapse
 
arielmejiadev profile image
Ariel Mejia

@shivamblog Sorry items could be the number of items so you can shuffle and also get only some of them:

and the array should be the array to shuffle and slice it.

const randomizeArray = () => [...array].sort(() => 0.5 - Math.random()).slice(0, numberOfItems);
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
shivams1007 profile image
Shivam Singh

Then it is correct!