Last active
May 1, 2020 14:18
-
-
Save FlandreDaisuki/b9a85f62b1c78d90c164eecc66f5e6f6 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