{"ScriptPreparationCode":"function jsMerge(target, ...sources) {\r\n if (!sources.length) {\r\n return target;\r\n }\r\n\r\n sources.forEach((src) =\u003E {\r\n Object.keys(src).forEach((key) =\u003E {\r\n \tconst value = src[key];\r\n if (Object.prototype.hasOwnProperty.call(target, key)) {\r\n // target already has key. Merge if required.\r\n if (typeof target[key] === \u0027object\u0027 \u0026\u0026 typeof value === \u0027object\u0027) {\r\n // Try to merge objects or arrays\r\n \tif (Array.isArray(value)) {\r\n \tif (Array.isArray(target[key]) \u0026\u0026 target[key].length \u003E value.length) {\r\n\t \t// Both arrays and old array is longer. Merge\r\n \t \ttarget[key] = Array.prototype.concat(value, Array.prototype.slice.call(target[key], value.length));\r\n\t } else {\r\n \t// Either not both arrays or old array is same length/shorter. Overwrite.\r\n\t\t\t\t\t\t\ttarget[key] = value;\r\n }\r\n } else {\r\n // Both non-array objects. Recursively merge\r\n target[key] = jsMerge(target[key], value);\r\n }\r\n } else {\r\n // At least one side is not object/array. Overwrite.\r\n target[key] = value;\r\n }\r\n } else {\r\n // Key does not exist on object. Assign.\r\n target[key] = value;\r\n }\r\n });\r\n });\r\n\r\n return target;\r\n}","TestCases":[{"Name":"recursive indexed setter merge function","Code":"var a1 = { a: \u0027oh\u0027, b: \u0027my\u0027, c: \u0027goodness\u0027, d: { a: \u0027nested\u0027, b: \u0027object\u0027, c: [ \u0027arrayA\u0027, \u0027arrayB\u0027, \u0027arrayC\u0027 ], e: \u0027a.d.e\u0027 } };\r\nvar b1 = { c: \u0027GOODNESS\u0027, d: { b: \u0027object!\u0027, c: [ \u0027array1\u0027, \u0027array2\u0027 ], d: \u0027b.d.d\u0027 } };\r\njsMerge(a1, b1);","IsDeferred":false},{"Name":"lodash merge","Code":"var a2 = { a: \u0027oh\u0027, b: \u0027my\u0027, c: \u0027goodness\u0027, d: { a: \u0027nested\u0027, b: \u0027object\u0027, c: [ \u0027arrayA\u0027, \u0027arrayB\u0027, \u0027arrayC\u0027 ], e: \u0027a.d.e\u0027 } };\r\nvar b2 = { c: \u0027GOODNESS\u0027, d: { b: \u0027object!\u0027, c: [ \u0027array1\u0027, \u0027array2\u0027 ], d: \u0027b.d.d\u0027 } };\r\n_.merge(a2, b2);","IsDeferred":false}]}