From 614bead0f71fee16b49218ab901f3605eb5e02d5 Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 2 Nov 2022 13:24:45 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20cria=C3=A7=C3=A3o=20da=20resposta=20do?= =?UTF-8?q?=2009-mostRepeatedChar?= 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..52eb7de 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,22 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const boxChar = {}; + let max = 0; + let result = ''; + + for(let char of text){ + if(boxChar[char]){ + boxChar[char]++; + }else{ + boxChar[char] = 1; + } + } + for(let char in boxChar){ + if(boxChar[char] > max){ + max = boxChar[char]; + result = char; + } + } + + return result; } \ No newline at end of file