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

18 lines
426 B
JavaScript
Raw Normal View History

export function longestWords(words) {
2022-11-02 15:58:37 +00:00
let longestWord = "";
let longestWordsArray = [];
for (let i = 0; i < words.length; i++) {
if (words[i].length >= longestWord.length) {
longestWord = words[i];
}
}
for (let i = 0; i < words.length; i++) {
if (words[i].length == longestWord.length) {
longestWordsArray.push(words[i]);
}
}
return longestWordsArray;
// implementar logica aqui
}