使用ramda获取列表中最大的项目
Obtaining the largest item in a list using ramda
我正在尝试 return 列表中最大的元素 page
:
page = [1,2,3];
R.max(page); // returns a function.
R.max(-Infinity, page); // seems correct but doesn't work as expected.
我没有安装 ramda
包,所以这是未经测试的,但是从文档 max() only takes two arguments, so you would have to reduce() 你的阵列上看:
var page = [1, 2, 3],
result = R.reduce(R.max, -Infinity, page);
// 'result' should be 3.
使用apply
函数:https://ramdajs.com/0.22.1/docs/#apply
const page = [1, 2, 3];
R.apply(Math.max, page); //=> 3
我正在尝试 return 列表中最大的元素 page
:
page = [1,2,3];
R.max(page); // returns a function.
R.max(-Infinity, page); // seems correct but doesn't work as expected.
我没有安装 ramda
包,所以这是未经测试的,但是从文档 max() only takes two arguments, so you would have to reduce() 你的阵列上看:
var page = [1, 2, 3],
result = R.reduce(R.max, -Infinity, page);
// 'result' should be 3.
使用apply
函数:https://ramdajs.com/0.22.1/docs/#apply
const page = [1, 2, 3];
R.apply(Math.max, page); //=> 3