Created
March 16, 2017 16:31
-
-
Save zerobias/cee00377d79066d90f637b3dfb166b95 to your computer and use it in GitHub Desktop.
Tagged template literal reduce example
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 upperExpr (template, ...expressions) { | |
return template.reduce((accumulator, part, i) => { | |
return accumulator + expressions[i - 1].toUpperCase() + part | |
}) | |
} | |
var name = 'nico' | |
var outfit = 'leather jacket' | |
var text = upperExpr`hello ${name}, you look lovely today in that ${outfit}` | |
console.log(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment