Last active
June 26, 2019 17:43
-
-
Save danielkellyio/b1d08ec9e0388199593b825edd33358c to your computer and use it in GitHub Desktop.
The best way I've found to to set a variable based on multiple conditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In helper file with global helper functions | |
function switchMap(before_value, map={}, default_value=false){ | |
return Object.keys(map).includes(before_value) ? map[before_value] : default_value; | |
} | |
//In code where condition is needed | |
var friendly_timezone = switchMap(tz_timezone, { | |
'America/New_York': 'Eastern', | |
'America/Chicago': 'Central', | |
'America/Denver': 'Mountain', | |
'America/Los_Angeles': 'Pacific', | |
}, "No Timezone Specified"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment