desafio 09 concluido

This commit is contained in:
Douglas Vinicius Nobrega 2022-10-29 02:04:11 -03:00
parent 35269078e8
commit 70fd2a1c47
3 changed files with 49 additions and 12 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use o IntelliSense para saber mais sobre os atributos possíveis.
// Focalizar para exibir as descrições dos atributos existentes.
// Para obter mais informações, acesse: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}

View File

@ -1,4 +1,26 @@
export function mostUsedChar(text) {
// implementar logica aqui
return ""
let arr = [];
for (let i = 0; i < text.length; i++) {
let letra = text[i]
if(arr[letra]) {
arr[letra]++
} else {
arr[letra] = 1
}
}
return returnValue(text, arr);
}
function returnValue(text, arr) {
let maiorValor = 0
let letraMaiorValor = ""
for (let i = 0; i < text.length; i++) {
let letra = text[i]
let qtdLetra = arr[letra]
if(qtdLetra > maiorValor) {
maiorValor = qtdLetra
letraMaiorValor = letra
}
}
return letraMaiorValor
}