Answer the question
In order to leave comments, you need to log in
Change value in hash?
array = [ { 1 => 5, 23 => 1}, { 2 => 6, 22 => 2} ]
hash = { 1 => 5, 23 => 1}
array <<
hash having a key keys[0] == hash.keys[0] then you need to increase its value by +1.
End result array = [ { 1 => 6 , 23 => 1}, { 2 => 6, 22 => 2} ]
Answer the question
In order to leave comments, you need to log in
Wrote in haste
array = [ { 1 => 5, 23 => 1}, { 2 => 6, 22 => 2} ]
hash = { 1 => 5, 23 => 1}
array = array.map do |x|
first_key = x.keys[0]
x[first_key] = x[first_key] + 1 if first_key == hash.keys[0]
x
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question