View Full Version : flip node order

04-28-2003, 06:00 PM
I've got a bunch of nodes - a list:


What's the quickest / easiest way of rearranging those nodes so they go 4-3-2-1?

Would it perhaps be possible to prototype something like a sort() method for node structures?

04-28-2003, 09:12 PM
The easiest would be to determine the wanted order, and append them to parentNode using appendChild in that order.

The most efficient would be only moving those necessare to move, but that would take more calculation in turn,

04-28-2003, 09:14 PM
Create a swap node function, and then do (pseudo-code-ish):

for (i = 0; i < parseInt(length/2); i++)
swap(i, length-1-i);

04-29-2003, 03:59 PM
Thanks - tis pretty much what I had in mind