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

104
Vistas
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 Respuestas
Responde la pregunta

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 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