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]
> 
> thanks


letters = ("a".."z").to_a
last_index = letters.length - 1

results = []

0.step(last_index, 2) do |i|
  results << letters[i]
end

letters = results
p letters

--output:--
["a", "c", "e", "g", "i", "k", "m", "o", "q", "s", "u", "w", "y"]
-- 
Posted via http://www.ruby-forum.com/.