2022-10-27 15:07:13 +00:00
|
|
|
export function longestWords(words) {
|
2022-11-02 22:34:16 +00:00
|
|
|
var longest = '';
|
2022-11-01 23:05:41 +00:00
|
|
|
|
|
|
|
for (const word of words) {
|
|
|
|
if (word.length > longest.length) {
|
|
|
|
longest = word;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return words.filter((word) => word.length === longest.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(longestWords(["abacaxi", "melancia", "banana"])); // ['melancia']
|
|
|
|
console.log(longestWords(["aba", "aa", "ad", "vcd", "aba"])); // ["aba","vcd", "aba"]
|
|
|
|
console.log(longestWords(["aa"])); // ["aa"]
|
|
|
|
console.log(longestWords(["abc", "eeee", "abcd", "dcd"]));//["eeee", "abcd"]
|
|
|
|
console.log(longestWords(["aa", "bb", "cc"]));//["aa", "bb", "cc"]
|
|
|
|
console.log(longestWords(["a", "abc", "cbd", "zzzzzz", "a", "abcdef", "asasa", "aaaaaa"]));//["zzzzzz", "abcdef", "aaaaaa"]
|