Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function sumRecur(...args) {
  2. if (args.length <= 2) {
  3. return args[0] + args[1];
  4. }
  5. return (
  6. args[0] +
  7. sumRecur(...args.slice(1))
  8. );
  9. }
  10.  
  11. sumRecur(3,4,5); // 12
  12.  
  13. // Transpiled to ES5
  14. "use strict";
  15.  
  16. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  17.  
  18. function sumRecur() {
  19. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  20. args[_key] = arguments[_key];
  21. }
  22.  
  23. if (args.length <= 2) {
  24. return args[0] + args[1];
  25. }
  26. return args[0] + sumRecur.apply(undefined, _toConsumableArray(args.slice(1)));
  27. }
  28.  
  29. sumRecur(3, 4, 5);
  30.  
  31.  
  32.  
  33. 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement