How to get the maximum Double value of a tuple array in Swift?

Viewed 1664

Currently I have a tuple array defined as var myArray = [(Date, Double)]().

The output of myArray might look something like this:

[(2016-08-30 07:00:00 +0000, 1.0), (2016-09-30 07:00:00 +0000, 0.050000000000000003), 
(2016-10-30 07:00:00 +0000, 20.0), (2017-06-30 07:00:00 +0000, 6.0), 
(2017-07-30 07:00:00 +0000, 5.0)]

I am trying to get the max Double value from the array of tuples but not sure how to go about it.

I see there is a function:

myArray.max { (<#(Date, Double)#>, <#(Date, Double)#>) -> Bool in 

}

However, I'm not exactly sure how to use it if that even is the right function to use?

Can someone point me in the right direction?

5 Answers
Related