Re: delete_if_with_index or delete_at(array) in 1.8.6?
by James Gray other posts by this author
Jul 2 2009 5:51AM messages near this date
Re: delete_if_with_index or delete_at(array) in 1.8.6?
|
Re: delete_if_with_index or delete_at(array) in 1.8.6?
On Jul 2, 2009, at 7:20 AM, Bil Kleb wrote:
> Given an array of integers, I need to delete all those
> entries that are lower than the current array index.
> Anything more elegant available?
>
> Or perhaps an alternative way to attack the problem?
On Ruby 1.9, your very first example can almost be made to work as is:
> > a = Array.new(10) { |i| i + [-1, 0, 1][rand(3)] }
=> [-1, 1, 2, 4, 3, 5, 7, 7, 9, 10]
> > a.delete_if.with_index { |e, i| e < i }
=> [1, 2, 4, 5, 7, 7, 9, 10]
James Edward Gray II
Thread:
Bil Kleb
David A. Black
Bil Kleb
James Gray
Robert Klemme
James Gray
Robert Klemme
Bil Kleb
Robert Klemme
Bil Kleb
|