I am trying to calculate someone's bowel health based on a point system. I can edit data structure, or logic in any way, I am trying to write functions and data structures to handle this capability.
Pseudo calculator function:
// intestinal health calculator var points = 0; If age is 30 and 34: points + = 1 if age is 35 and 40: points + = 2 if daily BM is 1 and 3: points - = 1 if daily BM is between 4 and 6: points - = 2 Return points;
Pseudo-data structure:
var digits_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} // About this plus 10 additional metrics like them (all the same "map plus or zero value for each category" argument)};
I have a complete spreadsheet of data like this, and I am trying to write a DRY version of the code and a dry version of this data (i.e., probably '30s There is no string for -34 ', etc.) to handle such things without code without having switch
statement.
I thought that something in the better structure could be:
< Code> {[35,1], [40,2], [45,6]. .. [150, blank]},
then make a loop on it:
for (var i = 0; i & lt; points_map .ge Length -1; I ++) {if (val> gt; = points_map.age [i] [0] & amp; amp; & amp; ll & lt; points_map.age [i + 1] [0] ) Digit + = points_map.age [i] [1]; }
If necessary it can be made a bit more efficient but you get this idea.
Comments
Post a Comment