💾arr.shuffle()

/**
 * ⭐️ shuffle(arr)
 * - arr is shuffled in place
 * @param arr array to shuffle
 */
export function shuffle(arr) {

    var n = arr.length;

    for (let i = n - 1; i > 0; i--) {
        let j = randomInt(0, i);
        [arr[i], arr[j]] = [arr[j], arr[i]];
    }

    return arr;
}

// ⭐️ array.shuffle()
Array.prototype.shuffle = function () {
    return shuffle(this);
};

Last updated