Last active
April 16, 2017 19:38
-
-
Save mwq27/253383cb7e961e4c1e1235200609f071 to your computer and use it in GitHub Desktop.
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
function foo(strings, ...values) { | |
return strings.reduce(function(str, val, idx) { | |
/* | |
We do the 'idx > 0 ? values[idx - 1]' part because of the starting point in the accumlator (''). | |
That will be the first section of the string. | |
*/ | |
return str + (idx > 0 ? values[idx - 1] : '') + val | |
}, ''); | |
} | |
const name = 'Marques'; | |
const city = 'Chicago'; | |
console.log( | |
foo`My name is ${name} from ${city}. Is your name ${name} as well?` | |
) | |
// "My name is Marques from Chicago. Is your name Marques as well?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment