javascript

Convert a flatten nested array into a single-dimensional array using recursion.

const arr = [1, [2, 3], [4, [5, 6]], 7, [8, [9, [10]]]];

function getArray(input){
  let result = [];
  for(let item of input){
   	if(Array.isArray(item)){
      result = result.concat(getArray(item));
    }else{
      result.push(item)
  }
}
  return result;
}


console.log(getArray(arr));

// output : [1, 2, 3, 4,  5, 6, 7, 8, 9, 10]