From 7144ca7ade04f4698ce47ee0591a5762cc40056f Mon Sep 17 00:00:00 2001 From: Nicolly Vieira Date: Fri, 28 Oct 2022 15:11:42 -0300 Subject: [PATCH] feat(mosrUsedChar): funcao feita --- 09-mostRepeatedChar/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..fddff13 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,19 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let textLower = text.toLowerCase().split(''); + let caractereMaisRepetido; + let numeroDeCaractereRepetido = 0; + + textLower.forEach(element => { + let caracteresRepetidos = textLower.filter((x) => x === element); + + if (caracteresRepetidos.length > numeroDeCaractereRepetido) { + caractereMaisRepetido = caracteresRepetidos.filter((caractere, indice) => { + return caracteresRepetidos.indexOf(caractere) === indice + }) + numeroDeCaractereRepetido = caracteresRepetidos.length + } + }); + + return caractereMaisRepetido.toString() } \ No newline at end of file