Created
December 18, 2016 00:28
-
-
Save casprwang/64747268470df82e6c459da3835ea240 to your computer and use it in GitHub Desktop.
ES6 case
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
function getDrink(type) { | |
const drinks = new Map([ | |
['coke', () => 'Coke'], | |
['pepsi', () => 'Pepsi'], | |
['lemonade', () => 'Lemonade'], | |
['default', () => 'Default item'], | |
]); | |
const drink = drinks.has(type) ? drinks.get(type)() : drinks.get('default')(); | |
return `The drink I chose was ${drink}`; | |
} | |
console.log(getDrink('pepsi')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment