Skip to content

Instantly share code, notes, and snippets.

@vssn
Created December 17, 2018 14:38
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 vssn/a8b8396cea7b7c550c33b6c12ac574af to your computer and use it in GitHub Desktop.
Save vssn/a8b8396cea7b7c550c33b6c12ac574af to your computer and use it in GitHub Desktop.
Combine template strings with custom functions
function endSentenceWithYo(template, ...expressions) {
return template.reduce((accumulator, part, i) => {
return accumulator + expressions[i - 1] + part
}) + ", yo!"
}
let type = 'delivery guy';
let name = 'Barry';
let says = 'Here ye go';
var template = endSentenceWithYo`The ${type} ${name} says: ${says}`;
console.log(template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment