From 2be83cd8303b561835a0b2104afcf51ceac03f96 Mon Sep 17 00:00:00 2001 From: ueberjames Date: Fri, 28 Oct 2022 21:15:31 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20implementa=C3=A7=C3=A3o=20de=20algoritm?= =?UTF-8?q?o=20que=20retorne=20a=20a=20letra=20mias=20repetida=20de=20uma?= =?UTF-8?q?=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 09-mostRepeatedChar/index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..8ac1839 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,22 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + + let str = text.toLowerCase().split("").sort().join(''); + let letraRepetida = 0; + let cont = 1; + let mostra = ""; + + for (let i = 0; i < str.length; i++) { + if (str[i] === str[i + 1]) { + cont++; + } else { + if (cont > letraRepetida) { + letraRepetida = cont; + mostra = str[i]; + } + cont = 1; + } + } + + return mostra; } \ No newline at end of file