From 61b8dc538c07b49afc911b19e365c88586c3ef26 Mon Sep 17 00:00:00 2001 From: wellington carlos Date: Tue, 1 Nov 2022 13:47:11 -0300 Subject: [PATCH] (feat)finalizando teste 09-mostRepeatedChar --- 09-mostRepeatedChar/index.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..8b914b9 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,28 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + + + const palavra = {}; + let maximo = 0; + let repetido = ''; + + for(let letra of text){ + if(palavra[letra]){ + palavra[letra]++; + }else{ + palavra[letra] = 1; + } + } + + for(let letra in palavra){ + if(palavra[letra] > maximo){ + maximo = palavra[letra]; + repetido = letra; + } + } + + return repetido +} + + + + \ No newline at end of file