From f207e8a5cd32d94f7bce52ebc2df26b9fc30dcf1 Mon Sep 17 00:00:00 2001 From: Nicolas Oliveira <110689312+thedevnicolas@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:53:09 -0300 Subject: [PATCH] feat(desafio09):desafio-completo --- 09-mostRepeatedChar/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..e7d6fdf 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,19 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" -} \ No newline at end of file + let result = ''; + let mostUsedCount = 0; + for (const letter of text) { + let countLetter = 0; + for (const letterToCount of text) { + if (letterToCount === letter) { + countLetter++; + } + } + if (countLetter > mostUsedCount) { + mostUsedCount = countLetter; + result = letter; + } + } + + return result; + } \ No newline at end of file -- 2.34.1