Skip to content

Instantly share code, notes, and snippets.

@agoalofalife
Created October 8, 2016 17:08
Show Gist options
  • Save agoalofalife/9ced42bbefe1b4fcaf36d958a628a1dc to your computer and use it in GitHub Desktop.
Save agoalofalife/9ced42bbefe1b4fcaf36d958a628a1dc to your computer and use it in GitHub Desktop.
let name = 'Maria';
let name2 = 'Vasilij';
let age = 18;
let result = tag`My name ${name} sd sdc sdc and ${name2} and ${age}`;
function tag(srting,...values) {
return srting.reduce((prev,current,id) => {
if (id > 0) {
if (typeof values[id - 1] == 'string') {
prev += `@${values[id - 1]}`;
}
else {
prev += values[id-1];
}
}
return prev + current;
});
}
console.log( result );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment