Your Submissions
You haven't submitted any code for this challenge yet. Solve the problem by passing all the test cases, and your submissions will appear here.
xxxxxxxxxx
12
function flat(array, depthLevel = 1) {
let result = [];
array.forEach((item) => {
// if the item of the main array is an array itself, call the method recursively
// to check the elements inside
if (Array.isArray(item) && depthLevel > 0) {
result.push(flat(item, depthLevel - 1));
} else result.push(item); // else, push the object into the result
});
return result;
}
OUTPUT
Results will appear here.