My app has a WebView control with an HTML page inside.
That page is made of divs which contain one iFrame each, so when many divs are children of document.body all iFrames are like HTML pages themselves, one after other.
The divs have a attribute called orderIndex, because they have to be ordered according to an array of indexes.
(The iFrames have already loaded at the sorting time)
These indexes are the new positions, so for examples orderIndexesArray[0] contains the new position that the first child has to attain.
I found some sorting methods at:
https://stackoverflow.com/a/39569822/930835
I adapted this one
var bd = document.body;
Array.prototype.slice.call(bd.children)
.map(function (x) { return bd.removeChild(x); })
.sort(function (x, y) { return /* your sort logic, compare x and y here */; })
.forEach(function (x) { bd.appendChild(x); });
I want that the ordering process is not much like "blinking parts of the HTML page being swiftly reordered", instead I would like that the redrawing starts from the first so the visible part of the page is sort of replaced with no much blinking.
My concern is also for performance. HTML and Javascript are not my main programming environment.
So, is that algorithm doing a nice job redrawing from the top and well performing, or does it contain numberous swaps and it is slow?