Can anyone help me with filtering a range of values from a json object?
Here is the range data I am working with:
const contractAmountRange = [
{ id: '1', min: 0, max: 100000, description: 'Less than $100,000' },
{
id: '2',
min: 100001,
max: 500000,
description: '$100,001 to $500,000',
},
{
id: '3',
min: 500000,
max: 1000000,
description: '$500,000 to $1,000,000',
},
{
id: '4',
min: 1000001,
max: 5000000,
description: '$1,000,001 to $5,000,000',
},
{
id: '5',
min: 5000000,
description: 'More than $5,000,000',
},
];
I am trying to filter the json object based on the chosen range from the above data.
const data = [
{
tenderNo: 'ASHQ17HH26334',
awardedAmt: 400000,
yearAwarded: 2015,
},
{
tenderNo: 'BFG8765TT14000008',
awardedAmt: 300000,
yearAwarded: 2015,
},
{
tenderNo: 'AFSH00ETT14000009',
awardedAmt: 76071.21,
yearAwarded: 2015,
},
];
This is my current progress:
data represents the json object
contractAmountRange contains the available ranges
rangeSelected is the id of the chosen range
const filterData = (data, contractAmountRange, rangeSelected) => {
// let maxRange, minRange;
const rangeMap = {};
for (const item of contractAmountRange) {
rangeMap[item.id] = item;
}
const filteredData = data.filter((el) => {
return (
?????
);