2022-10-27 15:07:13 +00:00
|
|
|
export function longestWords(words) {
|
|
|
|
// implementar logica aqui
|
2022-10-29 23:44:19 +00:00
|
|
|
|
|
|
|
let wordsInfo = []
|
|
|
|
let newArr = []
|
|
|
|
|
|
|
|
|
|
|
|
words.forEach(word => {
|
|
|
|
const wordInfo = {
|
|
|
|
[word]: word.length
|
|
|
|
}
|
|
|
|
wordsInfo.push(wordInfo)
|
|
|
|
})
|
|
|
|
|
|
|
|
let maxValue = 0
|
|
|
|
|
|
|
|
wordsInfo.forEach(wordInfo => {
|
|
|
|
let newMaxValue = Math.max(...Object.values(wordInfo))
|
|
|
|
if (newMaxValue > maxValue) {
|
|
|
|
maxValue = newMaxValue
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
wordsInfo.forEach(wordInfo => {
|
|
|
|
Object.keys(wordInfo).filter((key) => {
|
|
|
|
if (key.length >= maxValue) {
|
|
|
|
newArr.push(key)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return newArr
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
longestWords(["abacaxi", "melancia", "banana"]) // ["melancia"]
|