
I used the solution and examples already in the article. I chose to make the test cases use Array.reduce() to compute the sum, instead of hard-coding the answer myself. Not sure how good of practice that is.
15 lines
171 B
JavaScript
15 lines
171 B
JavaScript
function sum(a) {
|
|
|
|
let currentSum = a;
|
|
|
|
function f(b) {
|
|
currentSum += b;
|
|
return f;
|
|
}
|
|
|
|
f.toString = function() {
|
|
return currentSum;
|
|
};
|
|
|
|
return f;
|
|
}
|