Let's find the sum of the primitive elements of our array:
function func(arr) {
let sum = 0;
for (let elem of arr) {
if (typeof elem == 'object') {
sum += func(elem);
} else {
sum += elem;
}
}
return sum;
}
console.log(func([1, [2, 7, 8], [3, 4, [5, [6, 7]]]]));
A multidimensional object of arbitrary nesting level is given, for example, such as:
{a: 1, b: {c: 2, d: 3, e: 4}, f: {g: 5, j: 6, k: {l: 7, m: {n: 8, o: 9}}}}
Use recursion to find the sum of the elements of this object.
A multidimensional array of arbitrary nesting level, containing strings inside, is given, for example, such as:
['a', ['b', 'c', 'd'], ['e', 'f', ['g', ['j', 'k']]]]
Use recursion to merge the elements of this array into one string:
'abcdefgjk'