I'm trying to calculate somebody's bowel health based on a points system. I can edit the data structure, or logic in any way. I'm just trying to write a function and data structure to handle this ability.
Pseudo calculator function:
// Bowel health calculator
var points = 0;
If age is from 30 and 34:
points += 1
If age is from 35 and 40:
points += 2
If daily BMs is from 1 and 3:
points -= 1
If daily BMs is from 4 and 6:
points -= 2
return points;
Pseudo data structure:
var points_map = {
age:
{
'35-40': 1,
'40-45': 2,
'45-50': 6,
'50-55': 2,
'55-60': 1,
'60-65': 4,
'65-70': 3,
'70-75': 1,
'75-150': 2
},
dbm:
{
'1-3': -1,
'4-6': -2,
'7-9': -3,
'10-150': 5
}
// This plus about 10 more metrics like them (all with the same "Map a plus or minus value to each range" logic)
};
I have a full spreadsheet of data like this, and I am trying to write a DRY version of code and a DRY version of this data (ie, probably not a string for the '30-34', etc) in order to handle this sort of thing without a humongous number of switch
statements.