JSFiddle - React, Tailwind, and code Playground
by chrisfargen
JavaScript
x = [1, 2, 3, 4, 5];
console.log('I just set x = ' + x);
y = x;
console.log('After setting y = x, y = ' + y);
x = shuffle(x);
console.log('After shuffling x, y = ' + y);
x = shuffle(x);
console.log('After shuffling x again, y = ' + y);
function shuffle(r1,n) {
var i = r1.length, j, tempi, tempj, r2;
r2 = r1;
while (--i) {
j = Math.floor(Math.random() * (i + 1));
tempi = r2[i];
tempj = r2[j];
r2[i] = tempj;
r2[j] = tempi;
}
return r2.slice(0,n);
}