From 835230d507fc9488d851f3ef1612035650499185 Mon Sep 17 00:00:00 2001 From: Emmanuel Vitor Date: Mon, 31 Oct 2022 13:59:07 -0300 Subject: [PATCH] feat: cria algoritmo que retorne a a letra mias repetida de uma string. --- 09-mostRepeatedChar/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..1a4d0f2 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,17 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let char = ''; + let repeatLetter = 0; + for (const character of text) { + let countLetter = 0; + for (const verifyCharacter of text) { + if (character === verifyCharacter) + countLetter++ + } + if (countLetter > repeatLetter) { + repeatLetter = countLetter; + char = character + } + } + return char; } \ No newline at end of file