Created
December 25, 2010 00:34
-
-
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
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
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