Re: Delete every other value in an array
by Robert Dober other posts by this author
May 9 2008 9:27AM messages near this date
Re: Delete every other value in an array
|
Re: Delete every other value in an array
On Fri, May 9, 2008 at 4:16 PM, Tim Conner <crofty_james@[...].com> 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]
what about #values_at
x.values_at( *(0...x.size).map{|i| (i%2).zero? && i || nil}.compact) )
too bad compact does not do what *I* want ;).
HTH
Robert
>
> thanks
> --
> Posted via http://www.ruby-forum.com/.
>
>
--
http://ruby-smalltalk.blogspot.com/
---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein
Thread:
Tim Conner
7stud --
S2
David A. Black
7stud --
Joel VanderWerf
Yermej
Robert Dober
Robert Dober
Ara.T.Howard
James Gray
rgs
Ara.T.Howard
Harry Kakueki
Harry Kakueki
Harry Kakueki
Yermej
Ara.T.Howard
|