James Gray
5/9/2008 2:39:00 PM
On May 9, 2008, at 9:16 AM, Tim Conner wrote:
> What is the best way to delete every other value in a ruby array?
> e.g.
> %w(a b c d e f g h i j k)
>
> becomes => [a c e g i k]
>> ary = ("a".."k").to_a
=> ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]
>> require "enumerator"
=> true
>> ary.enum_slice(2).map { |pair| pair.first }
=> ["a", "c", "e", "g", "i", "k"]
Hope that helps.
James Edward Gray II