Created
November 27, 2014 17:57
-
-
Save tuxfight3r/a350767f32038121d7ee to your computer and use it in GitHub Desktop.
ruby remove nth object by object_id from array
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
str=lambda {|arr,div| arr.each_with_index.map{|x,i| i=i+1; next if i % div == 0; x}.compact } | |
=> #<Proc:0x000000015a7138@(irb):138 (lambda)> | |
irb(main):139:0> str.call((0..20).to_a, 3) | |
=> [0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19] | |
irb(main):140:0> str.call((1..20).to_a, 3) | |
=> [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment