feat(10-longestWords)executa exercicio 10

This commit is contained in:
Henrique Martins Silva 2022-10-30 12:08:42 -03:00
parent 151c74165a
commit fd55e12640

View File

@ -1,4 +1,38 @@
export function longestWords(words) {
// implementar logica aqui
}
// 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
}
// let palavra = [];
// for (let word = 0; word < words.length; word++) {
// if (palavra < word.length) palavra = word;
// }
// let palavraLonga = []
// for (let i = 0; i < palavra.length; i++) {
// if (i.length == palavra.length) palavraLonga = words[i];
// }
// return palavraLonga;