{"ScriptPreparationCode":"\r\n const chunkByLoop = (array,size)=\u003E{\r\n const chunked = [];\r\n for(let i=0;i\u003Carray.length;i\u002B\u002B){\r\n const chunk = chunked[chunked.length-1];\r\n chunk?.length \u003C size ? chunk.push(array[i]) : chunked.push([array[i]])\r\n }\r\n return chunked;\r\n }\r\n\r\n const chunkByReduce = (array,size)=\u003E{\r\n const result = array.reduce(((acc, item)=\u003E{\r\n const chunk = acc[acc.length-1];\r\n chunk?.length \u003C size ? chunk.push(item) : acc.push([item])\r\n return acc;\r\n }),[]);\r\n return result;\r\n }\r\n\r\n const chunkBySlice = (array,size)=\u003E{\r\n const chunked = [];\r\n if (size === 0) \r\n return chunked;\r\n\r\n const slicesNumber = array.length%size ? Math.ceil(array.length/size) : array.length/size;\r\n for(let i=0;i\u003CslicesNumber;i\u002B\u002B){\r\n chunked.push(array.slice(i*size,i*size\u002Bsize))\r\n }\r\n return chunked;\r\n }\r\n \r\n var checkResult = (expected,actual)=\u003E{\r\n return Array.isArray(expected) \u0026\u0026 Array.isArray(actual) \u0026\u0026 expected.length === actual.length \u0026\u0026\r\n expected.every((chunk,index)=\u003E Array.isArray(chunk) \u0026\u0026 chunk.every(item =\u003E actual[index].includes(item)))\r\n }\r\n \r\n \r\n var funMap = {\r\n \u0022ByLoop\u0022:chunkByLoop,\r\n \u0022ByReduce\u0022:chunkByReduce,\r\n \u0022BySlice\u0022:chunkBySlice\r\n }; \r\n\r\n\r\n","TestCases":[{"Name":"BySlice","Code":" const chunk = funMap[\u0022BySlice\u0022];\r\n const arrEmpty = chunk([],1);\r\n console.log(\u0022case 1\u0022,checkResult(arrEmpty,[]));\r\n\r\n const simpleCase = chunk([1,2,3,4],2);\r\n console.log(\u0022case 2\u0022,checkResult(simpleCase,[[1,2],[3,4]]));\r\n\r\n const advancedCase = chunk([1,2,3,4],3);\r\n console.log(\u0022case 3\u0022,checkResult(advancedCase,[[1,2,3],[4]]));","IsDeferred":false},{"Name":"ByReduce","Code":" const chunk = funMap[\u0022ByReduce\u0022];\r\n const arrEmpty = chunk([],1);\r\n console.log(\u0022case 1\u0022,checkResult(arrEmpty,[]));\r\n\r\n const simpleCase = chunk([1,2,3,4],2);\r\n console.log(\u0022case 2\u0022,checkResult(simpleCase,[[1,2],[3,4]]));\r\n\r\n const advancedCase = chunk([1,2,3,4],3);\r\n console.log(\u0022case 3\u0022,checkResult(advancedCase,[[1,2,3],[4]]));","IsDeferred":false}]}