Last active
October 19, 2022 18:07
-
-
Save EugeneAZDev/6f3a12261f56e9a963c585920b078ad1 to your computer and use it in GitHub Desktop.
Alternative of Switch case approach
This file contains hidden or 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
// 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