Skip to content

Instantly share code, notes, and snippets.

@EugeneAZDev
Last active October 19, 2022 18:07
Show Gist options
  • Save EugeneAZDev/6f3a12261f56e9a963c585920b078ad1 to your computer and use it in GitHub Desktop.
Save EugeneAZDev/6f3a12261f56e9a963c585920b078ad1 to your computer and use it in GitHub Desktop.
Alternative of Switch case approach
// Another approach of Switch case
// Output =>
// Result: () => {
// const r = 1 * 56
// const ar = r - 4
//
// return ar
// }
const first = () => {
const r = 1 * 56
const ar = r - 4
return ar
}
const second = () => {
return 2
}
const func = type => ({ first, second }[type] ?? 'Some specific result here.')
const result = func('first')
console.log(`Result: ${result}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment