Guest User

Untitled

a guest
Oct 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. var sum = dispatcher([
  2. function() { return 0 },
  3. function(x) { return x },
  4. function(x, y) { return x + y }
  5. ], function(x, y, z) {
  6. return Array.prototype.slice.call(arguments, 1).reduce(function(x, y) {
  7. return sum(x, y)
  8. }, x)
  9. })
  10.  
  11. sum() // => 0
  12. sum(2) // => 2
  13. sum(2, 3) // => 5
  14. sum(2, 3, 4) // => 9
Add Comment
Please, Sign In to add comment