Sequence NODE_152
Medium

Flatten a Nested Array (One Level)

JavaScript
Technical Specification

Given an array that may contain nested arrays one level deep, return a new flattened array.

Input/Output Samples
Input:[1, [2, 3], 4, [5]]
Output:[1, 2, 3, 4, 5]
Optimal Logic Path
function flattenOneLevel(arr) {
  return arr.flat(1);
}
Architectural Deep-Dive
flat(1) flattens the array by one nesting level, which is enough for this problem.