I have an amount. I want to iterate the array starting from the first value and if I add the next value and it equals amount then those two values in the array should be re
Try this:
array = [1,2,3,4,7] amount = 17 master_array = (1..array.size).map { |i| array.each_slice(i).to_a } master_array.each.with_index do |e,i| p e[0] if master_array[i][0].inject(:+) == amount end