feat: Adiciona 09-mostRepeatedChar

This commit is contained in:
Izabela Balizardo 2022-10-29 20:19:17 -03:00
parent e35b0ad71b
commit ec3a93f1ad
2 changed files with 39 additions and 16 deletions

View File

@ -1,4 +1,27 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
// implementar logica aqui
var cont = 0,
maior = 0;
var resp = text.toLowerCase();
var i = 0,
j = 0;
for (i = 0; i < text.length; i++) {
cont = 0;
for (j = 0; j < text.length; j++) {
if (resp[i] == text[j]) {
cont++;
}
}
if (maior < cont) {
maior= cont;
var result= resp[i];
}
}
return result;
}

View File

@ -1,19 +1,19 @@
import { mostUsedChar } from ".";
describe("mostUsedChar", () => {
it("Dever retornar 'f' quando passamos a palavra 'fdgdfgff'", () => {
expect(mostUsedChar("fdgdfgff")).toBe("f");
});
it("Dever retornar 'f' quando passamos a palavra 'fdgdfgff'", () => {
expect(mostUsedChar("fdgdfgff")).toBe("f");
});
it("Dever retornar 'm' quando passamos a palavra 'Lorem ipsum'", () => {
expect(mostUsedChar("Lorem ipsum")).toBe("m");
});
it("Dever retornar 'm' quando passamos a palavra 'Lorem ipsum'", () => {
expect(mostUsedChar("Lorem ipsum")).toBe("m");
});
it("Dever retornar 's' quando passamos a palavra 'adsassdasd'", () => {
expect(mostUsedChar("adsassdasd")).toBe("s");
});
it("Dever retornar 's' quando passamos a palavra 'adsassdasd'", () => {
expect(mostUsedChar("adsassdasd")).toBe("s");
});
it("Dever retornar 'e' quando passamos a palavra 'testeeeee'", () => {
expect(mostUsedChar("testeeeee")).toBe("e");
});
it("Dever retornar 'e' quando passamos a palavra 'testeeeee'", () => {
expect(mostUsedChar("testeeeee")).toBe("e");
});
});