-
-
Save hsuan1117/cf7c65341dbd34cc9b1eec1671e1ef2b to your computer and use it in GitHub Desktop.
應該是最美的 currying sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref: https://t.me/JavaScriptTw/52631 | |
function sum(...args) { | |
const total = args.reduce((p, c) => p + c); | |
const sumFunc = sum.bind(null, total); | |
sumFunc.valueOf = () => total; | |
return sumFunc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment