Skip to content

Instantly share code, notes, and snippets.

@twilson63
Created July 31, 2011 14:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save twilson63/1116813 to your computer and use it in GitHub Desktop.
Save twilson63/1116813 to your computer and use it in GitHub Desktop.
Common CoffeeScript Idoms - from the little book on CoffeeScript

Common CoffeeScript Idoms

Each

myfunction(item) for item in items

Map

result = (item.name for item in items)

Select

result = (item for item in items when item.name is "foobar")

Include

included = "foobar" in ["bar", "foobar", "foo"]

Include in a string

foo = "A dog walks down a path in the park."
included = !!~ foo.indexOf "dog"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment