Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created January 29, 2013 19:30
Show Gist options
  • Save jonelf/4666945 to your computer and use it in GitHub Desktop.
Save jonelf/4666945 to your computer and use it in GitHub Desktop.
Playing with Fibonacci in CoffeeScript and Ruby They are both kind of silly but I think I like the CoffeeScript version better.
#CoffeScript
fib = (n, i=0, j=1) -> i=j+j=i for _ in [1..n]
fib(7)
=> [1, 1, 2, 3, 5, 8, 13]
#Ruby
fib = ->(n, i=0, j=1){(1..n).map{i=j+j=i}}
fib[7]
=> [1, 1, 2, 3, 5, 8, 13]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment