Last active
December 19, 2015 11:19
-
-
Save ox/5946368 to your computer and use it in GitHub Desktop.
printf bunny
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 printf = function (str) { | |
var args = Array.prototype.slice.call(arguments) | |
console.log(str.split('%').map(function (e, i) { | |
return (e[0] === 'x' ? String(args[i]) + e.substr(1) : e) | |
}).join('')) | |
} | |
printf('hello world') // => hello world | |
printf('number: %x, string: %x', 1, 'foo') // => number: 1, string: foo | |
printf('number: %x, string: %x', 'lol', 1, 'foo') // => number: lol, string: 1 | |
printf('%xnumber: %x, string: %x', 'lol', 1, 'foo') // => lolnumber: 1, string: foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"{0} is easier for {1}".format("this", "me")