Javascript Algorithm Array Sort Bubble Sort
function bubbleSort(array) { for (var i = 0, arrayLength = array.length; i < arrayLength; i++) { for (var j = 0; j < arrayLength - 1 - i; j++) { if (array[j] > array[j+1]) { var temp = array[j]; array[j] = array[j+1];/* ww w. j av a 2 s . c o m*/ array[j+1] = temp; } } } return array; } let a = bubbleSort([6, 1, 2, 3, 4, 5]); // [1,2,3,4,5,6] console.log(a);