forked from M3-Academy/challenge-algorithms-v2.0
feat(10-longestWords): adiciona função
This commit is contained in:
parent
0eecc63f1c
commit
3c5165a358
@ -1,4 +1,19 @@
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user