I am building a calculator that uses two sliders like this:

I have a range of CPU and RAM data that is stored in an object like this:
var CloudPlans = {
small: {
id: 'small',
from: {
cpu: 1,
ram: 1
},
to: {
cpu: 2,
ram: 2
},
price: {
linux: 3490,
windows: 4190
}
},
medium: {
id: 'medium',
from: {
cpu: 2,
ram: 2
},
to: {
cpu: 4,
ram: 4
},
price: {
linux: 5600,
windows: 6300
}
},
large: {
id: 'large',
from: {
cpu: 4,
ram: 4
},
to: {
cpu: 6,
ram: 8
},
price: {
linux: 9500,
windows: 10200
}
},
[...more configs here]
}
Now based on the position and value of the slider, I have to check which plan the user has selected and then calculate the price of the components. Here is the function that checks the price range:
checkPlaninRange: function(cpuVal, ramVal) {
if(cpuVal >= CloudPlan.small.from.cpu && cpuVal <= CloudPlan.small.to.cpu ) {
return "small";
} else if (ramVal >= CloudPlan.small.from.cpu && ramVal <= CloudPlan.small.to.cpu) {
return "small";
}
}
As you can see I will be dealing with almost an endless list of conditionals to return the selected plan. Is there any way to simplify the storage or selection of these plan configs based on code other than conditionals or case statements?
Use an array instead:
Now you can simply iterate over
CloudPlans: