{"ScriptPreparationCode":"function chunk1(xs, n) {\r\n return xs.reduce(function(o, x, i) {\r\n o[Math.floor(i / n)].push(x);\r\n return o;\r\n }, Array(Math.ceil(xs.length / n)).fill([]));\r\n}\r\n\r\nfunction chunk2(xs, n) {\r\n return (xs.length \u003C= n) ? [xs] : [\r\n xs.slice(0, n),\r\n ...chunk2(xs.slice(n), n)\r\n ]\r\n}\r\n\r\nfunction chunk3(array, size) {\r\n //declaring variable \u0027chunked\u0027 as an empty array\r\n let chunked = []\r\n\r\n //looping through the array until it has been entirely \u0022manipulated\u0022 or split into our subarrays\r\n while (array.length \u003E 0) {\r\n //taking the spliced segments completely out of our original array\r\n //pushing these subarrays into our new \u0022chunked\u0022 array\r\n chunked.push(array.splice(0, size))\r\n }\r\n //returning the new array of subarrays\r\n return chunked\r\n}\r\n\r\nfunction chunk4(array, size) {\r\n //declaring variable \u0027chunked\u0027 as an empty array\r\n let chunked = []\r\n\r\n //setting our start point for our while loop at index 0\r\n let i = 0;\r\n //looping through the array until we have reached the final index\r\n while (i \u003C array.length) {\r\n //push the sliced subarray of length \u0027size\u0027 into our new \u0027chunked\u0027 array\r\n chunked.push(array.slice(i, i \u002B size))\r\n //increment by the size as to avoid duplicates\r\n i \u002B= size;\r\n }\r\n //return the array of subarrays\r\n return chunked\r\n}\r\n\r\nfunction chunk5(array, size) {\r\n //declaring variable \u0027chunked\u0027 as an empty array\r\n let chunked = [];\r\n\r\n //for loop iterating through every element of our input array\r\n for (let ele of array) {\r\n //declaring variable \u0027last\u0027 as the last index of our \u0027chunked\u0027 array\r\n const last = chunked[chunked.length - 1];\r\n\r\n //checking if last is undefined or if the last subarray is equal to the size\r\n if (!last || last.length === size) {\r\n //then we push the element to be a new subarray in \u0027chunked\u0027\r\n chunked.push([ele])\r\n } else {\r\n //if not, then we add the element to the \u0027last\u0027 subarray\r\n last.push(ele)\r\n }\r\n }\r\n //return the array of subarrays\r\n return chunked\r\n}\r\n\r\nfunction chunk6(array, size) {\r\n const chunked_arr = [];\r\n for (let i = 0; i \u003C array.length; i\u002B\u002B) {\r\n const last = chunked_arr[chunked_arr.length - 1];\r\n if (!last || last.length === size) {\r\n chunked_arr.push([array[i]]);\r\n } else {\r\n last.push(array[i]);\r\n }\r\n }\r\n return chunked_arr;\r\n}\r\n\r\nfunction chunk7(array, size) {\r\n const chunked_arr = [];\r\n let copied = [...array]; // ES6 destructuring\r\n const numOfChild = Math.ceil(copied.length / size); // Round up to the nearest integer\r\n for (let i = 0; i \u003C numOfChild; i\u002B\u002B) {\r\n chunked_arr.push(copied.splice(0, size));\r\n }\r\n return chunked_arr;\r\n}\r\n\r\nfunction chunk8(array, size) {\r\n const chunked_arr = [];\r\n let index = 0;\r\n while (index \u003C array.length) {\r\n chunked_arr.push(array.slice(index, size \u002B index));\r\n index \u002B= size;\r\n }\r\n return chunked_arr;\r\n}\r\n\r\nfunction chunk9(array, size) {\r\n if (!array) return [];\r\n const firstChunk = array.slice(0, size); // create the first chunk of the given array\r\n if (!firstChunk.length) {\r\n return array; // this is the base case to terminal the recursive\r\n }\r\n return [firstChunk].concat(chunk9(array.slice(size, array.length), size));\r\n}\r\n\r\nfunction chunk10(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 chunk11(array, size) {\r\n if (array.length \u003C= size) {\r\n return [array]\r\n }\r\n return [array.slice(0, size), ...chunk11(array.slice(size), size)]\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},{"Name":"6","Code":"chunk6([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"7","Code":"chunk7([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"8","Code":"chunk8([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"9","Code":"chunk9([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"10","Code":"chunk10([1, 2, 3, 4], 2);","IsDeferred":false},{"Name":"11","Code":"chunk11([1, 2, 3, 4], 2);","IsDeferred":false}]}