Created
December 3, 2019 11:52
-
-
Save Fhernd/3f19ce1e347b8fe1b3c68ff4bdf2f3f0 to your computer and use it in GitHub Desktop.
// Ejercicio 191: Contar las ocurrencias de los elementos de un arreglo con forEach.
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
// Ejercicio 191: Contar las ocurrencias de los elementos de un arreglo con forEach. | |
// Solución: | |
let numeros = [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8]; | |
let conteo = {}; | |
numeros.forEach((valor) => { | |
if(conteo[valor]){ | |
conteo[valor] += 1; | |
} else { | |
conteo[valor] = 1; | |
} | |
}); | |
console.log(numeros); | |
console.log(conteo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment