Created
December 17, 2018 14:38
-
-
Save vssn/a8b8396cea7b7c550c33b6c12ac574af to your computer and use it in GitHub Desktop.
Combine template strings with custom functions
This file contains hidden or 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 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