Skip to content

Instantly share code, notes, and snippets.

@Atlas7
Forked from guilhermepontes/shuffle.js
Created November 13, 2017 07:17
Show Gist options
  • Save Atlas7/c04bbef301dfce601f36324886635558 to your computer and use it in GitHub Desktop.
Save Atlas7/c04bbef301dfce601f36324886635558 to your computer and use it in GitHub Desktop.
Shuffle array element ES2015, ES6
const shuffleArray = arr => arr.sort(() => Math.random() - 0.5)
shuffleArray([1, 2, 3]) //[3, 1, 2]
@jgrunik
Copy link

jgrunik commented Oct 10, 2018

This will only swap neighbouring elements
This is limited without multiple iterations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment