Last active
November 29, 2015 15:11
-
-
Save zhangchiqing/cedbea7c78e9e8037c54 to your computer and use it in GitHub Desktop.
add.js
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
/* | |
* Provide the implementations for 3 `add` functions to output the same value as commented | |
* without using if-else or switch-case | |
*/ | |
var num = 1; | |
var add = function(n) { | |
// to implement | |
}; | |
var addNum = add(num); | |
addNum(2); | |
// => 3 | |
addNum(2); | |
// => 3 | |
num = 4; | |
addNum(2); | |
// => 3 | |
var num = 1; | |
var add = function(n) { | |
// to implement | |
}; | |
var addNum = add(num); | |
addNum(2); | |
// => 3 | |
addNum(2); | |
// => 5 | |
num = 4; | |
addNum(2); | |
// => 7 | |
var num = 1; | |
var add = function(n) { | |
// to implement | |
}; | |
var addNum = add(num); | |
addNum(2); | |
// => 3 | |
addNum(2); | |
// => 5 | |
num = 4; | |
addNum(2); | |
// => 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment