{"ScriptPreparationCode":"function chunk1(array, size) {\r\n let chunked = [];\r\n\r\n for (let ele of array) {\r\n const last = chunked[chunked.length - 1];\r\n\r\n if (!last || last.length === size) {\r\n chunked.push([ele])\r\n } else {\r\n last.push(ele)\r\n }\r\n }\r\n \r\n return chunked\r\n}\r\n\r\nfunction chunk2(array, size) {\r\n let chunked = [];\r\n\r\n array.forEach(element =\u003E {\r\n const last = chunked[chunked.length - 1];\r\n if (!last || last.length === size) {\r\n chunked.push([element])\r\n } else {\r\n last.push(element)\r\n }\r\n });\r\n \r\n return chunked\r\n}\r\n\r\nfunction chunk3(arr, n) {\r\n let chunked = arr.reduce((chunk, val) =\u003E {\r\n\r\n if (chunk[chunk.length - 1].length === n)\r\n chunk.push([]);\r\n\r\n chunk[chunk.length - 1].push(val);\r\n\r\n return chunk;\r\n }, [\r\n []\r\n ]);\r\n\r\n return chunked\r\n}\r\n\r\nfunction chunk4 ([...arr], n) {\r\n return [...Array(Math.ceil(arr.length) / n)].map(_ =\u003E arr.splice(0, n));\r\n}\r\n\r\nfunction chunk5([...array], size) {\r\n let chunked = []\r\n\r\n while(array.length \u003E 0) {\r\n chunked.push(array.splice(0, size))\r\n }\r\n \r\n return chunked\r\n}\r\n","TestCases":[{"Name":"1","Code":"chunk1([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"2","Code":"chunk2([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"3","Code":"chunk3([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"4","Code":"chunk4([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"5","Code":"chunk5([1, 2, 3, 4], 2);","IsDeferred":false}]}