Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 865
Jim Avatar asked Nov 30 '22 10:11

Jim


2 Answers

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.
like image 66
Frédéric Hamidi Avatar answered Dec 02 '22 00:12

Frédéric Hamidi


Use the apply function: https://ramdajs.com/0.22.1/docs/#apply

const page = [1, 2, 3];
R.apply(Math.max, page); //=> 3
like image 28
Xuan Avatar answered Dec 01 '22 23:12

Xuan