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