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

211
Views
Destructuring vs. `if`: ¿Cuál funcionaría mejor?

Tengo una función llamada updateLanguages que puedo escribir de dos formas.

Primero, usando desestructuración de objetos y || operador:

 const updateLanguages = async (content, post) => { const languages = new Set(); try { const attachments = post.attachments || {}; const { poll, mediaFile } = attachments; const { first, second, third, fourth } = poll || {}; const { description: mediaDescription } = mediaFile || {}; await Promise.all([ populateLanguages(content, languages), first && populateLanguages(first, languages), second && populateLanguages(second, languages), third && populateLanguages(third, languages), fourth && populateLanguages(fourth, languages), mediaDescription && populateLanguages(mediaDescription, languages) ]); } catch { languages.add("xx"); } post.languages = [...languages]; };

En segundo lugar, usando bloques if :

 const updateLanguages = async (content, post) => { const languages = new Set(); try { await populateLanguages(content, languages); const attachments = post.attachments; if(attachments) { const { poll, mediaFile } = attachments; if(poll) { const { first, second, third, fourth } = poll; await Promise.all([ first && populateLanguages(first, languages), second && populateLanguages(second, languages), third && populateLanguages(third, languages), fourth && populateLanguages(fourth, languages) ]); } if(mediaFile) { const { description: mediaDescription } = mediaFile; if(mediaDescription) { await populateLanguages(mediaDescription, languages); } } } } catch { languages.add("xx"); } post.languages = [...languages]; };

¿Cuál funcionaría más rápido y usaría menos memoria? ¿Y por qué?

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!