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

174
Vistas
Find the minimum value of array of object with conditions
    let event = [
    {
        "vendorBidId": 58,
        "participantName": "bro.gee@test.in",
        "bidAmount": 10000,
        "productionRate": 10000,
        "bidTime": "2021-10-21T14:55:05.957324",
        "isYou": false,
        "awarded": false
    },
    {
        "vendorBidId": 57,
        "participantName": "test@gmail.com",
        "bidAmount": 20000,
        "productionRate": 20000,
        "bidTime": "2021-10-21T14:50:24.493522",
        "isYou": false,
        "awarded": true
    },
    {
        "vendorBidId": null,
        "participantName": "bro+2@test.com",
        "bidAmount": 0,
        "productionRate": null,
        "bidTime": null,
        "isYou": false,
        "awarded": false
    },
    {
        "vendorBidId": null,
        "participantName": "bro.hey@test.com",
        "bidAmount": 0,
        "productionRate": null,
        "bidTime": null,
        "isYou": true,
        "awarded": false
    }
]

Here I want to find the minimum bidAmount, but after checking below condition,

  1. Skip if vendorBidId is null

I tried to do like this.

let minimum = event.reduce(function(prev, curr) {
    return prev.bidAmount < curr.bidAmount ? prev : curr;
});

But and tried to add my condition also. But doesn't work well.

I want just the minimum bidAmount (skip for vendorBidId is null) only.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Math.min on a Filter and map

let event = [{ "vendorBidId": 58, "participantName": "bro.gee@test.in", "bidAmount": 10000, "productionRate": 10000, "bidTime": "2021-10-21T14:55:05.957324", "isYou": false, "awarded": false }, { "vendorBidId": 57, "participantName": "test@gmail.com", "bidAmount": 20000, "productionRate": 20000, "bidTime": "2021-10-21T14:50:24.493522", "isYou": false, "awarded": true }, { "vendorBidId": null, "participantName": "bro+2@test.com", "bidAmount": 0, "productionRate": null, "bidTime": null, "isYou": false, "awarded": false }, { "vendorBidId": null, "participantName": "bro.hey@test.com", "bidAmount": 0, "productionRate": null, "bidTime": null, "isYou": true, "awarded": false } ]

const min = Math.min(...event
  .filter(evt => evt.vendorBidId)
  .map(({bidAmount}) => bidAmount)
);  

console.log(min)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Using reduce is a simple approach (if you want the entire object).

If you just need the minimum vakue, you can use Math.min after mapping the minAmount key values.

  let event = [
    {
        "vendorBidId": 58,
        "participantName": "bro.gee@test.in",
        "bidAmount": 10000,
        "productionRate": 10000,
        "bidTime": "2021-10-21T14:55:05.957324",
        "isYou": false,
        "awarded": false
    },
    {
        "vendorBidId": 57,
        "participantName": "test@gmail.com",
        "bidAmount": 20000,
        "productionRate": 20000,
        "bidTime": "2021-10-21T14:50:24.493522",
        "isYou": false,
        "awarded": true
    },
    {
        "vendorBidId": null,
        "participantName": "bro+2@test.com",
        "bidAmount": 0,
        "productionRate": null,
        "bidTime": null,
        "isYou": false,
        "awarded": false
    },
    {
        "vendorBidId": null,
        "participantName": "bro.hey@test.com",
        "bidAmount": 0,
        "productionRate": null,
        "bidTime": null,
        "isYou": true,
        "awarded": false
    }
]

const min = event.reduce(function(prev, curr) {
    return prev.bidAmount < curr.bidAmount && curr.vendorBidId ? prev : curr;
});

console.log(min);

var minValue = Math.min(...event.map(item => item.vendorBidId ?   item.bidAmount : 0));

console.log(minValue);

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