-
-
Save danielpatricio/e08700ffbd23b493e5fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is being returned from the API | |
request = | |
{"orders"=> [ | |
{"total_price"=>"31.46"}, | |
{"total_price"=>"34.95"}, | |
{"total_price"=>"31.46"}, | |
{"total_price"=>"50.95"}, | |
{"total_price"=>"39.57"}, | |
{"total_price"=>"112.37"} | |
]} | |
# This script outputs each price but I need to add them to array so I can add them with inject | |
orders = request["orders"].each do |order| | |
price = order["total_price"] | |
puts price | |
end | |
#Todo - Add all the order values to calculate a total | |
orders.inject(0){ | total, order | total + order } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment