The problem is to create a function that flattens the given array up to the depth passed as an argument. Depth is basically how deep the array can be in the array. So the task is to create a function that looks like below:
function flatarray(arr, depth)
If the passed array is:
[1, 2, 3, [4, 5, [6, 7], 8], [10, 11, [12, [13]]], 9];
for depth = 1, it should return [1, 2, 3, 4, 5, 6, 7, 8, 10, 11 , 12, 13, 9]. Here, as the depth is 1, so it will be fully flattened.
for depth = 2, it should return [1, 2, 3, [4, 5, 6, 7, 8], [10, 11, 12, 13], 9]. Here, as the depth is 2, then array inside array should be flattened.
for depth = 3, it should return [1, 2, 3, [4, 5, [6, 7], 8], [10, 11, [12, 13], 9]. And so on.