Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Cómo convertir una matriz en un objeto. Los elementos de la matriz deben ser claves y los valores deben generarse desde la devolución de llamada

Estoy tratando de codificar la función arrToObj para lograr los registros de consola deseados. arrToObj debe devolver un objeto que tenga elementos de la matriz pasada como claves, y las salidas de la devolución de llamada (cuando esos elementos se pasan) como los valores correspondientes.

Aquí está el código que me dan...

 function arrToObj(array, callback) { // ADD CODE HERE } // Uncomment these to check your work! const arrOfStrings = ['beer', 'glue']; const capitalize = str => str.toUpperCase(); console.log(arrToObj(arrToObj(arrOfStrings, capitalize)); // should log: { beer: 'BEER', glue: 'GLUE' }

No estoy seguro de por dónde empezar. Las sugerencias o soluciones son bienvenidas. ¡Gracias por tu tiempo!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solo puedes usar reducir

 function arrToObj(array, callback) { return array.reduce((acc, next) => { return { ...acc, [next]: callback(next), }; }, {}) } // Uncomment these to check your work! const arrOfStrings = ['beer', 'glue']; const capitalize = str => str.toUpperCase(); console.log(arrToObj(arrOfStrings, capitalize)); // should log: { beer: 'BEER', glue: 'GLUE' }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!