0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

reduce(_: _:)メソッドを用いた要素を一つにまとめる処理について

Posted at

reduce(::)メソッドを用いた配列の要素を一つにまとめる処理について

・Sequenceプロトコルが提供するインターフェースであるreduce(::)メソッドは、要素を一つにまとめる処理ができる。

例:配列の要素内の数値を全て足し合わせるような処理を行いたい時

let numArray = [1,2,3,4,5]

//第1引数に初期値、第2引数に要素を結果に反映する処理を指定する
let sum = numArray.reduce(0, +)

print(sum) //15
0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?