Created
March 24, 2024 09:57
-
-
Save tjinlag/2c36ce2c712d479cc7e466ecae45a2cf to your computer and use it in GitHub Desktop.
Shuffle an array
This file contains 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
const shuffleItems = (items) => { | |
return items.map(item => ({ sort: Math.random(), value: item })) | |
.sort((item1, item2) => item1.sort - item2.sort) | |
.map(item => item.value); | |
} | |
shuffleItems([1,2,3,4,5,6]); | |
shuffleItems([1,2,3,4,5,6,6,8,10,12]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment