feat(desafio): Adiciona decima tarefa concluida

This commit is contained in:
Manuela Luana Schumacker Tavares 2022-10-31 12:27:13 -03:00
parent a334ca8a26
commit d1c5f75dd1

View File

@ -1,4 +1,30 @@
export function longestWords(words) {
// implementar logica aqui
if(words.length == 0 || words.length == 1) {
return words;
}else{
words.sort((a, b) => {
if(a.length > b.length){
return -1;
}else if(a.length < b.length){
return 1;
}else{
return 0;
}
});
let wordTaker = [];
let firstWord = words[0].length;
for (let i = 0; i < words.length; i++) {
const element = words[i];
if(element.length == firstWord){
wordTaker.push(element);
}else{
break;
}
}
return wordTaker;
}
}