How to get the index of item in:
my_array.inject {|rs,item| rs += item}
I need to summarize all except the i-th element.
Just summarize over the indices.
(0...a.size).inject(0) { |sum, index| if index != (i - 1) then sum + my_array[i] else sum }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With