mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
21 lines
520 B
TypeScript
21 lines
520 B
TypeScript
/**
|
|
* @param {array} arr array that needs flattening
|
|
* @description flattens an array of any depth
|
|
* @return {array} a flattened array
|
|
*/
|
|
|
|
export default function flat(arr: $TSFixMe): void {
|
|
const flattened: $TSFixMe = [];
|
|
const flatten: Function = (arr: $TSFixMe): void => {
|
|
for (const val of arr) {
|
|
if (Array.isArray(val)) {
|
|
flatten(val);
|
|
} else {
|
|
flattened.push(val);
|
|
}
|
|
}
|
|
};
|
|
flatten(arr);
|
|
return flattened;
|
|
}
|