Last active
August 29, 2015 14:10
-
-
Save tuxfight3r/39b9f6b1db38cc617ac0 to your computer and use it in GitHub Desktop.
ruby lambda fun
This file contains 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
#Basic lambda Hello World | |
irb(main):122:0> test=lambda{"Hello World"} | |
=> #<Proc:0x00000001393e28@(irb):122 (lambda)> | |
irb(main):123:0> test.call | |
=> "Hello World" | |
#lambda function to remove nth object from an array | |
irb(main):115:0> str=lambda {|arr,div| arr.each_with_index.map{|x,i| i+=1; next if i % div == 0; x}.compact } | |
=> #<Proc:0x00000001570a70@(irb):115 (lambda)> | |
irb(main):116:0> str.call((0..20).to_a, 3) | |
=> [0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment