{"ScriptPreparationCode":null,"TestCases":[{"Name":"1","Code":" function chunkArraySlice(array, size) {\r\n let result = []\r\n \r\n for (i = 0; i \u003C array.length; i \u002B= size) {\r\n let chunk = array.slice(i, i \u002B size)\r\n result.push(chunk)\r\n }\r\n \r\n return result\r\n }\r\n\r\nconsole.log(chunkArraySlice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 2));\r\n","IsDeferred":false},{"Name":"2","Code":"const chunk = (arr, size) =\u003E\r\n Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =\u003E\r\n arr.slice(i * size, i * size \u002B size)\r\n );\r\nconsole.log(chunk([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 2));\r\n","IsDeferred":false},{"Name":"3","Code":"function chunkArray(myArray, chunk_size){\r\n var results = [];\r\n \r\n while (myArray.length) {\r\n results.push(myArray.splice(0, chunk_size));\r\n }\r\n \r\n return results;\r\n}\r\n\r\nconsole.log(chunkArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 2)); \r\n","IsDeferred":false},{"Name":"4","Code":"function chunkArraySlice(array, size) {\r\n let result = []\r\n \r\n let i = 0\r\n array.forEach(() =\u003E {\r\n let chunk = array.slice(i, i \u002B size)\r\n result.push(chunk)\r\n i\u002B=size\r\n })\r\n \r\n return result\r\n }\r\n\r\nconsole.log(chunkArraySlice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 2));\r\n","IsDeferred":false},{"Name":"5","Code":"const chunkIt = (arr, size) =\u003E {\r\n let buckets = []\r\n \r\n size = size != 0 ? Math.abs(size) : 1\r\n\r\n // Just create the buckets/chunks storage\r\n for (let i = 1; i \u003C= Math.ceil(arr.length / size); i\u002B\u002B) {\r\n buckets.push([])\r\n }\r\n\r\n // Put in the buckets/storage by index access only\r\n for (let i = 0; i \u003C arr.length; i\u002B\u002B) {\r\n var arrIndex = Math.ceil((i \u002B 1) / size) - 1\r\n buckets[arrIndex].push(arr[i])\r\n }\r\n\r\n return buckets;\r\n}\r\n\r\nconsole.log(chunkIt([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 2));\r\n","IsDeferred":false},{"Name":"6","Code":"function 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\nconsole.log(chunk10([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 2));","IsDeferred":false}]}