Hello everyone, I'm extremely new to using JavaScript, and I have been working on a project for school. The last part I need to finish is to randomize a set of 24 divs. So it takes the divs I already have, and randomly swaps them around. I found this code online:

$(function () {
var parent = $("#shuffle");
var divs = parent.children();
while (divs.length) {
parent.append(divs.splice(Math.floor(Math.random() * divs.length), 1)[0]);
}

But I am not 100% sure what it is doing, or how it is exactly doing it. My code works perfect using this, and my entire project is complete, but I don't want to use it and have no idea what it does or how it works.

Can anyone explain it to me?

So far what I think it does is take a variable, parent, and set it equal to my div element that has the ID of shuffle.
Then it creates a divs variable, and creates an array of all of it's children (all of the divs inside of that div)
Then there is a while loop that runs while there is still a variable inside of the divs array.

Please correct me if anything is wrong, and then please explain that last line of code that performs the randomizing.

Thanks everyone in advance,

-Josh