Answer the question
In order to leave comments, you need to log in
How to add hash values to an array?
There is a hash like this
[{"amount"=>"5000.00"}, {"amount"=>"250.00"}, {"amount"=>"($200.00)"}, {"amount"=>"250.00"}, {"amount"=>"300.00"}, {"amount"=>"1200.00"},
amount
to the array, the result should be like this: arr = [5000.00, 200.00, 250.00, 300.00, 1200.00]
amount
can look like this ($200.00)
and here it needs to be processed correctly, but I don’t understand how to do it. I will be grateful for any help
Answer the question
In order to leave comments, you need to log in
arr = [ {"amount"=>"5000.00"} , {"amount"=>"250.00"}, {"amount"=>"($200.00)"}, {"amount"=>"250.00"}, {"amount"=>"300.00"}, {"amount"=>"1200.00"} ]
arr.map(&:values).flatten.map { |i| i.delete('()$') } # => ["5000.00", "250.00", "200.00", "250.00", "300.00", "1200.00"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question