From 985af27572b82a69899f791db833e55bc0be5122 Mon Sep 17 00:00:00 2001 From: Gabriel Ferraz Date: Fri, 28 Oct 2022 15:16:57 -0300 Subject: [PATCH] =?UTF-8?q?(09-mostRepeatedChar):=20implementa?= =?UTF-8?q?=C3=A7=C3=A3o=20do=20c=C3=B3digo=20MostReapeat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 09-mostRepeatedChar/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..8a25df1 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,9 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let words = {} + const texts = text.toLowerCase().split("").sort(); + texts.forEach((word) => words[word] = (words[word] || 0) + 1); + const maxVal = Math.max(...Object.values(words)); + const word = Object.keys(words).find((key) => words[key] === maxVal); + return word } \ No newline at end of file