Chunky Monkey solution feedback

Tell us what’s happening:
So I have an approach where I try to solve the problems on my own but I’d like to have some feedback on this solution as it isn’t really like those suggested in the hint section. I’m not really sure what is supposed to happen if you enter the size of 0 but I just solved it by not accepting 0 or lower.

Thanks for any feedback.

Your code so far

function chunkArrayInGroups(arr, size) {
  // Break it up.
  var newArray = [];
  var start = 0;
  if (size <= 0) // to stop it from infinite loop
      console.log("input positive digit 1-9");
      return null;
  for (var i=0;i<arr.length/size;i++)
      newArray[i] = arr.slice(start,start+size);
      start = start+size;

  return newArray;

chunkArrayInGroups(["a", "b", "c", "d"], 5);

Link to the challenge:

At this stage when you are learning, if it works then it works. :+1:
Say “well done” and move on.

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

1 Like