1. /**
    2. 编程题:函数柯里化
    3. function curry(func) {
    4. // something
    5. }
    6. function sum(a, b, c) {
    7. return a + b + c;
    8. }
    9. let curriedSum = curry(sum);
    10. console.log(curriedSum(1, 2, 3)); // 6, still callable normally
    11. console.log(curriedSum(1)(2, 3)); // 6, currying of 1st arg
    12. console.log(curriedSum(1)(2)(3)); // 6, full currying
    13. */
    14. function curry(func) {
    15. return function fn(...agrs) {
    16. if (agrs.length >= func.length) {
    17. return func.apply(this, agrs)
    18. } else {
    19. return function (...args2) {
    20. return fn.apply(this, agrs.concat(args2))
    21. }
    22. }
    23. }
    24. }
    25. function sum(a, b, c) {
    26. return a + b + c;
    27. }
    28. let curriedSum = curry(sum);
    29. console.log(curriedSum(1, 2, 3)); // 6, still callable normally
    30. console.log(curriedSum(1)(2, 3)); // 6, currying of 1st arg
    31. console.log(curriedSum(1)(2)(3)); // 6, full currying