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

Popular posts from this blog

Building a Full-Stack Student Management System with React.js and NestJS

Today I have solved the problem in javascript

Today I have solved problem in javascript