iOS Swift max(), min()
You can use the empty parameters for simple comparable data types, if you have a more complex data structures you need to provide a closure. Note: the order of the comparison are the following for both max
and min
if you do it backward you get wrong results.
[(0, "a"), (2, "b"), (5, "f"), (6, "g")].min(by: {$0.0 < $1.0}) // min (0, "a")[(0, "a"), (2, "b"), (5, "f"), (6, "g")].max(by: {$0.0 < $1.0}) // max (6, "g")