var a = [18,41,2,31,6,85,1,25,16]; console.log(a) for (var i=0; i<a.length-1; i++) { for (var j=0; j<a.length-1-i; j++) { if (a[j] < a[j+1]) { var temp = a[j+1]; a[j+1] = a[j]; a[j] = temp; } } } console.log(a)