{"ScriptPreparationCode":"var user = {\r\n id: 1,\r\n email: \u0027bob@somewhere.com\u0027,\r\n personalInfo: {\r\n name: \u0027Robert\u0027,\r\n address: {\r\n road: \u0027Quartier Djinageryber\u0027,\r\n city: \u0027Timbuktu\u0027,\r\n country: \u0027Mali\u0027\r\n }\r\n }\r\n}\r\n\r\nfunction setByPathWhile (keys, value, source) {\r\n let [currKey, nextKey] = keys\r\n let node = source\r\n let i = 1\r\n\r\n while (nextKey !== undefined) {\r\n\r\n if (!node[currKey]) {\r\n node[currKey] = isNaN(nextKey) ? {} : []\r\n }\r\n\r\n node = node[currKey]\r\n currKey = keys[i] \r\n nextKey = keys[\u002B\u002Bi]\r\n }\r\n\r\n node[currKey] = value\r\n\r\n return source\r\n}\r\n\r\nfunction setByPath ([key, nextKey, ...restOfKeys], value, source) {\r\n\r\n source[key] = (nextKey !== undefined)\r\n ? setByPath(\r\n [nextKey, ...restOfKeys],\r\n value,\r\n ({}.hasOwnProperty.call(source, key))\r\n \t? source[key]\r\n \t: isNaN(nextKey) ? {} : []\r\n )\r\n \t: value\r\n\r\n return source\r\n}","TestCases":[{"Name":"set by path recursive","Code":"setByPath([\u0027personalInfo\u0027, \u0027hobbies\u0027, 0], \u0027jogging\u0027, user)","IsDeferred":false},{"Name":"set by path while loop","Code":"setByPathWhile([\u0027personalInfo\u0027, \u0027hobbies\u0027, 0], \u0027jogging\u0027, user)","IsDeferred":false}]}