Skip to content

Instantly share code, notes, and snippets.

/**
* Shuffle an array without changing the original one
* @param {any[]} array Any array
* @returns {any[]} Randomized array
*/
const shuffleArray = array => {
const a = array.slice()
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
[a[i], a[j]] = [a[j], a[i]]