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

234
Views
¿Por qué esta función devuelve un objeto modificado a pesar de que el reemplazo se activa mediante una llamada recursiva que usa un nuevo objeto?

Estoy tratando de rastrear y descifrar el siguiente código.

 const strip2 = (object, path) => { const keys = [path]; const pathArray = keys[0].split('.'); pathArray.reduce((prevObj, key, index) => { if (!prevObj[key]) { return null; } if (Array.isArray(prevObj[key])) { return prevObj[key].map(item => strip2(item, pathArray[index + 1])); } if (index === pathArray.length - 1) { prevObj[key] = prevObj[key].replace('/hello', ''); } }, object); return object; }; strip2( { title: 'this is the title', menu: [ { link: '/hello/contact', title: 'Contact Us', }, { link: '/hello/faq', title: 'Faq', }, ], }, 'menu.link' ); \\ it will return { title: 'this is the title', menu: [ { link: '/contact', title: 'Contact Us' }, { link: '/faq', title: 'Faq' } ] }

Como puede ver, la función de reemplazo solo se activa mediante la llamada recursiva que usa un nuevo objeto pero se cambia el objeto original.

about 4 years ago · Juan Pablo Isaza
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!