Implement a function flatten
that returns a newly-created array with all sub-array elements concatenated recursively into a single level.
// Single-level arrays are unaffected.flatten([1, 2, 3]); // [1, 2, 3]// Inner arrays are flattened into a single level.flatten([1, [2, 3]]); // [1, 2, 3]flatten([[1, 2],[3, 4],]); // [1, 2, 3, 4]// Flattens recursively.flatten([1, [2, [3, [4, [5]]]]]); // [1, 2, 3, 4, 5]
console.log()
statements will appear here.To test your function without submitting, call the function below the declaration.