-
Notifications
You must be signed in to change notification settings - Fork 0
/
stable.ts
21 lines (17 loc) · 827 Bytes
/
stable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export default async function algorithm(inputData: any): Promise<any> {
// const result: Record<string, any> = {};
// const stack: Array<{obj: any, parentKey: string}> = [{ obj: inputData, parentKey: '' }];
// while (stack.length > 0) {
// const { obj, parentKey } = stack.pop()!; // Use stack to avoid recursion
// for (const key of Object.keys(obj)) {
// const newKey = parentKey ? `${parentKey}.${key}` : key;
// // Directly push object-type entries into the stack, delaying recursive action
// if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
// stack.push({ obj: obj[key], parentKey: newKey });
// } else {
// result[newKey] = obj[key]; // Directly assign values to the result
// }
// }
// }
// return result;
}