Ruby3.0.0
Arrayクラスmap
mapメソッドは配列を返す
#配列の値全てに数式を入力(nは変数)
a[0,1,2]
a.map{|n| n + 1} # => [1,2,3]
#配列の値全てを文字列に変換する
a.map(&:to_s)
#n個✖️nの配列に特定の値(0)を入力する
n = 2
a = Array.new(n).map{Array.new(n,0)}
puts a
# => [[0,0],[0,0]]
Go to list of users who liked
More than 1 year has passed since last update.
Ruby3.0.0
Arrayクラスmap
mapメソッドは配列を返す
#配列の値全てに数式を入力(nは変数)
a[0,1,2]
a.map{|n| n + 1} # => [1,2,3]
#配列の値全てを文字列に変換する
a.map(&:to_s)
#n個✖️nの配列に特定の値(0)を入力する
n = 2
a = Array.new(n).map{Array.new(n,0)}
puts a
# => [[0,0],[0,0]]
Register as a new user and use Qiita more conveniently
Go to list of users who liked