Created
June 11, 2014 07:58
-
-
Save khamiltonuk/0eae34869ffff7ac0eb0 to your computer and use it in GitHub Desktop.
Adding and subtracting all the arguments in a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sum(){ | |
| var result = 0, | |
| i = 0, | |
| len = arguments.length; | |
| while (i < len){ | |
| result += arguments[i]; | |
| i++; | |
| } | |
| return result; | |
| } | |
| function takeaway(){ | |
| var result = arguments[0], | |
| i = 1, | |
| len = arguments.length; | |
| while (i < len){ | |
| result -= arguments[i]; | |
| i++; | |
| } | |
| return result; | |
| } | |
| console.log(takeaway(1,3,2,2,4,1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment