Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!