forked from M3-Academy/challenge-algorithms-v2.0
feat: Adiciona 10-longestWords
This commit is contained in:
parent
ec3a93f1ad
commit
df6eb097d7
@ -1,4 +1,33 @@
|
||||
export function longestWords(words) {
|
||||
// implementar logica aqui
|
||||
|
||||
let longestWords = [];
|
||||
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
let word = words[i];
|
||||
let wordInfo = {
|
||||
[word]: word.length,
|
||||
};
|
||||
longestWords.push(wordInfo);
|
||||
}
|
||||
|
||||
let bigWord = 0;
|
||||
for (let j = 0; j < longestWords.length; j++) {
|
||||
let longWord = longestWords[j];
|
||||
let longInfo = Math.max(...Object.values(longWord));
|
||||
if (longInfo > bigWord) {
|
||||
bigWord = longInfo;
|
||||
}
|
||||
}
|
||||
|
||||
let finalResult = [];
|
||||
for (let result = 0; result < longestWords.length; result++) {
|
||||
let resultWord = longestWords[result];
|
||||
Object.keys(resultWord).filter((result) => {
|
||||
if (result.length == bigWord) {
|
||||
finalResult.push(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
return finalResult;
|
||||
}
|
Loading…
Reference in New Issue
Block a user