push array into another array at random positions javascript 1

push array into another array at random positions javascript

while (b.length) {
    a.splice(Math.floor(Math.random() * (a.length + 1)), 0, b.pop());
}

Here is what the above code is Doing:
1. Create an array of the numbers 1 through 10.
2. Create an empty array to hold the shuffled numbers.
3. While there are still numbers in the unshuffled array:
a. Pick a random number from the unshuffled array.
b. Remove that number from the unshuffled array.
c. Add that number to the shuffled array.

Similar Posts