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

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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