{"ScriptPreparationCode":"function flattenKeys(s) {\r\n return s.replace(/\\[(\\w\u002B)\\]/g, \u0027.$1\u0027).replace(/^\\./, \u0027\u0027).split(\u0027.\u0027)\r\n}\r\n\r\n\r\nfunction pick2(obj, props) {\r\n let result = {};\r\n if (obj == null || props == null || props.length == 0) {\r\n return undefined;\r\n }\r\n if (Array.isArray(obj)) {\r\n result = [];\r\n }\r\n if (typeof props == \u0022string\u0022) {\r\n props = [props];\r\n }\r\n if (obj != null \u0026\u0026 obj != undefined \u0026\u0026 typeof obj == \u0027object\u0027) {\r\n const newObj = structuredClone(obj);\r\n let tempObj = structuredClone(newObj);\r\n for (const i in props) {\r\n const path = flattenKeys(props[i]);\r\n let pathExists = false;\r\n for (const j in path) {\r\n if (tempObj[path[j]] != undefined) {\r\n tempObj = tempObj[path[j]];\r\n if (j == (path.length - 1)) {\r\n pathExists = true;\r\n }\r\n }\r\n }\r\n if (pathExists) {\r\n tempObj = structuredClone(newObj);\r\n let partialRes = {};\r\n if (tempObj[path[0]] != undefined) {\r\n tempObj = tempObj[path[0]];\r\n if (typeof tempObj == \u0027object\u0027) {\r\n partialRes = {};\r\n if (Array.isArray(tempObj)) {\r\n partialRes = [];\r\n }\r\n }\r\n if (path.length == 1) {\r\n partialRes[path[0]] = tempObj;\r\n } else if (path.length \u003E 1) {\r\n partialRes[path[0]] = pick2(tempObj, [path.slice(1).join(\u0027.\u0027)]);\r\n }\r\n }\r\n Object.assign(result, partialRes);\r\n }\r\n }\r\n return result;\r\n }\r\n return obj;\r\n};\r\nvar testA = {\r\n a: {\r\n b: {\r\n c: {\r\n d: [{\r\n sample1: \u0027sample1\u0027\r\n }, {\r\n sample2: \u0027sample2\u0027\r\n }],\r\n e: {\r\n f: \u0027other\u0027\r\n }\r\n }\r\n }\r\n }\r\n};","TestCases":[{"Name":"lodash omit","Code":"const resultA = _.pick(testA, [\u0027a.b.c.d.e\u0027]);\r\nconst resultB = _.pick(testA, [\u0027a.b.c.d[0]\u0027]);","IsDeferred":false},{"Name":"plain Pick","Code":"const resultA = pick2(testA, [\u0027a.b.c.d.e\u0027]);\r\nconst resultB = pick2(testA, [\u0027a.b.c.d[0]\u0027]);","IsDeferred":false}]}