Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active December 15, 2018 01:50
Show Gist options
  • Save matthewstokeley/148681250db40b6ceb40ff34551c0b8f to your computer and use it in GitHub Desktop.
Save matthewstokeley/148681250db40b6ceb40ff34551c0b8f to your computer and use it in GitHub Desktop.
objects can be used instead of conditionals and switches
/**
* 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