Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
UnhandledPromiseRejectionWarning: Rechazar una promesa no controlada al procesar ciertos casos con la pregunta

Tengo esta pregunta que aborda un montón de casos:

 Your function must always return a promise If data is not a number, return a promise rejected instantly and give the data "error" (in a string) If data is an odd number, return a promise resolved 1 second later and give the data "odd" (in a string) If data is an even number, return a promise rejected 2 seconds later and give the data "even" (in a string)

Escribí el código de la pregunta, pero recibí este error:

 (node:6) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: data is not defined (node:6) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Este es el código:

 const job = new Promise((resolve, reject)=>{ if(isNaN(data)){ reject('erroe') } else if(isNaN(data) && data%2!=0){ setTimeout(function(){ resolve('odd') } , 1000) } else { setTimeout(function(){ reject('even') }, 2000) } }) module.exports = job;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Esto es lo que puede hacer de manera concisa:

 const job = data => new Promise((resolve, reject) => typeof(data) === "number" ? setTimeout(() => resolve(data % 2 ? 'odd' : 'even'), 1000) : reject("error")) job("s") .then(result => console.log(result)) .catch(error => console.log(error)); job(5) .then(result => console.log(result)) .catch(error => console.log(error)) job(2) .then(result => console.log(result)) .catch(error => console.log(error))

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda