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

187
Views
Subrayar "predeterminados" desde cero

He estado tratando de reescribir el método _.defaults de underscore.js y sigo recibiendo este error:

debe copiar las propiedades de origen a propiedades indefinidas en el objeto de destino‣ AssertionError: esperado { a: 'existente' } para igualar profundamente { a: 'existente', b: 2, c: 3, d: 4 }

Aquí están las condiciones que faltan:

-debe copiar las propiedades de origen a propiedades no definidas en el objeto de destino y debe devolver el objeto de destino

y mi codigo:

 _.defaults = function (destination, source) { Object.keys(destination).forEach(key => { if (destination[key] === undefined || destination[key] === null) { destination[key] = source[key]; } }) return destination; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La idea en _.defaults es que las claves del objeto de origen pueden faltar por completo en el objeto de destino. Por lo tanto, debe iterar las claves del objeto de origen en lugar de las del objeto de destino:

 _.defaults = function (destination, source) { Object.keys(source).forEach(key => { if (destination[key] === undefined || destination[key] === null) { destination[key] = source[key]; } }) return destination; };

Nota al margen: puede escribir x == null en lugar de x === null || x === undefined . Ahorra algunas preciosas pulsaciones de teclas.

 _.defaults = function (destination, source) { Object.keys(source).forEach(key => { if (destination[key] == null) { destination[key] = source[key]; } }) return destination; };
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!