Skip to content

Instantly share code, notes, and snippets.

@VinixGonzalez
Created August 15, 2024 19:28
Show Gist options
  • Select an option

  • Save VinixGonzalez/308d25d8f28eb6a1e6deb81e4ff4649e to your computer and use it in GitHub Desktop.

Select an option

Save VinixGonzalez/308d25d8f28eb6a1e6deb81e4ff4649e to your computer and use it in GitHub Desktop.
Parte 2 - Questão 2
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