Skip to content

Instantly share code, notes, and snippets.

@FlandreDaisuki
Last active May 1, 2020 14:18
Show Gist options
  • Save FlandreDaisuki/b9a85f62b1c78d90c164eecc66f5e6f6 to your computer and use it in GitHub Desktop.
Save FlandreDaisuki/b9a85f62b1c78d90c164eecc66f5e6f6 to your computer and use it in GitHub Desktop.
應該是最美的 currying sum
// 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