{"ScriptPreparationCode":"var numbers = new Array(1000);\r\nvar results = new Array(1000);\r\n\r\nfor (let i = 0; i \u003C numbers.length; i\u002B\u002B);\r\n{\r\n numbers[i] = (Math.random() - 0.5) * 3;\r\n}\r\n\r\nfunction clamp(min, value, max) {\r\n\tif (value \u003E= max)\r\n\t\treturn max;\r\n\tif (value \u003C= min)\r\n\t\treturn min;\r\n\treturn value;\r\n}\r\n\r\nfunction clamp2(min, value, max) {\r\n\treturn [min, value, max][1 \u002B (value \u003E= max) - (value \u003C= min)];\r\n}\r\n\r\nfunction clamp3(min, value, max) {\r\n\treturn Math.max(value, Math.min(value, max));\r\n}\r\n\r\nfunction clamp4(min, value, max) {\r\n return value \u003C= min ? min : (value \u003E= max ? max : value);\r\n}\r\n\r\nfunction clamp5(min, value, max) {\r\n\tif (value \u003E= max)\r\n\t\treturn max;\r\n\telse if (value \u003C= min)\r\n\t\treturn min;\r\n\telse\r\n\t\treturn value;\r\n}\r\n\r\nfunction clamp6(min, value, max) {\r\n\treturn (value \u003E= max) * (max - value) \u002B\r\n\t\t\t(value \u003C= min) * (min - value) \u002B\r\n\t\t\tvalue;\r\n}\r\n","TestCases":[{"Name":"Early Return","Code":"for (let i = 0; i \u003C numbers.length; i\u002B\u002B) {\r\n\tresults[i] = clamp(0, numbers[i], 1.0);\r\n}","IsDeferred":false},{"Name":"Compute Offset in Array","Code":"for (let i = 0; i \u003C numbers.length; i\u002B\u002B) {\r\n\tresults[i] = clamp2(0, numbers[i], 1.0);\r\n}\r\n","IsDeferred":false},{"Name":"Math Min and Max Functions","Code":"for (let i = 0; i \u003C numbers.length; i\u002B\u002B) {\r\n\tresults[i] = clamp3(0, numbers[i], 1.0);\r\n}\r\n","IsDeferred":false},{"Name":"Ternary Operators","Code":"for (let i = 0; i \u003C numbers.length; i\u002B\u002B) {\r\n\tresults[i] = clamp4(0, numbers[i], 1.0);\r\n}","IsDeferred":false},{"Name":"If...else","Code":"for (let i = 0; i \u003C numbers.length; i\u002B\u002B) {\r\n\tresults[i] = clamp5(0, numbers[i], 1.0);\r\n}","IsDeferred":false},{"Name":"Pure Arithmetic","Code":"for (let i = 0; i \u003C numbers.length; i\u002B\u002B) {\r\n\tresults[i] = clamp6(0, numbers[i], 1.0);\r\n}","IsDeferred":false}]}