Coding Challenge - #4: Flatten Nested Arrays

Write a function flattenOnce(arr) that flattens an array by exactly one level, not fully recursive. For example, flattenOnce([1, [2, 3], [4, [5, 6]]]) should return [1, 2, 3, 4, [5, 6]].

function flattenOnce(arr) {
  // your code here
}

Rules:

  • No use of Array.prototype.flat
  • Only flatten one level deep, nested arrays inside nested arrays stay intact
  • Must return a new array, not mutate the input

Post your solution as a reply. Answer goes up in about a day.