{"ScriptPreparationCode":"var n = 128,\r\n l = -14,\r\n h = 304;\r\n\r\nvar clampIf = (x) =\u003E {\r\n if (x \u003C 0) return 0;\r\n else if (x \u003E 255) return 255;\r\n else return x;\r\n};\r\n\r\nvar clampTern = (x) =\u003E (x \u003C 0) ? 0 : (x \u003E 255) ? 255 : x;\r\n\r\nfunction clampU(x){ x \u003C 0 \u0026\u0026 (x=0); x \u003E 255 \u0026\u0026 (x=255); return x }\r\n\r\nfunction clampMinMax(x){return Math.min(Math.max(x,0),255) }","TestCases":[{"Name":"Clamp from 0 to 255 using ternary","Code":"n = n \u003C 0 ? 0 : n \u003E 255 ? 255 : n;\r\nl = l \u003C 0 ? 0 : l \u003E 255 ? 255 : l;\r\nh = h \u003C 0 ? 0 : h \u003E 255 ? 255 : h;\r\n\r\n\r\n","IsDeferred":false},{"Name":"Clamp from 0 to 255 using Min/Max","Code":"n = Math.min(Math.max(n,0),255);\r\nl = Math.min(Math.max(l,0),255);\r\nh = Math.min(Math.max(h,0),255);","IsDeferred":false},{"Name":"Clamp from 0 to 255 with IF","Code":"if (n \u003C 0) { n = 0; } else if (n \u003E 255) { n = 255; };\r\nif (l \u003C 0) { l = 0; } else if (l \u003E 255) { l = 255; };\r\nif (h \u003C 0) { h = 0; } else if (n \u003E 255) { h = 255; };","IsDeferred":false},{"Name":"Clamp from 0 to 255 with unary \u0026\u0026","Code":"n \u003C 0 \u0026\u0026 (n=0);\r\nn \u003E 255 \u0026\u0026 (n=255);\r\nl \u003C 0 \u0026\u0026 (l=0);\r\nl \u003E 255 \u0026\u0026 (l=255);\r\nh \u003C 0 \u0026\u0026 (h=0);\r\nh \u003E 255 \u0026\u0026 (h=255);\r\n\r\n","IsDeferred":false},{"Name":"Clamp in arrow function with ternary","Code":"n = clampTern(n);\r\nl = clampTern(l);\r\nh = clampTern(h);\r\n\r\n\r\n","IsDeferred":false},{"Name":"Clamp in regular function with MinMax","Code":"n = clampMinMax(n);\r\nl = clampMinMax(l);\r\nh = clampMinMax(h);\r\n\r\n","IsDeferred":false},{"Name":"Clamp in arrow function with IF","Code":"n = clampIf(n);\r\nl = clampIf(l);\r\nh = clampIf(h);","IsDeferred":false},{"Name":"Clamp in regular function with unary","Code":"n = clampU(n);\r\nl = clampU(l);\r\nh = clampU(h);","IsDeferred":false}]}