Newbie question working with JSON responses and arrays

Summing a set of values from an API response but getting confused
flipping between hashes and arrays. This feels like it should be really
simple.

All code provided below
https://gist.github.com/danielpatricio/e08700ffbd23b493e5fe

sum = request[“orders”].reduce(0) do |sum,item|
sum + item[“total_price”].to_r
end
puts sum
puts sum.to_f

I converted the strings representing the prices to Rationals to avoid
rounding errors.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs