B2G/gecko/content/xml/tests/books/books.js
// An inefficient, but effective bubble sort
An inefficient, but effective bubble sort
An inefficient but effective bubble sort
function sort(collection, key)
{
  var i, j;
  var count = collection.length;
  var parent, child;
  for (i = count-1; i >= 0; i--) {
    for (j = 1; j <= i; j++) {
      if (collection[j-1][key] > collection[j][key]) {
         child = collection[j];
         parent = child.parentNode;
         collection[j] = collection[j-1];
         collection[j-1] = child;
         parent.removeChild(child);       
         parent.insertBefore(child, collection[j]);
      }
    }
  }
}
function sort ( collection , key ) { var i , j ; var count = collection . length ; var parent , child ; for ( i = count - 1 ; i >= 0 ; i -- ) { for ( j = 1 ; j <= i ; j ++ ) { if ( collection [ j - 1 ] [ key ] > collection [ j ] [ key ] ) { child = collection [ j ] ; parent = child . parentNode ; collection [ j ] = collection [ j - 1 ] ; collection [ j - 1 ] = child ; parent . removeChild ( child ) ; parent . insertBefore ( child , collection [ j ] ) ; } } } }
An inefficient, but effective bubble sort
An inefficient but effective bubble sort
// Move the item both in the local array and // in the tree