簡體   English   中英

使用 ramda 獲取列表中最大的項目

[英]Obtaining the largest item in a list using ramda

我正在嘗試返回列表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()只需要兩個參數,所以你必須在它上面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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM