admin管理员组文章数量:1201353
I am trying to return the largest element in a list page
:
page = [1,2,3];
R.max(page); // returns a function.
R.max(-Infinity, page); // seems correct but doesn't work as expected.
I am trying to return the largest element in a list page
:
page = [1,2,3];
R.max(page); // returns a function.
R.max(-Infinity, page); // seems correct but doesn't work as expected.
Share
Improve this question
edited Mar 17, 2017 at 9:05
Angelos Chalaris
6,7478 gold badges53 silver badges79 bronze badges
asked Jul 19, 2015 at 18:13
JimJim
16k16 gold badges89 silver badges174 bronze badges
3
|
2 Answers
Reset to default 23I 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:
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
const page = [1, 2, 3];
R.apply(Math.max, page); //=> 3
本文标签: javascriptObtaining the largest item in a list using ramdaStack Overflow
版权声明:本文标题:javascript - Obtaining the largest item in a list using ramda - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738577528a2100964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Math.min.apply(this,[1,2,3])
– vinayakj Commented Jul 19, 2015 at 18:15max
andmin
functions are binary, for reasons described in Issue 1230 and implemented in PR 1231. The answer from @FrédéricHamidi is probably the simplest way to do this. Obviously you could create a stand-alone function for this if you need it often. – Scott Sauyet Commented Jul 19, 2015 at 21:59