Chunky Monkey - Very different solution

So this is on the Chunky Monkey alg obv…

It took a while for me to solve and I never looked at any hints. I felt pretty good about it but then I looked at the hints after and the solution is WAY different than what I have. Is there anybody that has any comments about what I may have been missing in solving it the way I did rather than what was in the hints link?

Thanks!

Your code so far

function chunkArrayInGroups(arr, size) {

var arrsingle = [];
  var j= 0;

  var newarr = [];
  
  for( var i = 1; i <= Math.ceil(arr.length/size); i++){
    arrsingle=arr.slice(j,j+size);
   newarr.push(arrsingle);
   j=j+size;

  }

  
  return newarr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.

Link to the challenge:

Don’t worry about how you came to your solution - if it works, it works.

There is a contentious quote about programming: ‘make it work, make it right, make it fast’

You made it work! That’s a big step.

Read the other examples and see if you understand what they do and why someone may have chosen to do it those ways instead.

I ran a benchmark test on the basic, intermediate and advanced solutions from the hints (didn’t bother with the last one):

image

Yours is a little faster that the supposed ‘intermediate’ and ‘advanced’ solutions - but way slower than the beginner solution! Figuring out why will teach you some interesting things about algorithm complexity :slight_smile:

Edit:

For anyone interested in how I benchmarked them, I followed the process I wrote about here: https://medium.freecodecamp.org/what-i-learned-from-writing-six-functions-that-all-did-the-same-thing-b38fd48f0d55

Wow. Thanks Jackson. Very helpful.