feat: criando o algoritmo para a lista com as palavras longas

This commit is contained in:
PATRICK DE SOUZA SILVA 2022-11-02 13:41:20 -03:00
parent c6f6df9c59
commit 5b864a1417

View File

@ -1,4 +1,27 @@
export function longestWords(words) {
// implementar logica aqui
// 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
}