๐Ÿ’พ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