[英]Obtaining the largest item in a list using ramda
I am trying to return the largest element in a list page
:我正在尝试返回列表page
的最大元素:
page = [1,2,3];
R.max(page); // returns a function.
R.max(-Infinity, page); // seems correct but doesn't work as expected.
I don't have the ramda
package installed, so this is untested, but from the documentation max() only takes two arguments, so you would have to reduce() your array upon it:我没有安装ramda
包,所以这是未经测试的,但是从文档中max()只需要两个参数,所以你必须在它上面reduce()你的数组:
var page = [1, 2, 3],
result = R.reduce(R.max, -Infinity, page);
// 'result' should be 3.
Use the apply
function: https://ramdajs.com/0.22.1/docs/#apply使用apply
功能: https : //ramdajs.com/0.22.1/docs/#apply
const page = [1, 2, 3];
R.apply(Math.max, page); //=> 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.