Stack Exchange
Stack Overflow
Questions
Tags
Users
About
Stack Overflow
Public
Questions
Tags
Users
About
How to write a function to evaluate this expression?
Asked
Feb 21 '21 at 18:08
Active
Feb 21 '21 at 18:08
Viewed
21 times
0
Sum(6)(2,3)(6,7,8)() = 32
Sum() = 0
Sum(6,1,3)() = 10
Needs to evaluate this with single function.
javascript
asked Feb 21 '21 at 18:08
anandharshan
5,817
4
34
33
I would just add up all the numbers. that's what sum means.
–
Rick
Feb 21 '21 at 18:11
See [this answer](https://stackoverflow.com/a/66305648/5459839) in the duplicate reference.
–
trincot
Feb 21 '21 at 18:28
function add(...args) { if (args.length === 0) return 0; let sum = args.reduce((a, b) => a+b, 0); return (...args) => args.length ? add(sum, ...args) : sum; }
–
anandharshan
Feb 21 '21 at 18:32
0 Answers
0