Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created November 27, 2014 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxfight3r/a350767f32038121d7ee to your computer and use it in GitHub Desktop.
Save tuxfight3r/a350767f32038121d7ee to your computer and use it in GitHub Desktop.
ruby remove nth object by object_id from array
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