Created
January 29, 2013 19:30
-
-
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.
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
#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