REVERSE NESTED ARRAY USING RECURSION IN JAVASCRIPT


## Reversing of nested Array

the code is:


// we are doing it in recursive method

function reverseNested(arr){
  // applying base condition : if its type is not array, return arr
  if(!Array.isArray(arr)) return arr
  
  // reverse the array
  const reversedArr = arr.reverse()
  
  // recursive reverse of nested array
  return reversedArr.map(subArr => reverseNested(subArr))
}

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

console.log(reverseNested(arr))

output: [ [ [ 14, 13 ], 12 ], 11, 10, [ 9, [ 8, 7, 6 ], 5, 4 ], 3, 2, 1 ]