challenge-algorithms-v2.0-e.../10-longestWords/index.js
2022-11-01 22:52:13 -03:00

20 lines
443 B
JavaScript

export function longestWords(words) {
// implementar logica aqui
const longestWords = [];
let longest = '';
for (let i = 0; i < words.length; i++) {
if (words[i].length > longest.length) {
longest = words[i];
}
}
for (let i = 0; i < words.length; i++) {
if (words[i].length === longest.length) {
longestWords.push(words[i]);
}
}
return longestWords;
}