5
6

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 5 years have passed since last update.

Swift2 配列の最小値・最大値を求める

Posted at

配列から最小値・最大値を求める方法

Swift 2

let numbers = [5, 2, 3, 9, 4, 6]
let numMin = numbers.minElement()
let numMax = numbers.maxElement()
print(numMin!,numMax!)

Swift 1.2

let numbers = [5, 2, 3, 9, 4, 6]
let numMin = numbers.reduce(Int.max, combine: { min($0, $1) })
let numMax = numbers.reduce(Int.min, combine: { max($0, $1) })
print(numMin,numMax)

参考にしたサイト
http://stackoverflow.com/questions/24036514/correct-way-to-find-max-in-an-array-in-swift

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?