Max and min in an array of Float in Swift -


According to

, to get the maximum of one array we can do:

  = [1, 6, 3, 9, 4, 6]; We have a  array and lieutenant; Float & gt;  How to do this. (Num.max = nums.reduce {int.min, {max ($ 0, $ 1)})  

, because minimum and max Not for float ?

Let's go: Array and lieutenant; Float & gt; = [2.45, 7.21, 1.35, 10.22, 2.45, 3];

The solution here works for all the visuals of comparable elements, even so Float's array:

  Let Floats: Array & Lt; Float & gt; = [2.45, 7.21, 1.35, 10.22, 2.45, 3] nummax = maxElement (floats)  

maximum element () defined in the swift It is necessary to have maximum element in the form of library

  /// `element`: ///` element 'is missing o (counted elements) fancy xacpland & lt; R: Sequence type where R.Generator.Element: Comparable & gt; (Element: r) - & gt; R.Generator.Element  

Comments