1function randomArrayShuffle(array) {
2 var currentIndex = array.length, temporaryValue, randomIndex;
3 while (0 !== currentIndex) {
4 randomIndex = Math.floor(Math.random() * currentIndex);
5 currentIndex -= 1;
6 temporaryValue = array[currentIndex];
7 array[currentIndex] = array[randomIndex];
8 array[randomIndex] = temporaryValue;
9 }
10 return array;
11}
12var alphabet=["a","b","c","d","e"];
13randomArrayShuffle(alphabet);
14//alphabet is now shuffled randomly = ["d", "c", "b", "e", "a"]
15
16
17
1const getShuffledArr = arr => {
2 const newArr = arr.slice()
3 for (let i = newArr.length - 1; i > 0; i--) {
4 const rand = Math.floor(Math.random() * (i + 1));
5 [newArr[i], newArr[rand]] = [newArr[rand], newArr[i]];
6 }
7 return newArr
8};
1let unshuffled = ['hello', 'a', 't', 'q', 1, 2, 3, {cats: true}]
2
3let shuffled = unshuffled
4 .map((a) => ({sort: Math.random(), value: a}))
5 .sort((a, b) => a.sort - b.sort)
6 .map((a) => a.value)
7