forked from M3-Academy/challenge-algorithms-v2.0
feature: resolve exercício 10-longestWords
This commit is contained in:
parent
588770824a
commit
8a048120da
@ -1,4 +1,13 @@
|
|||||||
export function longestWords(words) {
|
export function longestWords(words) {
|
||||||
// implementar logica aqui
|
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user