Https://www.freecodecamp.com/challenges/chunky-monkey

Https://www.freecodecamp.com/challenges/chunky-monkey
0.0 0

#1


Hello artuist, I could be able to split the array. But now I can’t insert these arrays into a single array. can you please tell me what’s the problem? Here is my code:
/////////////////////////////////////////////////////////////////////////////////////

function chunkArrayInGroups(arr, size) {
// Break it up.
var start = 0;
var end = size;
var citrus;
var newArr = [];
for(i = 0; i < arr.length; i+=size){
citrus = arr.slice(start, end);
console.log(citrus);
newArr.push(citrus);
start = end;
end = start + size;
}
console.log(newArr);
}

chunkArrayInGroups([“a”, “b”, “c”, “d”], 2);

/////////////////////////////////////////////////////////////////////////////////////


#2

seems like newArr has what you want - just return newArr from the function


#3

could you please explain it more clearly ? It shows this output:


#4

@ppc says that you need to change this line

console.log(newArr);

to

return newArr;

Every function should return value or another function. Yours doesn’t return any value , that’s why your solution is incorrect


#5

If I change it to return type then it shows same output.


#6

Well I typed your solution into my freecodeCamp workspace and it’s working:

function chunkArrayInGroups(arr, size) {
// Break it up.
var start = 0;
var end = size;
var citrus;
var newArr = [];
for(i = 0; i < arr.length; i+=size){
citrus = arr.slice(start, end);
console.log(citrus);
newArr.push(citrus);
start = end;
end = start + size;
}
return newArr;
}


#7

yeah now it works. thanks a lot.