Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
how to create an object from an array and calculate values in a new object?

I have an array where each index with the same name should be counted in the object. Please check the example and result below. I'm trying to figure out a few things:

  1. how to create two new objects "viktor" and "kate" inside the object ?
  2. how to provide a calculation for each key if they are the same: "apple", "grape", "orange", "apple" and "banana" ?
const obj = {
  viktor: ["apple", "grape", "orange", "apple", "banana"],
  kate: ["grape", "orange", "apple", "grape", "banana"]
};

function calc(a) {
}

console.log(calc(obj));

// result of calc method should be equal to
// {
//   viktor: {
//     apple: 2,
//     grape: 1,
//     orange: 1,
//     banana: 1
//   },
//   kate: {
//     apple: 1,
//     grape: 2,
//     orange: 1,
//     banana: 1
//   }
// }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda