forked from M3-Academy/challenge-algorithms-v2.0
24 lines
595 B
JavaScript
24 lines
595 B
JavaScript
export function longestWords(words) {
|
|
let arr, arr1;
|
|
let cont = 0;
|
|
let primeiro = true;
|
|
for (let i = 0; i < words.length; i++) {
|
|
|
|
if (primeiro === true) {
|
|
cont = words[i].length;
|
|
arr = " " + words[i];
|
|
primeiro = false;
|
|
} else if (words[i].length > cont) {
|
|
cont = words[i].length;
|
|
arr = " " + words[i];
|
|
|
|
} else if (words[i].length === cont) {
|
|
cont = words[i].length;
|
|
arr += " " + words[i];
|
|
}
|
|
}
|
|
arr1 = arr.split(" ");
|
|
arr1.shift();
|
|
|
|
return (arr1);
|
|
} |