JSFiddle - React, Tailwind, and code Playground

by hpmhpm

JavaScript

function shuffle(array) {
    let counter = array.length;

    // While there are elements in the array
    while (counter > 0) {
        // Pick a random index
        let index = Math.floor(Math.random() * counter);

        // Decrease counter by 1
        counter--;

        // And swap the last element with it
        let temp = array[counter];
        array[counter] = array[index];
        array[index] = temp;
    }

    return array;
}

function range(lowEnd, highEnd) {
		var list = [];
    for (var i = lowEnd; i <= highEnd; i++) {
        list.push(i);
    }
    return list;
}

input = range(1, 10);

shuffled = shuffle(input);

alert(shuffled.toString());