feat: criando o algoritmo para a lista com as palavras longas
This commit is contained in:
parent
c6f6df9c59
commit
5b864a1417
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user