From ece207425d685860fb553a7875266d4edbd6c7ed Mon Sep 17 00:00:00 2001 From: Gabriel Lehmann Date: Sat, 29 Oct 2022 23:42:52 -0300 Subject: [PATCH] feat(mostrepeatedchar): made ninth challenge --- 09-mostRepeatedChar/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..d1a9a80 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,18 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let count = 0; + let char = " "; + let save = {}; + text.split("").forEach((letter) => { + if(save[letter]){ + save[letter] += 1; + } else { + save[letter] = 1; + } + if(save[letter] > count){ + count = save[letter]; + char = letter; + } + }) + return char; } \ No newline at end of file