I know that there is already question for "how to shuffle an array in JavaScript" but I didn't find a specific question for how to shuffle an array immutably. So, what's the best way to shuffle an array immutably in JavaScript?
Maybe taking the answer from https://stackoverflow.com/a/2450976/3022127 and simply copying the array first (inside of the method) would be the best way?
Or maybe something like this:
const shuffleArray = (arr) => {
return arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1])
}
(seems to be pretty random https://jsfiddle.net/Lpy22x4c/1/)