{"ScriptPreparationCode":"\r\nfunction chunkReduce(array, size = 1) {\r\n return array.reduce((target, item, index) =\u003E {\r\n if (index % size === 0) {\r\n return [...target, [item]]\r\n }\r\n const last = target[target.length - 1]\r\n return [...target.slice(0, target.length - 1), [...last, item]]\r\n }, [])\r\n}\r\nfunction chunkReduce2(array, size = 1) {\r\n let key = -1\r\n return array.reduce((target, item, index) =\u003E {\r\n if (index % size === 0) {\r\n key\u002B\u002B\r\n target[key] = []\r\n }\r\n target[key].push(item)\r\n\treturn target\r\n }, [])\r\n}\r\nfunction chunkReduce3(array, size = 1) {\r\n let key = -1\r\n const length = array.length\r\n const target = []\r\n for (let index = 0; index \u003C length; \u002B\u002Bindex) {\r\n const item = array[index]\r\n if (index % size === 0) {\r\n key\u002B\u002B\r\n target[key] = []\r\n }\r\n target[key].push(item)\r\n }\r\n return target\r\n}\r\n\r\n\r\nfunction chunkWhile(array, size = 1) {\r\n var length = array == null ? 0 : array.length;\r\n if (!length || size \u003C 1) {\r\n return [];\r\n }\r\n var index = 0,\r\n resIndex = 0,\r\n result = Array(Math.ceil(length / size));\r\n\r\n while (index \u003C length) {\r\n result[resIndex\u002B\u002B] = array.slice(index, (index \u002B= size));\r\n }\r\n return result;\r\n}\r\n","TestCases":[{"Name":"Using reduce","Code":"chunkReduce([1,2,3,4,5,6,7,8,9,1,0,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,7,14,6,4,56,4,5], 4)","IsDeferred":false},{"Name":"Using while","Code":"chunkWhile([1,2,3,4,5,6,7,8,9,1,0,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,7,14,6,4,56,4,5], 4)","IsDeferred":false},{"Name":"Using reduce 2 and push","Code":"chunkReduce2([1,2,3,4,5,6,7,8,9,1,0,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,7,14,6,4,56,4,5], 4)","IsDeferred":false},{"Name":"Using for loop and push","Code":"chunkReduce3([1,2,3,4,5,6,7,8,9,1,0,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,7,14,6,4,56,4,5], 4)","IsDeferred":false}]}