forked from M3-Academy/challenge-algorithms-v2.0
feat(desafio): Adiciona decima tarefa concluida
This commit is contained in:
parent
a334ca8a26
commit
d1c5f75dd1
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user