JavaScript - question regarding data structure

Posted by orokusaki on Stack Overflow See other posts from Stack Overflow or by orokusaki
Published on 2010-05-17T18:05:45Z Indexed on 2010/05/17 18:10 UTC
Read the original article Hit count: 218

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:
    {
        '30-34': 1,
        '35-40': 2
    },

    dbm:
    {
        '1-3': -1,
        '4-6': -2
    }
};

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about data-structures