Skip to content

Instantly share code, notes, and snippets.

@fluffywaffles
Last active June 20, 2016 21:03
Show Gist options
  • Save fluffywaffles/a0ca674e758f16b017db6b65198902c1 to your computer and use it in GitHub Desktop.
Save fluffywaffles/a0ca674e758f16b017db6b65198902c1 to your computer and use it in GitHub Desktop.
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