Skip to content

Instantly share code, notes, and snippets.

@nathanaelnsmith
Last active November 3, 2016 23:29
Show Gist options
  • Save nathanaelnsmith/370592258e0b289582a6c2aa4ccdaf18 to your computer and use it in GitHub Desktop.
Save nathanaelnsmith/370592258e0b289582a6c2aa4ccdaf18 to your computer and use it in GitHub Desktop.
Append or prepend a string to a predefined string
var prepend = concatStrings('prependWith-'),
append = concatStrings('-appendWith', true);
console.log(prepend('baseString')); // outputs prependWith-baseString
console.log(append('baseString')); // outputs baseString-appendWith
function concatStrings (classFragmentA, reverse) {
return function (classFragmentB) {
var fragments = [classFragmentA, classFragmentB];
return (reverse) ? fragments.reverse().join('') : fragments.join('');
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment