{"ScriptPreparationCode":"var dataSource = [...Array(100)].map(() =\u003E ({\r\n _id: crypto.randomUUID(),\r\n children: [...Array(10)].map(() =\u003E ({\r\n _id: crypto.randomUUID(),\r\n children: [...Array(10)].map(() =\u003E ({\r\n _id: crypto.randomUUID(),\r\n children: [],\r\n }))\r\n }))\r\n}));\r\n\r\nvar collectExpandedIdsFromDataSource1 = (\r\n dataSource,\r\n searchPhrase,\r\n) =\u003E {\r\n const ids = [];\r\n\r\n if (!searchPhrase) return ids;\r\n\r\n const getRowIds = (row) =\u003E {\r\n if (row._id \u0026\u0026 row.children?.length) ids.push(row._id);\r\n\r\n for (const child of row.children ?? []) getRowIds(child);\r\n };\r\n\r\n for (const row of dataSource) getRowIds(row);\r\n\r\n return ids;\r\n};\r\n\r\nvar collectExpandedIdsFromDataSource2 = (dataSource, searchPhrase) =\u003E {\r\n if (!searchPhrase) return [];\r\n\r\n return dataSource.flatMap(row =\u003E {\r\n return row.children?.length ?\r\n (row._id ? [row._id, ...collectExpandedIdsFromDataSource2(row.children, searchPhrase)] :\r\n collectExpandedIdsFromDataSource2(row.children, searchPhrase)) : []\r\n })\r\n};\r\n\r\nfunction* collectExpandedIdsFromDataSource3(dataSource, searchPhrase) {\r\n if (!searchPhrase) return;\r\n\r\n for (const row of dataSource) {\r\n if (row.children?.length) {\r\n if (row._id) yield row._id;\r\n\r\n yield* collectExpandedIdsFromDataSource3(row.children, searchPhrase);\r\n }\r\n\r\n };\r\n};","TestCases":[{"Name":"collectExpandedIdsFromDataSource loop","Code":"collectExpandedIdsFromDataSource1(dataSource, \u0027aaa\u0027)","IsDeferred":false},{"Name":"collectExpandedIdsFromDataSource flatMap","Code":"collectExpandedIdsFromDataSource2(dataSource, \u0027aaa\u0027)","IsDeferred":false},{"Name":"collectExpandedIdsFromDataSource generator","Code":"[...collectExpandedIdsFromDataSource3(dataSource, \u0027aaa\u0027)]","IsDeferred":false}]}