{"ScriptPreparationCode":null,"TestCases":[{"Name":"selectionToggleUsingIndexOfSliceConcat","Code":"const selectedAddressGroupIds = Array.from(\r\n new Set(new Array(500).fill(null).map(() =\u003E Math.floor(Math.random() * 5000)))\r\n);\r\nconst toggleAddressGroupIds = Array.from(\r\n new Set(new Array(50).fill(null).map(() =\u003E Math.floor(Math.random() * 5000)))\r\n);\r\n\r\nconst selectionToggleUsingIndexOfSliceConcat = (addressGroupId) =\u003E {\r\n const selectedIndex = selectedAddressGroupIds.indexOf(addressGroupId);\r\n let newSelected = [];\r\n\r\n // Following will be faster than \u0060Array.filter()\u0060 because \u0060Array.indexOf()\u0060 \u0026 \u0060Array.concat()\u0060 combined together is faster\r\n if (selectedIndex === -1) {\r\n newSelected = newSelected.concat(selectedAddressGroupIds, addressGroupId);\r\n } else if (selectedIndex === 0) {\r\n newSelected = newSelected.concat(selectedAddressGroupIds.slice(1));\r\n } else if (selectedIndex === selectedAddressGroupIds.length - 1) {\r\n newSelected = newSelected.concat(selectedAddressGroupIds.slice(0, -1));\r\n } else if (selectedIndex \u003E 0) {\r\n newSelected = newSelected.concat(\r\n selectedAddressGroupIds.slice(0, selectedIndex),\r\n selectedAddressGroupIds.slice(selectedIndex \u002B 1)\r\n );\r\n }\r\n\r\n return newSelected;\r\n};\r\n\r\ntoggleAddressGroupIds.map(selectionToggleUsingIndexOfSliceConcat);\r\n","IsDeferred":false},{"Name":"selectionToggleUsingFilter","Code":"const selectedAddressGroupIds = Array.from(\r\n new Set(new Array(500).fill(null).map(() =\u003E Math.floor(Math.random() * 5000)))\r\n);\r\n\r\nconst toggleAddressGroupIds = Array.from(\r\n new Set(new Array(50).fill(null).map(() =\u003E Math.floor(Math.random() * 5000)))\r\n);\r\n\r\nconst selectionToggleUsingFilter = (addressGroupId) =\u003E {\r\n const selectedIndex = selectedAddressGroupIds.indexOf(addressGroupId);\r\n let newSelected = [];\r\n\r\n // Following will be faster than \u0060Array.filter()\u0060 because \u0060Array.indexOf()\u0060 \u0026 \u0060Array.concat()\u0060 combined together is faster\r\n if (selectedIndex === -1) {\r\n newSelected = newSelected.concat(selectedAddressGroupIds, addressGroupId);\r\n } else {\r\n newSelected = selectedAddressGroupIds.filter((id) =\u003E id !== addressGroupId);\r\n }\r\n\r\n return newSelected;\r\n};\r\n\r\ntoggleAddressGroupIds.map(selectionToggleUsingFilter);\r\n","IsDeferred":false}]}