Discuss / JavaScript / 练习

练习

Topic source
var sout = () => console.log('out out out!')
var zero = (f) => ((x) => x) // 定义数字 0
zero(sout)()
var one = (f) => ((x) => f(x)) // 定义数字 1
one(sout)()
function add(n, m) {
  return ((f) => ((x) => m(f)(n(f)(x))))
} // 定义加法
var two = add(one, one) // (f) => ((x) => f(f(x)))
two(sout)()
var four = add(two, two) // (f) => ((x) => f(f(f(f(x)))))
four((x) => x * x)(2)

  • 1

Reply