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

173
Views
¿Cómo resuelvo las siguientes promesas?

Estoy tratando de resolver la promesa en la función getABC, pero la variable const local b no está definida. ¿Cómo implemento la función de devolución de llamada utilizada por la función getB para que devuelva el elemento de matriz desestructurado con el valor de 'B'?

 const [A, B, C] = ['A', 'B', 'C']; function getA() { return A; } function getB(callback) { setTimeout(() => { callback(B); }, 10); } function getC() { return Promise.resolve().then(() => C); } function getABC() { return new Promise((resolve, reject) => { const a = getA(); const b = getB(b => b); const c = getC().then(item => item).catch(err => console.log(err)); resolve([a, b, c]) }); } getABC().then((arr) => console.log(arr));

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

0

También debe envolver setTimeout dentro de Promise y llamar a Promise.all antes de resolve :

 const [A, B, C] = ['A', 'B', 'C']; function getA() { return A; } function getB(callback) { return new Promise((resolve, reject) => { setTimeout(() => { resolve(callback(B)); }, 10); }); } function getC() { return Promise.resolve().then(() => C); } function getABC() { return new Promise((resolve, reject) => { const a = getA(); const b = getB(b => b); const c = getC().then(item => item).catch(err => console.log(err)); resolve(Promise.all([a, b, c])); }); } getABC().then(arr => console.log(arr));

Todo esto realmente se puede simplificar si usa async/await.

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!