From 739d026c88b50b5faf1739ae6bb80606b6c91273 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 2 Nov 2022 22:49:02 -0200 Subject: [PATCH] feat(mostRepeatedChar): cria funcao que descobre o caractere mais repetido de uma string --- 09-mostRepeatedChar/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..316aef4 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,21 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + // implementar logica aqui + let palavra = text.toLowerCase().split("").sort(); + let i, + j, + k = 0; + let maisRepetido; + for (i in palavra) { + let char = palavra[i]; + if (char === palavra[i - 1]) { + j++; + if (j > k) { + k = j; + maisRepetido = palavra[i]; + } + } else { + j = 0; + } + } + return maisRepetido; +}