I am trying to use bubble sort to sort this array,
var blocks = ["50", "90", "70", "40", "190", "110", "300", "30", "60", "245"];
But for some reason I only get 110,190,245,30,300,40,50,60,70,90 when I print out the array after sorting.
Here is the code for sorting
$("#bubble").click(function(){
for(var i=0; i<blocks.length; i++){
for(var j=0; j<blocks.length-i-1; j++){
if(blocks[j]> blocks[j+1]){
var temp = blocks[j];
blocks[j] = blocks[j+1];
blocks[j+1] = temp;
}
}
}
var x = blocks.toString();
$("#blocks_container").append(x);
});
var blocks = [50, 90, 70, 40, 190, 110, 300, 30, 60, 245];- what do you get? Do you know why it's different?