Skip to content

Instantly share code, notes, and snippets.

@mainyaa
Created October 4, 2012 03:15
Show Gist options
  • Save mainyaa/3831261 to your computer and use it in GitHub Desktop.
Save mainyaa/3831261 to your computer and use it in GitHub Desktop.
This is Functional Programming on CoffeeScript
_ = require "underscore"
assert = require "assert"
list = [1..6]
sum = _.chain(list)
.filter( (i) -> i % 2 == 0)
.map( (i) -> i * 2)
.reduce(
(seed, item) ->
seed + item
, 0)
.value()
assert.equal 24, sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment