Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda