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

103
Visualizações
Multiplication within payload

I am working on a product, and I am trying to create a payload. I need total to be equal to totalPrice*taxRate. I tried doing this by:

total: selectedQuantities.reduce((a, c) => a + c.value * c.price, 0).reduce((m, n) => m * n.taxRate)

and by:

total: selectedQuantities.reduce((a, c) => a + c.value * c.price, 0) * devolucionItems.taxRate

Neither of these worked, and I really appreciate any help or advice with this, thank you!

Full Payload:

const returnPayload = {
            ...devolucionItems,
            qty: totalQuantity,
            seller: devolucionItems.user._id,
            orderItems: devolucionItems.orderItems.map((item) => {
                const result = selectedQuantities.find((selectedItem) => selectedItem.id === item._id);
                return { ...item, qty: result.value, price: +result.price * +result.value, tax: result.tax};
            }),
            itemsPrice: selectedQuantities.reduce((a, c) => a + c.price, 0),
            totalPrice: selectedQuantities.reduce((a, c) => a + c.value * c.price, 0),
            taxRate: devolucionItems.taxRate,
            total: selectedQuantities.reduce((a, c) => a + c.value * c.price, 0).reduce((m, n) => m * n.taxRate),
        };```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I am not sure why it means that it is not working. In your calculation 2nd, reduce will not work.

I would suggest giving more context like the input object and what you get and what you expected etc. I was trying to create the context you can check below which is working fine as expected.

const devolucionItems = { taxRate:10 }

const selectedQuantities = [
    {value: 1, price: 100},
    {value: 1, price: 100},
    {value: 1, price: 100},
]

const returnPayload = {
            ...devolucionItems,
            itemsPrice: selectedQuantities.reduce((a, c) => a + c.price, 0),
            totalPrice: selectedQuantities.reduce((a, c) => a + c.value * c.price, 0),
            taxRate: devolucionItems.taxRate,
            total: selectedQuantities.reduce((a, c) => a + c.value * c.price, 0) * (devolucionItems.taxRate / 100),
        };

console.log(returnPayload);

Output:

{taxRate: 10, itemsPrice: 300, totalPrice: 300, total: 30}

10 % of 300 = 30

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