Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
17 lines (14 sloc) 334 Bytes
import { reduce } from './reduce';
import { concat } from './concat';
export function flat<T>(array: T | T[], depth = 0) {
if (depth < 1 || !Array.isArray(array)) {
return array;
}
return reduce<T, T[]>(
array,
(result, current) => {
return concat(result, flat<T>(current, depth - 1));
},
[],
);
}
You can’t perform that action at this time.