Today I have solved the problem in javascript
Write a function, add_subtract, which alternately adds and subtracts curried arguments. Here are some sample operations:
function add_subtract(value) {
function innerFunction(nextValue) {
return nextValue === undefined ? value : add_subtract(value + nextValue);
} return innerFunction;
}console.log(add_subtract(7));
console.log(add_subtract(1)(2)(3)());
console.log(add_subtract(-5)(10)(3)(9)());
Output:
[Function: innerFunction] 6 17
Comments
Post a Comment