Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var sum = dispatcher([
- function() { return 0 },
- function(x) { return x },
- function(x, y) { return x + y }
- ], function(x, y, z) {
- return Array.prototype.slice.call(arguments, 1).reduce(function(x, y) {
- return sum(x, y)
- }, x)
- })
- sum() // => 0
- sum(2) // => 2
- sum(2, 3) // => 5
- sum(2, 3, 4) // => 9
Add Comment
Please, Sign In to add comment