Merge pull request 'feat: criando o algoritmo para a lista com as palavras longas' (#5) from feature/long-words into master

Reviewed-on: #5
This commit is contained in:
PATRICK DE SOUZA SILVA 2022-11-02 16:52:23 +00:00
commit d50035a9ce

View File

@ -1,4 +1,27 @@
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
}