challenge-algorithms-v2.0-a.../10-longestWords/index.js

13 lines
318 B
JavaScript
Raw Normal View History

export function longestWords(words) {
let sortedWords = words.sort((a, b) => b.length - a.length);
let maxLength = sortedWords[0].length
let longestWords = []
for (let word of sortedWords) {
if(word.length != maxLength) break;
longestWords.push(word)
}
return longestWords;
}