I have the following code:
var compare = function( nodeA, nodeB ){
return +nodeA.index - +nodeB.index;
};
var sort = function( nodes ){
nodes.sort( compare );
};
The node has this (pseudo) structure:
{
index: <integer>
value: <literal>
}
And it currently sorts them the regular way, when I call the sort
function, and print out the index's of each node:
0
1
2
3
How can I change my current logic to make it look like this? :
1
2
3
0 <-- 0 should be considered the biggest index