function longest(arr) {
return arr.sort( (a,b) => {
return a.length - b.length;
});
}
var res = longest(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k','l']);
console.log(res); // -> [ 'f', 'a', 'c', 'd', 'e', 'b', 'g', 'h', 'i', 'k', 'l' ]
Isn't it strange how the function's return is sorting the array in this unexpected way? I thought it was supposed to keep the original order.
Is my understanding correct?