feat: Adiciona 10-longestWords

This commit is contained in:
Izabela Balizardo 2022-10-31 22:38:12 -03:00
parent ec3a93f1ad
commit df6eb097d7

View File

@ -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;
}