Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述根据 this answer,要获得阵列的最大值,我们可以做到: let nums = [1, 6, 3, 9, 4, 6];let numMax = nums.reduce(Int.min, { max($0, $1) }) 我们如何为Array< Float>做同样的事情,因为Float没有min和max? let floats: Array<Float> = [2.45, 7.21, 1. 根据 this answer,要获得阵列的最大值,我们可以做到:

let nums = [1,6,3,9,4,6];let numMax = nums.reduce(Int.min,{ max(
let floats: Array<float> = [2.45,7.21,1.35,10.22,2.45,3];
,) })

我们如何为Array< float>做同样的事情,因为float没有min和max?

let floats: Array<float> = [2.45,3]let numMax = maxElement(floats)
解决方法 这里给出的解决方案 https://stackoverflow.com/a/24161004/1187415适用于
对于所有可比较元素的序列,因此对于一系列浮点数:

/// Returns the maximum element in `elements`.  Requires:/// `elements` is non-empty. O(countElements(elements))func maxElement<R : SequenceType where R.Generator.Element : Comparable>(elements: R) -> R.Generator.Element

maxElement()在Swift库中定义为

[+++] 总结

以上是内存溢出为你收集整理的数组 – Swift中Float数组中的Max和min全部内容,希望文章能够帮你解决数组 – Swift中Float数组中的Max和min所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
数组 – Swift中Float数组中的Max和min_app_内存溢出

数组 – Swift中Float数组中的Max和min

数组 – Swift中Float数组中的Max和min,第1张

概述根据 this answer,要获得阵列的最大值,我们可以做到: let nums = [1, 6, 3, 9, 4, 6];let numMax = nums.reduce(Int.min, { max($0, $1) }) 我们如何为Array< Float>做同样的事情,因为Float没有min和max? let floats: Array<Float> = [2.45, 7.21, 1. 根据 this answer,要获得阵列的最大值,我们可以做到:

let nums = [1,6,3,9,4,6];let numMax = nums.reduce(Int.min,{ max(
let floats: Array<float> = [2.45,7.21,1.35,10.22,2.45,3];
,) })

我们如何为Array< float>做同样的事情,因为float没有min和max?

let floats: Array<float> = [2.45,3]let numMax = maxElement(floats)
解决方法 这里给出的解决方案 https://stackoverflow.com/a/24161004/1187415适用于
对于所有可比较元素的序列,因此对于一系列浮点数:

/// Returns the maximum element in `elements`.  Requires:/// `elements` is non-empty. O(countElements(elements))func maxElement<R : SequenceType where R.Generator.Element : Comparable>(elements: R) -> R.Generator.Element

maxElement()在Swift库中定义为

总结

以上是内存溢出为你收集整理的数组 – Swift中Float数组中的Max和min全部内容,希望文章能够帮你解决数组 – Swift中Float数组中的Max和min所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/999936.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

, ) }) 我们如何", "pubDate": "2022-05-21", "upDate": "2022-05-21" }
保存
, ) }) 我们如何', author : '华为云服务', cat_name : 'app', time_y_m : '2022年05月', time_d : '21', site_motto : '内存溢出' }; {script} {script}