Skip to content

Files

Latest commit

f2d1bde · Dec 19, 2022

History

History
19 lines (13 loc) · 371 Bytes

negate.md

File metadata and controls

19 lines (13 loc) · 371 Bytes
标题 标签
negate(否定函数) function(函数)

否定谓词函数。

  • 获取一个谓词函数,并将非运算符 (!) 与其参数一起应用于它。
const negate = func => (...args) => !func(...args);

调用方式:

[1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)); // [ 1, 3, 5 ]

应用场景