I'm working some JS algorithms with TS. So I made this functions:
function steamrollArray(arr: any[]): any[] {
return arr.reduce(
(accum: any, val: any) =>
Array.isArray(val) ? accum.concat(steamrollArray(val)) : accum.concat(val)
, []);
}
but the arguments need the flexibility to accept multiple dimension arrays, as follow:
steamrollArray([[["a"]], [["b"]]]);
steamrollArray([1, [2], [3, [[4]]]]);
steamrollArray([1, [], [3, [[4]]]]);
steamrollArray([1, {}, [3, [[4]]]]);
Which is the proper way to define the arguments for the function?
Certainly I could use Types, like here: typescript multidimensional array with different types but won't work with all cases.