challenge-algorithms-v2.0-h.../10-longestWords/index.js

30 lines
775 B
JavaScript

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
}