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

148
Vistas
Is it possible to pass multiple arguments to JS Promise.resolve()?

I am trying to learn promises in JS. I have a function that computes the sum or difference of two numbers depending on operation provided by the user.

function compute(firstNum, secondNum, operation) {
    let result = null;
    operation === "+"
        ? (result = firstNum + secondNum)
        : operation === "-"
        ? (result = firstNum - secondNum)
        : console.log("operation not supported");
    return result;
}

I am trying to define a function that returns a promise which does essentially the same thing as the compute function above.

let operators = {
    "+": function (a, b) {
        console.log(a + b);
    },
    "-": function (a, b) {
        console.log(a - b);
    },
};

function calculate(firstNum, secondNum, operation) {
    return new Promise((resolve, reject) => {
        if (operation === "+" || operation === "-")
            resolve([firstNum, secondNum, operation]);
        else reject(new Error("operation not supported"));
    });
}

calculate(5, 51, "-")
    .then((returnedArr) => {
        let answer = operators[returnedArr[2]](returnedArr[0], returnedArr[1]);
    })
    .catch((err) => {
        console.log(err);
    });

Is it possible to pass more than one argument to resolve() inside a promise?

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