I am facing an unusual issue while shuffling an array in JavaScript and I am unable to identify the root cause. Can someone provide assistance?
When attempting to shuffle an array, the output I receive is unexpected:
[1,2,3,4,5,6,7,8,9,10]
Instead of the desired result, I encounter null values as shown below:
[null,10,1,8,9,3,2,7,6,4]
Below is the code snippet (http://jsfiddle.net/2m5q3d2j/):
Array.prototype.suffle = function () {
for (var i in this) {
var j = Math.floor(Math.random() * this.length);
this[i] = this[j] + (this[j] = this[i], 0);
}
return this;
};