forked from M3-Academy/challenge-algorithms-v2.0
feat: cria algoritmo que retorne uma lista com as palavras mais longas de uma lista de palavras.
This commit is contained in:
parent
5a8fa6be43
commit
6f3d088691
@ -1,4 +1,15 @@
|
||||
export function longestWords(words) {
|
||||
// implementar logica aqui
|
||||
|
||||
let longWords = [];
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
if ((longWords.length === 0) || (words[i].length === longWords[0].length)) {
|
||||
longWords.push(words[i]);
|
||||
|
||||
} else if (words[i].length > longWords[0].length) {
|
||||
longWords = [];
|
||||
longWords.push(words[i]);
|
||||
}
|
||||
}
|
||||
return longWords;
|
||||
}
|
Loading…
Reference in New Issue
Block a user