Re: Delete every other value in an array
by Harry Kakueki other posts by this author
May 10 2008 5:03PM messages near this date
Re: Delete every other value in an array
|
Re: Delete every other value in an array
> >
> >
>
> Oops. My code has a bug.
>
> arr = %w[a b c d b f g h i j k l m]
>
> p arr.select{|x| arr.index(x) % 2 == 0}#> ["a", "c", "g", "i", "k", "m"]
>
> res = []
> (0...arr.length).step(2) {|x| res << arr[x]}
> p res #> ["a", "c", "b", "g", "i", "k", "m"]
>
> Harry
>
>
Or not. :)
Which do you want?
Harry
--
A Look into Japanese Ruby List in English
http://www.kakueki.com/ruby/list.html
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
|