feat: implementação de algoritmo que retorne uma lista com as palavras mais longas de uma lista de palavras

This commit is contained in:
Ueber James Santos 2022-10-29 11:18:59 -03:00
parent 2be83cd830
commit 3ea5479e5f
3 changed files with 49 additions and 23 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -1,4 +1,14 @@
export function longestWords(words) { export function longestWords(words) {
// implementar logica aqui // implementar logica aqui
let longest = '';
for (const word of words) {
if (word.length > longest.length) {
longest = word;
}
}
return words.filter((word) => word.length === longest.length);
} }

View File

@ -1,28 +1,43 @@
import { longestWords } from '.'; import { longestWords } from ".";
describe('longestWords', () => { describe("longestWords", () => {
it('Dever retornar ["melancia"] quando passamos a lista ["abacaxi", "melancia", "banana"]', () => { it('Dever retornar ["melancia"] quando passamos a lista ["abacaxi", "melancia", "banana"]', () => {
expect(longestWords(["abacaxi", "melancia", "banana"])).toEqual(["melancia"]); expect(longestWords(["abacaxi", "melancia", "banana"])).toEqual([
}); "melancia",
]);
});
it('Dever retornar ["aba", "aa", "ad", "vcd", "aba"] quando passamos a lista ["aba","vcd", "aba"]', () => { it('Dever retornar ["aba","vcd", "aba"] quando passamos a lista ["aba", "aa", "ad", "vcd", "aba"]', () => {
expect(longestWords(["aba", "aa", "ad", "vcd", "aba"])).toEqual(["aba", "vcd", "aba"]); expect(longestWords(["aba", "aa", "ad", "vcd", "aba"])).toEqual(["aba","vcd","aba",]);
}); });
it('Dever retornar ["aa"] quando passamos a lista ["aa"]', () => { it('Dever retornar ["aa"] quando passamos a lista ["aa"]', () => {
expect(longestWords(["aa"])).toEqual(["aa"]); expect(longestWords(["aa"])).toEqual(["aa"]);
}); });
it('Dever retornar ["eeee", "abcd"] quando passamos a lista ["abc", "eeee", "abcd", "dcd"]', () => { it('Dever retornar ["eeee", "abcd"] quando passamos a lista ["abc", "eeee", "abcd", "dcd"]', () => {
expect(longestWords(["abc", "eeee", "abcd", "dcd"])).toEqual(["eeee", "abcd"]); expect(longestWords(["abc", "eeee", "abcd", "dcd"])).toEqual([
}); "eeee",
"abcd",
]);
});
it('Dever retornar ["aa", "bb", "cc"] quando passamos a lista ["aa", "bb", "cc"]', () => { it('Dever retornar ["aa", "bb", "cc"] quando passamos a lista ["aa", "bb", "cc"]', () => {
expect(longestWords(["aa", "bb", "cc"])).toEqual(["aa", "bb", "cc"]); expect(longestWords(["aa", "bb", "cc"])).toEqual(["aa", "bb", "cc"]);
}); });
it('Dever retornar ["zzzzzz", "abcdef", "aaaaaa"] quando passamos a lista ["a", "abc", "cbd", "zzzzzz", "a", "abcdef", "asasa", "aaaaaa"]', () => { it('Dever retornar ["zzzzzz", "abcdef", "aaaaaa"] quando passamos a lista ["a", "abc", "cbd", "zzzzzz", "a", "abcdef", "asasa", "aaaaaa"]', () => {
expect(longestWords(["a", "abc", "cbd", "zzzzzz", "a", "abcdef", "asasa", "aaaaaa"])).toEqual(["zzzzzz", "abcdef", "aaaaaa"]); expect(
}); longestWords([
"a",
"abc",
"cbd",
"zzzzzz",
"a",
"abcdef",
"asasa",
"aaaaaa",
])
).toEqual(["zzzzzz", "abcdef", "aaaaaa"]);
});
}); });