Flatten Array

EasyPayPalGoogleAmazonLyftMeta

Prompt

Implement a flattenArray function that takes a nested array and returns a new single-level array with all elements in order.

Imagine the native Array.prototype.flat() method doesn't exist — you need to build it from scratch.

Requirements:

  • The function should handle any depth of nesting, not just one level.
  • All values should be preserved, including null and undefined.
  • Empty sub-arrays should be skipped (they contribute no elements).