Skip to content

Instantly share code, notes, and snippets.

@lg
Created December 25, 2010 00:34
Show Gist options
  • Save lg/754585 to your computer and use it in GitHub Desktop.
Save lg/754585 to your computer and use it in GitHub Desktop.
To try to pick up on CoffeeScript, i wrote a few quick functions to mimic Ruby's Array operations
Array::collect = (action) ->
for item in this
action(item)
Array::map = (action) -> this.collect(action)
Array::inject = (initial, action) ->
for item in this
initial = action(initial, item)
initial
Array::compact = ->
new_arr = []
(new_arr.push item if item?) for item in this
new_arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment