function func(arr) {
for (let elem of arr) {
if (typeof elem == 'object') {
func(elem);
} else {
console.log(elem);
}
}
}
func(['a', ['b', 'c', 'd'], ['e', 'f', ['g', ['j', 'k']]]]);
const join = val => Array.isArray(val) ? val.map(join).join('') : val;
const join = arr => ''.concat(...arr.flat(Infinity));
const join = arr => arr.reduce((acc, n) => acc + (n instanceof Array ? join(n) : n), '');
function join(arr) {
const result = [];
for (const stack = [ arr ]; stack.length;) {
const n = stack.pop();
if (n?.constructor === Array) {
stack.push(...[...n].reverse());
} else {
result.push(n);
}
}
return result.join``;
}