From 3b5099d7d16bd4e5fa277c03dd1e4cedc1869c6b Mon Sep 17 00:00:00 2001 From: Gustavo_Rallenson Date: Fri, 28 Oct 2022 21:53:51 -0300 Subject: [PATCH] Feat:Finalizado:MostRepeatedChar --- 09-mostRepeatedChar/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..230e645 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,25 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + const CharUnited = text.toLowerCase().split(" ").join('') + const Char = CharUnited.split(""); + Char.sort((a, b) => { + return a.localeCompare(b); + }) + let Count = 1 + let maior = 0 + let FrequenteChar = '' + for(let i = 1;i < text.length; i ++ ){ + //console.log(maior, FrequenteChar) + if(Char[i] === Char[i-1]){ + Count ++ + }else{ + Count = 1 + } + if (Count > maior){ + maior = Count + FrequenteChar = Char[i] + } + } + + return FrequenteChar } \ No newline at end of file