Created
June 29, 2014 20:32
-
-
Save jpiccari/b287bacb14fb933598d5 to your computer and use it in GitHub Desktop.
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
/** | |
* Creates a string using indexed format string | |
* @param {string} Format of string | |
* @param {...string} One or more strings to be using in the format | |
*/ | |
function formatString(/* ... */) { | |
var args = Array.apply(0, arguments); | |
return args.shift().replace(/\{(\d+)\}/g, function(match, index) { | |
return index < args.length | |
? args[index] | |
: match; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment