Sum of array elements with recursion in JavaScript

Let's find the sum of the primitive elements of our array:

javascriptfunction 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]]]]));
Задание 1

A multidimensional object of arbitrary nesting level is given, for example, such as:

javascript{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.

Задание 2

A multidimensional array of arbitrary nesting level, containing strings inside, is given, for example, such as:

javascript['a', ['b', 'c', 'd'], ['e', 'f', ['g', ['j', 'k']]]]

Use recursion to merge the elements of this array into one string:

javascript'abcdefgjk'