Last active
August 29, 2015 14:05
-
-
Save davidchase/437b752306267aba1e2c to your computer and use it in GitHub Desktop.
Format Utility
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
var format = function () { | |
var args = Array.apply(null, arguments); | |
var initial = args.shift(); | |
var replacer = function (text, replacement) { | |
return text.replace('%s', replacement); | |
} | |
return args.reduce(replacer, initial); | |
} | |
// usage: | |
// var myName = 'david'; | |
// format('hello %s', myName); | |
// prints hello david |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment