From dc310d5daa5845778f3338ab29088f851f885a1c Mon Sep 17 00:00:00 2001 From: DaviHKlein Date: Fri, 28 Oct 2022 18:55:51 -0300 Subject: [PATCH] feat(mostRepeatedChar): implementa funcao mostUsedChar --- 09-mostRepeatedChar/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..601edb7 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,20 @@ export function mostUsedChar(text) { // implementar logica aqui - return "" + let array = text.replace('').toLowerCase().split('') + let indice; + let repeticoes=0; + let auxiliar=0; + for(let i=0;i < array.length;i++){ + for(let j = 0;j < array.length;j++){ + if(array[i] == array[j]){ + auxiliar++ + } + if(auxiliar > repeticoes){ + repeticoes = auxiliar + auxiliar = 0 + indice = array[i] + } + } + } + return indice } \ No newline at end of file -- 2.34.1