On 16.11.2006 02:33, Bernard K. wrote:
This works fine
sum = 0
arr = (1…10).to_a
arr.inject(0) { |sum, i| sum += ( i == 3 ? 0 : i ) } => 52
We had similar suggestions already. Also, this is more efficient:
(1…10).inject(0) {|sum, i| i == 3 ? sum : sum + i}
Regards
robert