From 6d4c4c3b5344811d50bb50b5bddec31db6f54299 Mon Sep 17 00:00:00 2001 From: Carlos Lins Date: Thu, 27 Oct 2022 20:44:23 -0300 Subject: [PATCH] feat: Algoritmo 09-mostRepeatedChar - finalizado --- 09-mostRepeatedChar/index.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..b3e09d1 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,26 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let newStr = text.replace(' ', '').split(''); + let count = 0; + let countControl = 0; + let strRepeat = ''; + + for(let i = 0; i < newStr.length; i++){ + + for(let j = 0; j < newStr.length; j++){ + if(newStr[i] === newStr[j]){ + count++; + } + } + + if(count > countControl){ + strRepeat = newStr[i]; + countControl = count; + } + + count = 0; + + } + + return strRepeat; } \ No newline at end of file