简体   繁体   中英

Obtaining the largest item in a list using ramda

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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM