-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e331c0
commit fceb18d
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// https://www.codewars.com/kata/a-chain-adding-function/ | ||
|
||
// We want to create a function that will add numbers together when called in succession. | ||
|
||
// add(1)(2); | ||
// // returns 3 | ||
// We also want to be able to continue to add numbers to our chain. | ||
|
||
// add(1)(2)(3); // 6 | ||
// add(1)(2)(3)(4); // 10 | ||
// add(1)(2)(3)(4)(5); // 15 | ||
// and so on. | ||
|
||
// A single call should return the number passed in. | ||
|
||
// add(1); // 1 | ||
// We should be able to store the returned values and reuse them. | ||
|
||
// var addTwo = add(2); | ||
// addTwo; // 2 | ||
// addTwo + 5; // 7 | ||
// addTwo(3); // 5 | ||
// addTwo(3)(5); // 10 | ||
// We can assume any number being passed in will be valid whole number. | ||
|
||
function add(n){ | ||
const sum = function (y) { | ||
return add(n + y); | ||
}; | ||
|
||
sum.valueOf = function () { | ||
return n; | ||
}; | ||
|
||
return sum; | ||
} |