flatten
Flattens an array up to the specified depth.
- Use recursion, decrementing
depthby1for each level of depth. - Use
Array.prototype.reduce()andArray.prototype.concat()to merge elements or arrays. - Base case, for
depthequal to1stops recursion. - Omit the second argument,
depth, to flatten only to a depth of1(single flatten).