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
sum(1, 2, 3).valueOf() // 6 sum(2, 3)(2).valueOf() // 7 sum(1)(2)(3)(4).valueOf() // 10 sum(2)(4, 1)(2).valueOf() // 9
const sum = () => { let args = [...arguments]; const func = () => { args = [...args, ...arguments]; return func; } func.valueOf = () => args.reduce((cur, prev) => cur + prev); return func; }
const sum = (...args1) => { const fullArgs = [...args1]; const fn = (...args2) => { // 收集参数 fullArgs.push(...args2) // 返回自身保持链式调用 return fn; }; // 重写valueOf,累加已收集的参数 fn.valueOf = () => fullArgs.reduce((total, cur) => total + cur) return fn; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: