【发布时间】:2010-05-17 18:05:45
【问题描述】:
我正在尝试根据积分系统计算某人的肠道健康状况。我可以以任何方式编辑数据结构或逻辑。我只是想写一个函数和数据结构来处理这种能力。
伪计算器功能:
// 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;
伪数据结构:
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)
};
我有一个完整的这样的数据电子表格,我正在尝试按顺序编写代码的 DRY 版本和该数据的 DRY 版本(即,可能不是 '30-34' 的字符串等)在没有大量switch 语句的情况下处理这类事情。
【问题讨论】:
-
+1 用于开发与健康相关的应用程序(无论您是否为此付费)。
标签: javascript data-structures calculator