{"ScriptPreparationCode":"var sampleObject = [{\r\n \u0022id\u0022: \u00220001\u0022,\r\n \u0022type\u0022: \u0022donut\u0022,\r\n \u0022name\u0022: \u0022Cake\u0022,\r\n \u0022ppu\u0022: 0.55,\r\n \u0022batters\u0022: {\r\n \u0022batter\u0022: [{\r\n \u0022id\u0022: \u00221001\u0022,\r\n \u0022type\u0022: \u0022Regular\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221002\u0022,\r\n \u0022type\u0022: \u0022Chocolate\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221003\u0022,\r\n \u0022type\u0022: \u0022Blueberry\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221004\u0022,\r\n \u0022type\u0022: \u0022Devil\u0027s Food\u0022\r\n }\r\n ]\r\n },\r\n \u0022topping\u0022: [{\r\n \u0022id\u0022: \u00225001\u0022,\r\n \u0022type\u0022: \u0022None\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225002\u0022,\r\n \u0022type\u0022: \u0022Glazed\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225005\u0022,\r\n \u0022type\u0022: \u0022Sugar\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225007\u0022,\r\n \u0022type\u0022: \u0022Powdered Sugar\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225006\u0022,\r\n \u0022type\u0022: \u0022Chocolate with Sprinkles\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225003\u0022,\r\n \u0022type\u0022: \u0022Chocolate\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225004\u0022,\r\n \u0022type\u0022: \u0022Maple\u0022\r\n }\r\n ]\r\n },\r\n {\r\n \u0022id\u0022: \u00220002\u0022,\r\n \u0022type\u0022: \u0022donut\u0022,\r\n \u0022name\u0022: \u0022Raised\u0022,\r\n \u0022ppu\u0022: 0.55,\r\n \u0022batters\u0022: {\r\n \u0022batter\u0022: [{\r\n \u0022id\u0022: \u00221001\u0022,\r\n \u0022type\u0022: \u0022Regular\u0022\r\n }]\r\n },\r\n \u0022topping\u0022: [{\r\n \u0022id\u0022: \u00225001\u0022,\r\n \u0022type\u0022: \u0022None\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225002\u0022,\r\n \u0022type\u0022: \u0022Glazed\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225005\u0022,\r\n \u0022type\u0022: \u0022Sugar\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225003\u0022,\r\n \u0022type\u0022: \u0022Chocolate\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225004\u0022,\r\n \u0022type\u0022: \u0022Maple\u0022\r\n }\r\n ]\r\n },\r\n {\r\n \u0022id\u0022: \u00220003\u0022,\r\n \u0022type\u0022: \u0022donut\u0022,\r\n \u0022name\u0022: \u0022Old Fashioned\u0022,\r\n \u0022ppu\u0022: 0.55,\r\n \u0022batters\u0022: {\r\n \u0022batter\u0022: [{\r\n \u0022id\u0022: \u00221001\u0022,\r\n \u0022type\u0022: \u0022Regular\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221002\u0022,\r\n \u0022type\u0022: \u0022Chocolate\u0022\r\n }\r\n ]\r\n },\r\n \u0022topping\u0022: [{\r\n \u0022id\u0022: \u00225001\u0022,\r\n \u0022type\u0022: \u0022None\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225002\u0022,\r\n \u0022type\u0022: \u0022Glazed\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225003\u0022,\r\n \u0022type\u0022: \u0022Chocolate\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00225004\u0022,\r\n \u0022type\u0022: \u0022Maple\u0022\r\n }\r\n ]\r\n }\r\n];\r\n\r\nvar myCopy = null;","TestCases":[{"Name":"Json clone","Code":"myCopy = JSON.parse(JSON.stringify(sampleObject));","IsDeferred":false},{"Name":"RFDC copy","Code":"var cloneData = rfdc();\r\nmyCopy = cloneData(sampleObject);","IsDeferred":false},{"Name":"Clone Copy","Code":"var clone = (function() {\r\n\u0027use strict\u0027;\r\n\r\nfunction _instanceof(obj, type) {\r\n return type != null \u0026\u0026 obj instanceof type;\r\n}\r\n\r\nvar nativeMap;\r\ntry {\r\n nativeMap = Map;\r\n} catch(_) {\r\n // maybe a reference error because no \u0060Map\u0060. Give it a dummy value that no\r\n // value will ever be an instanceof.\r\n nativeMap = function() {};\r\n}\r\n\r\nvar nativeSet;\r\ntry {\r\n nativeSet = Set;\r\n} catch(_) {\r\n nativeSet = function() {};\r\n}\r\n\r\nvar nativePromise;\r\ntry {\r\n nativePromise = Promise;\r\n} catch(_) {\r\n nativePromise = function() {};\r\n}\r\n\r\n/**\r\n * Clones (copies) an Object using deep copying.\r\n *\r\n * This function supports circular references by default, but if you are certain\r\n * there are no circular references in your object, you can save some CPU time\r\n * by calling clone(obj, false).\r\n *\r\n * Caution: if \u0060circular\u0060 is false and \u0060parent\u0060 contains circular references,\r\n * your program may enter an infinite loop and crash.\r\n *\r\n * @param \u0060parent\u0060 - the object to be cloned\r\n * @param \u0060circular\u0060 - set to true if the object to be cloned may contain\r\n * circular references. (optional - true by default)\r\n * @param \u0060depth\u0060 - set to a number if the object is only to be cloned to\r\n * a particular depth. (optional - defaults to Infinity)\r\n * @param \u0060prototype\u0060 - sets the prototype to be used when cloning an object.\r\n * (optional - defaults to parent prototype).\r\n * @param \u0060includeNonEnumerable\u0060 - set to true if the non-enumerable properties\r\n * should be cloned as well. Non-enumerable properties on the prototype\r\n * chain will be ignored. (optional - false by default)\r\n*/\r\nfunction clone(parent, circular, depth, prototype, includeNonEnumerable) {\r\n if (typeof circular === \u0027object\u0027) {\r\n depth = circular.depth;\r\n prototype = circular.prototype;\r\n includeNonEnumerable = circular.includeNonEnumerable;\r\n circular = circular.circular;\r\n }\r\n // maintain two arrays for circular references, where corresponding parents\r\n // and children have the same index\r\n var allParents = [];\r\n var allChildren = [];\r\n\r\n var useBuffer = typeof Buffer != \u0027undefined\u0027;\r\n\r\n if (typeof circular == \u0027undefined\u0027)\r\n circular = true;\r\n\r\n if (typeof depth == \u0027undefined\u0027)\r\n depth = Infinity;\r\n\r\n // recurse this function so we don\u0027t reset allParents and allChildren\r\n function _clone(parent, depth) {\r\n // cloning null always returns null\r\n if (parent === null)\r\n return null;\r\n\r\n if (depth === 0)\r\n return parent;\r\n\r\n var child;\r\n var proto;\r\n if (typeof parent != \u0027object\u0027) {\r\n return parent;\r\n }\r\n\r\n if (_instanceof(parent, nativeMap)) {\r\n child = new nativeMap();\r\n } else if (_instanceof(parent, nativeSet)) {\r\n child = new nativeSet();\r\n } else if (_instanceof(parent, nativePromise)) {\r\n child = new nativePromise(function (resolve, reject) {\r\n parent.then(function(value) {\r\n resolve(_clone(value, depth - 1));\r\n }, function(err) {\r\n reject(_clone(err, depth - 1));\r\n });\r\n });\r\n } else if (clone.__isArray(parent)) {\r\n child = [];\r\n } else if (clone.__isRegExp(parent)) {\r\n child = new RegExp(parent.source, __getRegExpFlags(parent));\r\n if (parent.lastIndex) child.lastIndex = parent.lastIndex;\r\n } else if (clone.__isDate(parent)) {\r\n child = new Date(parent.getTime());\r\n } else if (useBuffer \u0026\u0026 Buffer.isBuffer(parent)) {\r\n if (Buffer.allocUnsafe) {\r\n // Node.js \u003E= 4.5.0\r\n child = Buffer.allocUnsafe(parent.length);\r\n } else {\r\n // Older Node.js versions\r\n child = new Buffer(parent.length);\r\n }\r\n parent.copy(child);\r\n return child;\r\n } else if (_instanceof(parent, Error)) {\r\n child = Object.create(parent);\r\n } else {\r\n if (typeof prototype == \u0027undefined\u0027) {\r\n proto = Object.getPrototypeOf(parent);\r\n child = Object.create(proto);\r\n }\r\n else {\r\n child = Object.create(prototype);\r\n proto = prototype;\r\n }\r\n }\r\n\r\n if (circular) {\r\n var index = allParents.indexOf(parent);\r\n\r\n if (index != -1) {\r\n return allChildren[index];\r\n }\r\n allParents.push(parent);\r\n allChildren.push(child);\r\n }\r\n\r\n if (_instanceof(parent, nativeMap)) {\r\n parent.forEach(function(value, key) {\r\n var keyChild = _clone(key, depth - 1);\r\n var valueChild = _clone(value, depth - 1);\r\n child.set(keyChild, valueChild);\r\n });\r\n }\r\n if (_instanceof(parent, nativeSet)) {\r\n parent.forEach(function(value) {\r\n var entryChild = _clone(value, depth - 1);\r\n child.add(entryChild);\r\n });\r\n }\r\n\r\n for (var i in parent) {\r\n var attrs;\r\n if (proto) {\r\n attrs = Object.getOwnPropertyDescriptor(proto, i);\r\n }\r\n\r\n if (attrs \u0026\u0026 attrs.set == null) {\r\n continue;\r\n }\r\n child[i] = _clone(parent[i], depth - 1);\r\n }\r\n\r\n if (Object.getOwnPropertySymbols) {\r\n var symbols = Object.getOwnPropertySymbols(parent);\r\n for (var i = 0; i \u003C symbols.length; i\u002B\u002B) {\r\n // Don\u0027t need to worry about cloning a symbol because it is a primitive,\r\n // like a number or string.\r\n var symbol = symbols[i];\r\n var descriptor = Object.getOwnPropertyDescriptor(parent, symbol);\r\n if (descriptor \u0026\u0026 !descriptor.enumerable \u0026\u0026 !includeNonEnumerable) {\r\n continue;\r\n }\r\n child[symbol] = _clone(parent[symbol], depth - 1);\r\n if (!descriptor.enumerable) {\r\n Object.defineProperty(child, symbol, {\r\n enumerable: false\r\n });\r\n }\r\n }\r\n }\r\n\r\n if (includeNonEnumerable) {\r\n var allPropertyNames = Object.getOwnPropertyNames(parent);\r\n for (var i = 0; i \u003C allPropertyNames.length; i\u002B\u002B) {\r\n var propertyName = allPropertyNames[i];\r\n var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName);\r\n if (descriptor \u0026\u0026 descriptor.enumerable) {\r\n continue;\r\n }\r\n child[propertyName] = _clone(parent[propertyName], depth - 1);\r\n Object.defineProperty(child, propertyName, {\r\n enumerable: false\r\n });\r\n }\r\n }\r\n\r\n return child;\r\n }\r\n\r\n return _clone(parent, depth);\r\n}\r\n\r\n/**\r\n * Simple flat clone using prototype, accepts only objects, usefull for property\r\n * override on FLAT configuration object (no nested props).\r\n *\r\n * USE WITH CAUTION! This may not behave as you wish if you do not know how this\r\n * works.\r\n */\r\nclone.clonePrototype = function clonePrototype(parent) {\r\n if (parent === null)\r\n return null;\r\n\r\n var c = function () {};\r\n c.prototype = parent;\r\n return new c();\r\n};\r\n\r\n// private utility functions\r\n\r\nfunction __objToStr(o) {\r\n return Object.prototype.toString.call(o);\r\n}\r\nclone.__objToStr = __objToStr;\r\n\r\nfunction __isDate(o) {\r\n return typeof o === \u0027object\u0027 \u0026\u0026 __objToStr(o) === \u0027[object Date]\u0027;\r\n}\r\nclone.__isDate = __isDate;\r\n\r\nfunction __isArray(o) {\r\n return typeof o === \u0027object\u0027 \u0026\u0026 __objToStr(o) === \u0027[object Array]\u0027;\r\n}\r\nclone.__isArray = __isArray;\r\n\r\nfunction __isRegExp(o) {\r\n return typeof o === \u0027object\u0027 \u0026\u0026 __objToStr(o) === \u0027[object RegExp]\u0027;\r\n}\r\nclone.__isRegExp = __isRegExp;\r\n\r\nfunction __getRegExpFlags(re) {\r\n var flags = \u0027\u0027;\r\n if (re.global) flags \u002B= \u0027g\u0027;\r\n if (re.ignoreCase) flags \u002B= \u0027i\u0027;\r\n if (re.multiline) flags \u002B= \u0027m\u0027;\r\n return flags;\r\n}\r\nclone.__getRegExpFlags = __getRegExpFlags;\r\n\r\nreturn clone;\r\n})();\r\nmyCopy = clone(sampleObject);","IsDeferred":false}]}