Recursive nested addition

Run Settings
LanguageJavaScript
Language Version
Run Command
function addElementsOfNestedArr(arr){ let sum=0 for(let x of arr){ if(typeof x==="number"){ console.log("adding ",x) sum+=x; } else{ console.log(x,sum) let val=addElementsOfNestedArr(x); sum+=val; console.log("adding return",val) } } return sum } const nestedArray=[1, 2, 3, 4, 5, [6, 7, 8], 9, [[10, 11], 13, [14]]]; console.log(addElementsOfNestedArr(nestedArray))
Editor Settings
Theme
Key bindings
Full width
Lines