Skip to content

Instantly share code, notes, and snippets.

@faustoct1
Created November 2, 2022 20:00
Show Gist options
  • Save faustoct1/c0ce242d07d3343584da14f5cc886e5f to your computer and use it in GitHub Desktop.
Save faustoct1/c0ce242d07d3343584da14f5cc886e5f to your computer and use it in GitHub Desktop.
Como embaralhar (shuffle) um array em javascript
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