forked from M3-Academy/challenge-algorithms-v2.0
feat: resolve funcão longestWords
This commit is contained in:
parent
29ab122a2f
commit
bfd4a7f93f
@ -1,4 +1,19 @@
|
||||
export function longestWords(words) {
|
||||
// implementar logica aqui
|
||||
if (words.length == 0)
|
||||
return console.log('Escreva as palavras a serem consultar');
|
||||
else {
|
||||
let cont = words[0].length;
|
||||
for (let i = 1; i < words.length; i++) {
|
||||
if (cont < words[i].length)
|
||||
cont = words[i].length;
|
||||
}
|
||||
let longest = [];
|
||||
for (let j = 0; j < words.length; j++) {
|
||||
if (cont == words[j].length)
|
||||
longest.push(words[j]);
|
||||
}
|
||||
return longest;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user