How to implement bubble sort to sort string length from largest to smallest?
I tried this but it is sorted from smallest to largest
function order(array) {
for ( let i = 0 ; i < array.length ; i++ ) {
for ( let j = i ; j < array.length ; j++ ) {
if ( array[i].length < array[j].length ) {
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
return array;
}
Well... if this comparison
if ( array[i].length < array[j].length ) {
/* swap */
}
sorts in ascending order...
What comparison might sort in descending order?