Recursion meets data structures

Given a JSON-encoded nested array of integers (arbitrarily deep), flatten it to a single level and print the values space-separated.

Input:  [1,[2,[3,4],5],6]
Output: 1 2 3 4 5 6

Constraints

  • Handle arbitrary nesting depth.
  • Use recursion.
  • Do not use Array.prototype.flat or flatMap.
Ad SpaceGoogle AdSense active for guests & free-tier learners.