Created
January 2, 2018 03:27
-
-
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.
This file contains 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
/** | |
* 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