Last active
December 15, 2018 01:50
-
-
Save matthewstokeley/148681250db40b6ceb40ff34551c0b8f to your computer and use it in GitHub Desktop.
objects can be used instead of conditionals and switches
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
/** | |
* This is an object | |
* where we can store methods | |
* that are accessible with a string | |
*/ | |
var conditional = { | |
humanities: () => | |
'2', | |
socialSciences: () => | |
'1' | |
} | |
/** | |
* This is our public-facing api | |
* that uses object rather than | |
* an if or switch statement | |
*/ | |
var api = { | |
findDepartmentNumber: (value) => | |
conditional[value] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment