forked from M3-Academy/challenge-algorithms-v2.0
feat(10-longestWords)executa exercicio 10
This commit is contained in:
parent
151c74165a
commit
fd55e12640
@ -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;
|
Loading…
Reference in New Issue
Block a user