{"ScriptPreparationCode":"var list = [];\r\nfor (var i = 0; i \u003C 1000 * 1000; i\u002B\u002B) {\r\n list.push({ id: i, name: \u0060${i}\u0060 });\r\n}\r\n\r\nvar updates = [\r\n { id: (1000 * 1000) - 1, name: \u0027Changed\u0027 },\r\n { id: (1000 * 1000) \u002B 1, name: \u0027Added\u0027 },\r\n];\r\n\r\nfunction updateOrInsertBySplice(\r\n array,\r\n update,\r\n key,\r\n) {\r\n const index = array.findIndex(item =\u003E item[key] === update[key])\r\n const startIndex = index === -1 ? 0 : index\r\n const toRemove = Number(index !== -1)\r\n return array.splice(startIndex, toRemove, update)\r\n}\r\n\r\nfunction updateOrInsertBySlice(\r\n array,\r\n update,\r\n key,\r\n) {\r\n const index = array.findIndex(item =\u003E item[key] === update[key])\r\n const startIndex = index === -1 ? 0 : index\r\n const toRemove = \u002BBoolean(index !== -1)\r\n return [...array.slice(0, startIndex), update, ...array.slice(startIndex \u002B toRemove)]\r\n}","TestCases":[{"Name":"splice","Code":"updates.forEach(update =\u003E updateOrInsertBySplice(list, update, \u0027id\u0027))","IsDeferred":false},{"Name":"slice","Code":"updates.forEach(update =\u003E updateOrInsertBySlice(list, update, \u0027id\u0027))","IsDeferred":false}]}