forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFlat.ts
More file actions
18 lines (17 loc) · 676 Bytes
/
ArrayFlat.ts
File metadata and controls
18 lines (17 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function __TS__ArrayFlat(this: void, array: any[], depth = 1): any[] {
let result: any[] = [];
for (const value of array) {
if (
depth > 0 &&
type(value) === "table" &&
// Workaround to determine if value is an array or not (fails in case of objects without keys)
// See discussion in: https://github.com/TypeScriptToLua/TypeScriptToLua/pull/737
(1 in value || (next as NextEmptyCheck)(value, undefined) === undefined)
) {
result = result.concat(__TS__ArrayFlat(value, depth - 1));
} else {
result[result.length] = value;
}
}
return result;
}