From 6801fc069d56cc9a5425b7483005fbe8105005cf Mon Sep 17 00:00:00 2001 From: HenriqueSSan Date: Thu, 27 Oct 2022 21:35:13 -0300 Subject: [PATCH] feat(challenge-9): completed challenge --- 09-mostRepeatedChar/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..28f1041 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,15 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" -} \ No newline at end of file + if (!text) return { error: 'Not Found Text' }; + + let max = 0, + maxChar = ''; + + for (let char of text) { + if (text.split(char).length > max) { + max = text.split(char).length; + maxChar = char; + } + } + + return maxChar; +}