A moment ago I asked this question: javascript sort array to align with order array based on what turned out to be a false premise. (I've been up for too long, give me a break please).
What I really need to do is sort DOM elements. Performance is key in my application as it will be running in very CPU-poor situations. So what I have is something like this:
<div id="moduleWrap">
<div class="module">Jack</div> <!-- 0 -->
<div class="module">Jill</div> <!-- 1 -->
<div class="module">Nancy</div> <!-- 2 -->
<div class="module">Tom</div> <!-- 3 -->
<div class="module">Cartman</div> <!-- 4 -->
</div>
And in JavaScript:
$modules = $('#moduleWrap .module');
order = [3,1,4,0,2];
What I need is this:
<div id="moduleWrap">
<div class="module">Tom</div> <!-- 3 -->
<div class="module">Jill</div> <!-- 1 -->
<div class="module">Cartman</div> <!-- 4 -->
<div class="module">Jack</div> <!-- 0 -->
<div class="module">Nancy</div> <!-- 2 -->
</div>
I thought (wrongly) that I could sort the jQuery object and simply append the result. This is not so.