I've got nine groups:
newFencepost
oldBoard
bigTree
largeRock
smallPebble
toughBoulder
diamondRing
emeraldNecklace
opalBracelet
and three categories
wood
, stone
& jewel
Each group belongs to one of the three categories, but the category name is not attached to the group object. So the categories know which groups belong to them, but the groups don't know which categories they belong to.
I need to write a function groupToCat()
that takes group
as its first parameter and returns the category associated with it.
I could do:
if (group == newFencepost || group == oldBoard || group == bigTree ){
var category = wood;
};
But that would be ugly, messy, and mean more work each time I add a new category or group.
Being a new programmer, I'd rather start by doing the simple things in the right way. What's a proper way to write this function without having to change it when new content is introduced?