Skip to content

Instantly share code, notes, and snippets.

@bogdanpetru
Last active December 9, 2015 21:55
Show Gist options
  • Save bogdanpetru/91e0215c1818fb77be8e to your computer and use it in GitHub Desktop.
Save bogdanpetru/91e0215c1818fb77be8e to your computer and use it in GitHub Desktop.
recurse shuffle array
function shuffle(list){
if(list.length === 1){
return list;
}
let min = 0;
let max = list.length - 1;
let randomIndex = Math.floor(Math.random() * (max - min + 1)) + min;
return shuffle(list.filter((x, i) => { return randomIndex !== i; } )).concat(list[randomIndex])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment