I have list of ages and agesGroups
I want to take each element of the list ages and search in list ageGroup the interval where it is to recover the price ,If an element is in two interval so we recover the lowest price of the list ,I want the sum of the total prices.
For example :
for age 8 I have price =50 and for 20 and 67 i have two choices 90 and 70 ,I will choose the lowest price which is 70 and then the result have to be 70 + 70 + 50 = 190 price = 190
let ages = [8, 20, 67]
let agesGroups = [{
min: 10,
max: 90,
price: 90
},
{
min: 10,
max: 90,
price: 70
},
{
min: 0,
max: 10,
price: 50
}
]
let price = 0
ages.forEach(a => {
agesGroups.forEach(s => {
if (a >= s.min && a <= s.max) {
price = price + parseInt(s.price, 10);
}
})
})
console.log(price);
The result that i got
price = 140