{"ScriptPreparationCode":"class UniqueArray {\r\n constructor() {\r\n this._map = new Map();\r\n this._array = [];\r\n }\r\n updatedIndicesMap(from) {\r\n for (let i = from; i \u003C this._array.length; i\u002B\u002B) {\r\n let item = this._array[i];\r\n this._map.set(item, i);\r\n }\r\n }\r\n has(item) {\r\n return this._map.has(item);\r\n }\r\n add(item) {\r\n let result;\r\n if (this._map.has(item)) {\r\n result = false;\r\n }\r\n else {\r\n this._array.push(item);\r\n this._map.set(item, this._array.length - 1);\r\n result = true;\r\n }\r\n return result;\r\n }\r\n insert(item, index) {\r\n let updateFrom = this._array.length \u002B 1;\r\n let removeResult = this.removeInternal(item);\r\n if (removeResult.result) {\r\n updateFrom = removeResult.index;\r\n }\r\n this._array.splice(index, 0, item);\r\n updateFrom = Math.min(index, updateFrom);\r\n this.updatedIndicesMap(updateFrom);\r\n }\r\n remove(item) {\r\n let removeResult = this.removeInternal(item);\r\n if (removeResult.result) {\r\n this.updatedIndicesMap(removeResult.index);\r\n }\r\n return removeResult.result;\r\n }\r\n removeInternal(item) {\r\n let index = this._map.get(item);\r\n if (index !== undefined) {\r\n this._array.splice(index, 1);\r\n this._map.delete(item);\r\n UniqueArray._removeResult.index = index;\r\n UniqueArray._removeResult.result = true;\r\n }\r\n else {\r\n UniqueArray._removeResult.index = 0;\r\n UniqueArray._removeResult.result = false;\r\n }\r\n return UniqueArray._removeResult;\r\n }\r\n clear() {\r\n this._map.clear();\r\n this._array.length = 0;\r\n }\r\n indexOf(item) {\r\n let index = this._map.get(item);\r\n return index === undefined ? -1 : index;\r\n }\r\n forEach(cb) {\r\n this._array.forEach(cb);\r\n }\r\n some(cb) {\r\n return this._array.some(cb);\r\n }\r\n clone() {\r\n let result = new UniqueArray();\r\n result._array = this._array.slice(0);\r\n result._map = new Map(this._map);\r\n return result;\r\n }\r\n}\r\nUniqueArray._removeResult = { index: 0, result: false };\r\n\r\nvar arr = []\r\nvar uarr = new UniqueArray()\r\n","TestCases":[{"Name":"1","Code":"for (var i = 0; i \u003C 10000; i\u002B\u002B) {\r\n if (arr.indexOf(i) === -1) { arr.push(i) }\r\n}","IsDeferred":false},{"Name":"2","Code":"for (var i = 0; i \u003C 10000; i\u002B\u002B) {\r\n uarr.add(i)\r\n}","IsDeferred":false}]}