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

112
Views
Filter array on the basis of multiple filters simultaneously

I am trying to create a screener that we usually see on stock market sites. I have few variables in which I have different data on the basis of which I want to filter. There is a array this one.

let array = [{
        "sector_code": "0828",
        "listed_in": ["ALLSHR,KSE100"],
        "marketcap": 1000000,
        "closingPrice": 356
    }, {
        "sector_code": "0828",
        "listed_in": ["ALLSHR,OGTI"],
        "marketcap": 50000,
        "closingPrice": 26


    }, {

        "sector_code": "0824",
        "listed_in": ["KSE100,ALLSHR,KMIALLSHR"],
        "marketcap": 20000,
        "closingPrice": 125
    }, {
        "sector_code": "0833",
        "listed_in": ["ALLSHR, KMI30",],
        "marketcap": 300000000,
        "closingPrice": 4500


    }
]

sectorFilters = ['0828','0828']
marketFilters = ['KMI30'];
minClosingValue = 0
maxClosingValue = 100
minMarketValue = 0
maxMarketValue = 100000

ok so What I am tryig to do is lets say just like in any side filter

  1. If we have minMarketValue lets say 0 and maxMarketValue = 100000 (and no other filter applied) then I should get all the stocks within this range.
  2. but if we also get minClosingValue =0 and maxClosingValue=100( with above market filter applied ) I should also filer the array based on both the conditions.
  3. lets say someone also selcted some sectors and we get ['0828','0829','0830] now I should get all the stocks with the above two conditions satsified+ withing these sectors
  4. lets say someone also selcted some markets and we get ['KSE100','ALLSHR'] Now I should get all the stocks with above three conditions satisfied+ these markets.

I tried working on this logic and I am getting some decent output on 3 and 4 point but really dont know ho to implment first and second along with both of these combined

function array_subset() {
        return array.filter(element => {
            const is_listed = listed_inilter.some(item => element.listed_in.includes(item));
            const is_sector = sector_code.includes(element.sector_code);
            if (sector_code.length == 0) {
                return ((is_listed || is_sector))
            } else {
                return ((is_listed && is_sector))
            }
        });
    }
    console.log(array_subset());

I am also attaching the js file script so that if someone wants to see the details as i have tried to make things simpler her

Please do ask if I didn't make my points clear and you are confused.

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