generate functionSun, 28 May 2023

crear una función que cuente cuántas veces se repite cada nombre y los represente con asteriscos (*). conla funcion countNameRepetitions

function countNameRepetitions(names) { /* names = ['Rafael', 'Juan', 'Alberto', 'Rafael']; output = { Rafael: 2, Juan: 1, Alberto: 1 } */ var table = {}; for (var i = 0; i < names.length; i++) { var name = names[i]; if (table[name] === undefined) { table[name] = 0; } table[name] += 1; } return table; }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant