Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created March 16, 2017 16:31
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 zerobias/cee00377d79066d90f637b3dfb166b95 to your computer and use it in GitHub Desktop.
Save zerobias/cee00377d79066d90f637b3dfb166b95 to your computer and use it in GitHub Desktop.
Tagged template literal reduce example
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