LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby】配列の要素の合計を出す

Last updated at Posted at 2021-07-17

大きさによって値段の違うフルーツがあったと仮定する。

fruits_price = [["apple", [200, 250, 220]], ["orange", [100, 120, 80]], ["melon", [1200, 1500]]]

(出力)
appleの合計金額は670円です
orangeの合計金額は300円です
melonの合計金額は2700円です

fruits_price = [["apple", [200, 250, 220]], ["orange", [100, 120, 80]], ["melon", [1200, 1500]]]

fruits_price.each do |name, prices|
  puts "#{name}の合計金額は#{prices.sum}円です"
end
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0