en.javascript.info/1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/_js.view/solution.js
Logan Schelly f20fb43f70 Add test case/sandbox for 1-js/06-advanced-functions/06-function-object/5-sum-many-brackets
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.
2020-06-10 15:29:06 -06:00

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;
}