From 7acb5a25b35f7db2ca94818edf3a14485bd2682f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cain=C3=A3=20Milech?= Date: Fri, 28 Oct 2022 18:36:38 -0300 Subject: [PATCH] feat(mostUsedChar): implementa function --- 09-mostRepeatedChar/index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/09-mostRepeatedChar/index.js b/09-mostRepeatedChar/index.js index b113ed8..252e917 100644 --- a/09-mostRepeatedChar/index.js +++ b/09-mostRepeatedChar/index.js @@ -1,4 +1,20 @@ export function mostUsedChar(text) { - // implementar logica aqui - return "" + + const objeto = {}; + let repeticoes = 0; + let maisRepetida = ''; + + for(let i of text){ + objeto[i] = objeto[i] +1 || 1; + } + + for(let i in objeto){ + if(objeto[i] > repeticoes){ + repeticoes = objeto[i]; + maisRepetida = i; + } + } + + return maisRepetida; + } \ No newline at end of file