Last active
June 20, 2016 21:03
-
-
Save fluffywaffles/a0ca674e758f16b017db6b65198902c1 to your computer and use it in GitHub Desktop.
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 helloWorldWithOptions (toWhom, { postfix1: p1, postfix2: p2='' }, greeting='Hello', additionalOptions={}) { | |
let { pre: preFn=String } = additionalOptions | |
return preFn(`${greeting}, ${toWhom}${p1}${p2}`) | |
} | |
helloWorldWithOptions('world', { postfix1: '!' }) // => 'Hello, world!' | |
helloWorldWithOptions('world', { postfix1: '!', postfix2: '1' }) // => 'Hello, world!1' | |
helloWorldWithOptions('Mom', { postfix1: '?' }, undefined, additionalOptions={ pre: (str) => str.toUpperCase() }) | |
// => 'HELLO, MOM?' | |
helloWorldWithOptions('world', { postfix1: '...' }, 'Goodbye') // => 'Goodbye, world...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment