input: Write a python function to flatten a nested array.
  assert flatten_array([[1, 2, [3]], 4]) == [1, 2, 3, 4]
  assert flatten_array([1, [2, [3, 4], 5], 6]) == [1, 2, 3, 4, 5, 6]
  assert flatten_array([[1, [2, [3, [4]]]], 5]) == [1, 2, 3, 4, 5]
output: def flatten_array(nested_array):
      def flatten(arr):
          for item in arr:
              if isinstance(item, list):
                  yield from flatten(item)
              else:
                  yield item
      return list(flatten(nested_array))