Reputation: 395
Any shorter (or more efficient) way to write this . just to be precise, daily, weekly... are being fetched from the interface (input[select])
switch(repeatFrequency) {
case "daily":
diffDays = 1;
break;
case "weekly":
diffDays = 7;
break;
case "weekly_2":
diffDays = 14;
break;
case "monthly":
diffDays=31;//we assume the worst case
break;
case "monthly_3":
diffDays = 92;//we assume the worst case
break;
}
Upvotes: 1
Views: 57
Reputation: 7195
The better way is use hash (map) object. Something like this:
var hash = {
'daily': 1,
'weekly': 7,
'weekly_2': 14,
'monthly': 31,
'monthly_3': 93,
};
var diffDays = repeatFrequency in hash? hash[repeatFrequency] : default_value;
Upvotes: 1