fork download
  1. // A third and simpler example of recursion: summation
  2.  
  3. Y = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y)))
  4. Q = f => n => n == 0 ? 0 : n + f(n - 1)
  5. sum = Y(Q)
  6.  
  7. for (let i = 0; i <= 10; i++) {
  8. console.log(i, sum(i));
  9. }
  10.  
  11. console.log(100, sum(100))
Success #stdin #stdout 0.03s 16724KB
stdin
Standard input is empty
stdout
0 0
1 1
2 3
3 6
4 10
5 15
6 21
7 28
8 36
9 45
10 55
100 5050