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
之前有写过一篇文章,是说柯里化函数和函数组合, 看完之后真是大受脾益,尤其是在看redux源码的时候,就感觉很顺通。
redux
今天上午看了下简书,发现了一个被面试到的问题,思考了下。问题是这样的:
函数闭包与柯里化(让手写一个函数完成求和操作,func(1)(2)(3)、func(1,2)(3)和func(1,2,3)都能保证可以正常求和)
function add(...args) { return args.reduce((total, item) => total = total + item, 0) } function func(fn){ return (length) => (...args) => (length - args.length) ? func(fn)(length).bind(null, ...args) : fn(...args) } add3 = func(add)(3) add3(1)(2)(3) add3(1,2)(3) add3(1,2,3)
上面的func看起来有些怪怪的, 有这个func(fn)(length),那么我们来改下下
func
func(fn)(length)
function func(fn){ return (length) => varFun = (...args) => (length - args.length) ? varFun.bind(null, ...args) : fn(...args) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
之前有写过一篇文章,是说柯里化函数和函数组合, 看完之后真是大受脾益,尤其是在看
redux
源码的时候,就感觉很顺通。今天上午看了下简书,发现了一个被面试到的问题,思考了下。问题是这样的:
上面的
func
看起来有些怪怪的, 有这个func(fn)(length)
,那么我们来改下下The text was updated successfully, but these errors were encountered: