{"ScriptPreparationCode":"window.actions = [\u0027i\u0027, \u0027d\u0027, \u0027r\u0027, \u0027m\u0027, \u0027f\u0027, \u0027x\u0027, \u0027c\u0027, \u0027p\u0027];\r\n\r\nwindow.generateRandomCommand = () =\u003E {\r\n const action = window.actions[Math.floor(Math.random() * window.actions.length)];\r\n const start = Math.floor(Math.random() * 10);\r\n const end = start \u002B Math.floor(Math.random() * 10);\r\n const text = Math.random().toString(36).substring(7);\r\n return \u0060${action} ${start} ${end} ${text}\u0060;\r\n};\r\n","TestCases":[{"Name":"switch","Code":"\r\n\r\n const version1 = cmd =\u003E {\r\n const action = cmd[0];\r\n\r\n if (!window.actions.includes(action)) {\r\n throw new Error(\u0027Invalid action\u0027);\r\n }\r\n\r\n const result = { action };\r\n\r\n switch (action) {\r\n case \u0027i\u0027:\r\n result.start = parseInt(cmd[2]);\r\n result.text = cmd.slice(4);\r\n break;\r\n\r\n case \u0027d\u0027:\r\n result.start = parseInt(cmd[2]);\r\n result.end = parseInt(cmd[4]);\r\n break;\r\n\r\n case \u0027r\u0027:\r\n result.start = parseInt(cmd[2]);\r\n result.end = parseInt(cmd[4]);\r\n result.text = cmd.slice(6);\r\n break;\r\n\r\n case \u0027m\u0027:\r\n result.start = parseInt(cmd[2]);\r\n result.end = parseInt(cmd[4]);\r\n result.newPos = parseInt(cmd[6]);\r\n break;\r\n\r\n case \u0027f\u0027:\r\n result.search = cmd.slice(2);\r\n break;\r\n\r\n case \u0027x\u0027:\r\n case \u0027c\u0027:\r\n result.start = parseInt(cmd[2]);\r\n result.end = parseInt(cmd[4]);\r\n break;\r\n\r\n default:\r\n throw new Error(\u0027Invalid action\u0027);\r\n }\r\n\r\n return result;\r\n};\r\n\r\n\r\n const command = window.generateRandomCommand();\r\n version1(command);","IsDeferred":false},{"Name":"if","Code":"\r\n\r\n const version2 = cmd =\u003E {\r\n const action = cmd[0]\r\n\r\n if (!window.actions.includes(action)) {\r\n throw new Error(\u0027Invalid action\u0027)\r\n }\r\n\r\n const result = { action }\r\n\r\n if (action !== \u0027f\u0027) {\r\n result.start = parseInt(cmd[2])\r\n }\r\n\r\n if (action !== \u0027i\u0027 \u0026\u0026 action !== \u0027f\u0027) {\r\n result.end = parseInt(cmd[4])\r\n }\r\n\r\n if (action === \u0027i\u0027) {\r\n result.text = cmd.slice(4)\r\n } else if (action === \u0027r\u0027) {\r\n result.text = cmd.slice(6)\r\n }\r\n\r\n if (action === \u0027m\u0027) {\r\n result.newPos = parseInt(cmd[6])\r\n }\r\n\r\n if (action === \u0027f\u0027) {\r\n result.search = cmd.slice(2)\r\n }\r\n\r\n return result\r\n}\r\n\r\n\r\n const command = window.generateRandomCommand();\r\n version2(command);","IsDeferred":false}]}