Skip to content

Instantly share code, notes, and snippets.

@hsuan1117
Forked from FlandreDaisuki/sum.js
Created May 1, 2020 13:07
Show Gist options
  • Save hsuan1117/cf7c65341dbd34cc9b1eec1671e1ef2b to your computer and use it in GitHub Desktop.
Save hsuan1117/cf7c65341dbd34cc9b1eec1671e1ef2b 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