Created
August 15, 2024 19:28
-
-
Save VinixGonzalez/308d25d8f28eb6a1e6deb81e4ff4649e to your computer and use it in GitHub Desktop.
Parte 2 - Questão 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countStrings(arr) { | |
| // Objeto para armazenar a contagem dos termos | |
| const counter = {}; | |
| // Itera sobre cada item da lista | |
| for (let str of arr) { | |
| // Converte para minúsculas | |
| const lowerStr = str.toLowerCase(); | |
| // Incrementa a contagem | |
| if (counter[lowerStr]) { | |
| counter[lowerStr]++; | |
| } else { | |
| counter[lowerStr] = 1; | |
| } | |
| } | |
| // Imprime a contagem | |
| for (let term in counter) { | |
| console.log(`${term}=${count[term]}`); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment