DEV Community

Discussion on: Vanilla JavaScript Shuffle Array

Collapse
 
olton profile image
Serhii Pimenov

In Metro 4, I use this method

Array.prototype.shuffle = function () {
    var currentIndex = this.length, temporaryValue, randomIndex;

    while (0 !== currentIndex) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
        temporaryValue = this[currentIndex];
        this[currentIndex] = this[randomIndex];
        this[randomIndex] = temporaryValue;
    }
    return this;
};
Collapse
 
dailydevtips1 profile image
Chris Bongers

Very nice that would be your normalized javascript solution as well.
Btw hadn't heard of Metro, but looks very cool