Recursive Sum of All Numbers in Object
Recursive Sum of All Numbers in Object
Calculate sum of all numeric values in a nested object.
Requirements:
- Find all numbers in nested structure
- Sum all numeric values
- Handle arrays and objects
- Ignore non-numeric values
Example:
Input: { a: 1, b: { c: 2, d: { e: 3 } }, f: [4, 5] }
Output: 15
Input: { x: 10, y: { z: 20 }, arr: [1, 2, 3] }
Output: 36
Examples:
Input 1:
{"obj":{"a":1,"b":{"c":2,"d":{"e":3}},"f":[4,5]}}Output 1:
15Input 2:
{"obj":{"x":10,"y":{"z":20},"arr":[1,2,3]}}Output 2:
36Loading editor...
Run your code to see results
Click the Run button above