Ramda过滤器如果不匹配

Ramda filter if not match

本文关键字:不匹配 如果不 如果 过滤器 Ramda      更新时间:2024-02-04

我想过滤所有与条件不匹配的元素。我能够做到这一点:

var a = [1,2,3];
function notSame(x,y) {
  R.pipe(
    R.equals,
    R.not
  )
}
R.filter(
  R.pipe(
    R.equals(1),
    R.not),
  a
) // [2,3]

但我觉得必须有一个更简单的方法:)

R.reject就是你想要的:

var isOdd = (n) => n % 2 === 1;
R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]
R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}