If you want to sort by ascending it should be the comparator function should return a - b not a.length - b.length because a.length - b.length the result will always be zero for all the alphabets of length 1. The result will be different for ['ab', 'a'] will produce ['a', 'ab'] because the length of first element in array is lesser than second element.
function longest(arr) {
return arr.sort( (a,b) => {
return a - b;
});
}
}