function chunkArrayInGroups(arr, size) {
var arr1=arr.slice(0,size);
var arr2=arr.slice(size,);
var temp = [[], []];
temp[0].push(arr1);
temp[1].push(arr2);
console.log(temp);
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
Tell me why the program does not make such a decision.
Write a function that splits an array (first argument) into groups the length of size
(second argument) and returns them as a two-dimensional array.
with return() the same does not pass the test. I found the problem, but I don’t understand why this happens.
function chunkArrayInGroups(arr, size) {
var arr1=arr.slice(0,size);
var arr2=arr.slice(size,);
var temp = [[], []];
temp[0].push(arr1);
temp[1].push(arr2);
return temp;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
but even so does not work
and there is an option how to make my code work? Without changing the meaning. I can not find on the Internet. How to add two arrays into one, but so that they are two?
Thank you.
I did not understand the condition correctly.
I am Russian, I decide with a translator)))
With splice () it turned out, but only for a special case.