Skip to content

Instantly share code, notes, and snippets.

@noodle71
Created April 4, 2019 17:47
Show Gist options
  • Save noodle71/9f32f7668202b9704d8e1065faeacc2f to your computer and use it in GitHub Desktop.
Save noodle71/9f32f7668202b9704d8e1065faeacc2f to your computer and use it in GitHub Desktop.
String template builder
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