ポイント制で誰かの腸の健康を計算しようとしています。データ構造やロジックはどのようにでも編集できます。この機能を処理するための関数とデータ構造を作成しようとしています。
疑似電卓機能:
// 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
ステートメントがないようなものです。