The following code works.
$Array = function() {};
$Array.prototype = Object.create(Array.prototype);
$Array.prototype.constructor = $Array;
$Array.prototype.shuffle = function() {
var r=new $Array(),c = this.slice(0);
while (c.length) r.push(c.splice(Math.random() * c.length, 1));
return r;
};
var n = new $Array();
n.push(0,1,2,3,4,5,6,7,8,9);
n.shuffle();
If instead of pushing the values into the $Array I instead try to use new $Array(0,1,2,3,4,5,6,7,8,9) the code doesn’t work. I have tried adding all the alternatives I can think of into the function on the first line of the code but none of them work. I am obviously overlooking something very simple but have run out of ideas.
Can someone please give me a hint as to what change is needed to the first line of the above code so that the values can be loaded when creating the $Array rather than having to push them into it afterward.