JSFiddle - React, Tailwind, and code Playground
HTML
<div id="replace"></div>
JavaScript
const shuffleArray = (arr) => {
return arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1])
}
const numberArrayIsEqual = (a, b) => {
let isEqual = true;
return a.every((curVal, idx) => curVal === b[idx]);
}
const x = [1,2,3];
shuffledArrays = [];
const numIterations = 10000
for (let i = 0; i < numIterations; i++) {
shuffledArrays.push(shuffleArray(x));
}
const count123 = shuffledArrays.filter(ary => numberArrayIsEqual(ary, [1, 2, 3])).length;
const count132 = shuffledArrays.filter(ary => numberArrayIsEqual(ary, [1, 3, 2])).length;
const count213 = shuffledArrays.filter(ary => numberArrayIsEqual(ary, [2, 1, 3])).length;
const count231 = shuffledArrays.filter(ary => numberArrayIsEqual(ary, [2, 3, 1])).length;
const count321 = shuffledArrays.filter(ary => numberArrayIsEqual(ary, [3, 2, 1])).length;
const count312 = shuffledArrays.filter(ary => numberArrayIsEqual(ary, [3, 1, 2])).length;
const elt = document.getElementById('replace');
elt.innerHTML = [count123, count132, count213, count231, count321, count312]
.map(x => x / numIterations).join("<br>")