Last active
November 3, 2016 23:29
-
-
Save nathanaelnsmith/370592258e0b289582a6c2aa4ccdaf18 to your computer and use it in GitHub Desktop.
Append or prepend a string to a predefined string
This file contains 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
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