方法名 | 标签 |
---|---|
both |
函数,逻辑,初级 |
检查两个给定的函数是否为给定参赛都返回 true
。
- 对提供的
args
调用两个函数的结果,并使用逻辑与(&&
)运算符
const both = (f, g) => (...args) => f(...args) && g(...args);
const isEven = num => num % 2 === 0;
const isPositive = num => num > 0;
const isPositiveEven = both(isEven, isPositive);
isPositiveEven(4); // true
isPositiveEven(-2); // false