From 77abbade219c76e902917ab5638313bcb3560f31 Mon Sep 17 00:00:00 2001 From: danielmoliaribarbosa Date: Fri, 28 Oct 2022 15:15:21 -0300 Subject: [PATCH] =?UTF-8?q?feat(mostRepeatedChar):=20Implementa=20fun?= =?UTF-8?q?=C3=A7=C3=A3o=20mostRepeatedChar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 09-mostRepeatedChar/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..bedc121 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,16 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const textObj = {} + let maxCount = 0 + let mostUsedChar = "" + for (let char of text) { + textObj[char] = textObj[char] + 1 || 1 + } + for (let key in textObj) { + if (textObj[key] > maxCount) { + maxCount = textObj[key] + mostUsedChar = key + } + } + return mostUsedChar } \ No newline at end of file