diegodfsd
12/19/2013 - 4:13 PM

Order desc list

Order desc list

function order(items){
    var iterator = 0;
    for(var x = items.length;x >= 0 ;x--){
        for(var y = 1;y <= x;y++){
            iterator += 1;
            if(items[y-1] < items[y])
            {
              var temp = items[y-1];
              items[y -1] = items[y];
              items[y] = temp;
            }
        }
    }
    console.log(iterator);
    return items;
}

var items = [1,2,3,4,5,6,7,9,8];
items = order(items);
console.log(items);