Created
November 2, 2022 20:00
-
-
Save faustoct1/c0ce242d07d3343584da14f5cc886e5f to your computer and use it in GitHub Desktop.
Como embaralhar (shuffle) um array em javascript
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 shuffle = (array) => array.map((a) => ({sort: Math.random(), value: a})) | |
.sort((a, b) => a.sort - b.sort) | |
.map((a) => a.value) | |
console.log(shuffle([1,2,3,4,5])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment