Medium
How can you implement a function to flatten a nested array of arbitrary depth?
1const nestedArray = [1, [2, [3, [4]]]];2const flattenArray = (arr) => {3 // Your implementation here4};56console.log(flattenArray(nestedArray)); // Expected: [1, 2, 3, 4]