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

28 lines
459 B
JavaScript
Raw Permalink Normal View History

export function longestWords(words) {
// implementar logica aqui
const lengthArray = []
words.forEach(element => {
lengthArray.push([element, element.length])
})
let res = ['', 0]
lengthArray.forEach(array => {
if (res[1] < array[1]) {
res = array
}
})
const AllLongestWords = []
lengthArray.forEach(array => {
if (res[1] == array[1]) {
AllLongestWords.push(array[0])
}
})
return AllLongestWords
}