function eq (y) {
  return function forX(x) {
    return x === y
  }
}

function mod (y) {
  return function forX (x) {
    return x % y
  }
}

function compose (fn2, fn1) {
  return function composed (val) {
    return fn2(fn1(val))
  }
}

function not (fn) {
  return function negated (...args) {
    return !fn(...args)
  }
}

isOdd = compose(
  eq(1),
  mod(2)
)

isEven = not(isOdd)

let fiveIsOdd = isOdd(5)
let fourIsEven = isEven(4)

console.log(`5 is odd ${fiveIsOdd}`)
console.log('4 is even', fourIsEven)

相关文章:

  • 2021-10-02
  • 2021-08-22
  • 2021-12-28
  • 2022-12-23
  • 2021-09-21
  • 2021-05-13
  • 2021-04-09
猜你喜欢
  • 2021-06-20
  • 2021-06-02
  • 2021-04-26
  • 2022-03-08
  • 2021-07-18
  • 2021-09-25
  • 2022-02-12
相关资源
相似解决方案