Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Created January 2, 2018 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mojavelinux/183d27cc8539e1fa9d111d0915de7823 to your computer and use it in GitHub Desktop.
Save mojavelinux/183d27cc8539e1fa9d111d0915de7823 to your computer and use it in GitHub Desktop.
A simple JavaScript template literal function that echos the string, populating all interpolated values.
/**
* Usage:
* const name = 'World'
* const place = '2018'
* console.log(echo`Hello, ${name}. Welcome to ${place}.`)
*/
function echo (literals, ...values) {
return literals.length > 1
? values.reduce((accum, value, idx) => accum + value + literals[idx + 1], literals[0])
: literals[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment