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

113
Visualizações
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
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