Skip to content

Instantly share code, notes, and snippets.

@hpyhacking
Created December 1, 2012 21:21
Show Gist options
  • Save hpyhacking/4185182 to your computer and use it in GitHub Desktop.
Save hpyhacking/4185182 to your computer and use it in GitHub Desktop.
String.format coffeescript version
@format = ->
return unless arguments.length
str = arguments[0]
for i in [1...arguments.length]
re = new RegExp('\\{' + (i-1) + '\\}', 'gm')
str = str.replace(re, arguments[i])
str
describe "@format", ->
it "format normal", ->
expect(@format("def")).toEqual("def")
it "format normal", ->
expect(@format("def{0}{1}", "def", "def2")).toEqual("defdefdef2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment