{"ScriptPreparationCode":"function format1(bytes) {\r\n var sizes = [\u0027Bytes\u0027, \u0027KB\u0027, \u0027MB\u0027, \u0027GB\u0027, \u0027TB\u0027];\r\n if (bytes == 0) return \u00270 Byte\u0027;\r\n var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));\r\n return Math.round(bytes / Math.pow(1024, i), 2) \u002B \u0027 \u0027 \u002B sizes[i];\r\n}\r\n\r\n\r\nfunction format2(bytes, decimals = 2) {\r\n if (bytes === 0) return \u00270 Bytes\u0027;\r\n\r\n const k = 1024;\r\n const dm = decimals \u003C 0 ? 0 : decimals;\r\n const sizes = [\u0027Bytes\u0027, \u0027KB\u0027, \u0027MB\u0027, \u0027GB\u0027, \u0027TB\u0027, \u0027PB\u0027, \u0027EB\u0027, \u0027ZB\u0027, \u0027YB\u0027];\r\n\r\n const i = Math.floor(Math.log(bytes) / Math.log(k));\r\n\r\n return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) \u002B \u0027 \u0027 \u002B sizes[i];\r\n}\r\n\r\nfunction format3(bytes) {\r\n var marker = 1024; // Change to 1000 if required\r\n var decimal = 3; // Change as required\r\n var kiloBytes = marker; // One Kilobyte is 1024 bytes\r\n var megaBytes = marker * marker; // One MB is 1024 KB\r\n var gigaBytes = marker * marker * marker; // One GB is 1024 MB\r\n var teraBytes = marker * marker * marker * marker; // One TB is 1024 GB\r\n\r\n // return bytes if less than a KB\r\n if(bytes \u003C kiloBytes) return bytes \u002B \u0022 Bytes\u0022;\r\n // return KB if less than a MB\r\n else if(bytes \u003C megaBytes) return(bytes / kiloBytes).toFixed(decimal) \u002B \u0022 KB\u0022;\r\n // return MB if less than a GB\r\n else if(bytes \u003C gigaBytes) return(bytes / megaBytes).toFixed(decimal) \u002B \u0022 MB\u0022;\r\n // return GB if less than a TB\r\n else return(bytes / gigaBytes).toFixed(decimal) \u002B \u0022 GB\u0022;\r\n}\r\n\r\n\r\nconst units = [\u0027bytes\u0027, \u0027KB\u0027, \u0027MB\u0027, \u0027GB\u0027, \u0027TB\u0027, \u0027PB\u0027, \u0027EB\u0027, \u0027ZB\u0027, \u0027YB\u0027];\r\n \r\nfunction format4(x){\r\n\r\n let l = 0, n = parseInt(x, 10) || 0;\r\n\r\n while(n \u003E= 1024 \u0026\u0026 \u002B\u002Bl){\r\n n = n/1024;\r\n }\r\n \r\n return(n.toFixed(n \u003C 10 \u0026\u0026 l \u003E 0 ? 1 : 0) \u002B \u0027 \u0027 \u002B units[l]);\r\n}\r\n\r\nfunction format5(bytes){\r\n var kb = 1024;\r\n var ndx = Math.floor( Math.log(bytes) / Math.log(kb) );\r\n var fileSizeTypes = [\u0022bytes\u0022, \u0022kb\u0022, \u0022mb\u0022, \u0022gb\u0022, \u0022tb\u0022, \u0022pb\u0022, \u0022eb\u0022, \u0022zb\u0022, \u0022yb\u0022];\r\n\r\n return {\r\n size: \u002B(bytes / kb / kb).toFixed(2),\r\n type: fileSizeTypes[ndx]\r\n };\r\n}\r\n","TestCases":[{"Name":"f1","Code":"for(var i =0; i\u003C100; i\u002B\u002B){\r\n var a = format1(i*1024); \r\n}","IsDeferred":false},{"Name":"f2","Code":"for(var i =0; i\u003C100; i\u002B\u002B){\r\n var a = format2(i*1024); \r\n}","IsDeferred":false},{"Name":"f3","Code":"for(var i =0; i\u003C100; i\u002B\u002B){\r\n var a = format3(i*1024); \r\n}","IsDeferred":false},{"Name":"f4","Code":"for(var i =0; i\u003C100; i\u002B\u002B){\r\n var a = format4(i*1024); \r\n}","IsDeferred":false},{"Name":"f5","Code":"for(var i =0; i\u003C100; i\u002B\u002B){\r\n var a = format5(i*1024); \r\n}","IsDeferred":false}]}