Created
April 4, 2019 17:47
-
-
Save noodle71/9f32f7668202b9704d8e1065faeacc2f to your computer and use it in GitHub Desktop.
String template builder
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 reverse(...a){ | |
let res = ''; | |
const templates = Array.isArray(a) && a.length > 0 ? a[0]:null; | |
if(templates){ | |
for(let i = 0; i < templates.length; i++) { | |
const placeholder = a[i+1]; | |
res+=templates[i]; | |
if(placeholder) res+=`${placeholder} :: ${placeholder.split('').reverse().join('')}` | |
} | |
} | |
return res; | |
} | |
reverse`Reverse this_ ${'Hello'} | |
And this -> ${'World!'} | |
And this ^^ ${'Hello World!'}`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment