We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
所谓函数柯里化,就是把一个接受多个参数的函数转变成接受单一参数(最初的函数的第一个参数)的函数,并且返回接受余下的参数而且返回结果的函数。
假设有一个进行加法运算的函数:
function add(a, b) { console.log(a + b); }
然后我们有实现柯里化的函数叫curry,所达到的效果应该包括:
curry
currying(add, 1)(2); // 3 const addRes = currying(add, 1); addRes(5); // 6
实现以上效果的curry函数的实现方法如下:
function currying(fn, ...args) { // 如果传入的参数数量大于等于传入函数所需的参数,直接返回结果 if (args.length >= fn.length) { return fn(...args); } return function (...args2) { return currying(fn, ...args, ...args2); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
所谓函数柯里化,就是把一个接受多个参数的函数转变成接受单一参数(最初的函数的第一个参数)的函数,并且返回接受余下的参数而且返回结果的函数。
假设有一个进行加法运算的函数:
然后我们有实现柯里化的函数叫
curry
,所达到的效果应该包括:实现以上效果的curry函数的实现方法如下:
The text was updated successfully, but these errors were encountered: