Flatten Nested Lists

Recursion Arrays Flatten

Flatten Nested Lists

Write a recursive function that takes a nested list (or array) of integers and/or further nested lists, and returns a flattened list containing all the integers in the same order.

For example:

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

Requirements

  • Use recursion to handle arbitrary levels of nesting.
  • The function should process an empty list without error.
  • Aim for clarity and efficiency.

This exercise is a festive nod to the idea of unwrapping layers—a fitting concept as we peel back complexities, much like preparing for the holidays when we simplify our lives to celebrate what matters most.