Chunkey monkey clarification

I am trying to solve it recursively and wanna set proper base cases.

There are no test cases for size ===0.

But i guess chunkArrayInGroups(arr, size) should return empty array for the case above? Is that correct?

Edit. For moderators.
I accidentally posted it in General subforum. Is there an opportunity to move thread in JS subforum?

That will depend on how your algorithm. Have you written out an algorithm yet for the challenge?

I didn’t write recursive step yet.

But I think I will use base case for size===1:

function chunkArrayInGroups(arr, size) {
  //base case
  if (size===1) {
    return [arr]
  //to do: figure out recursive step
  //try to grasp difference between cases size=== 3 and size===4
  //for some testArray

basecasecheck = chunkArrayInGroups(["a", "b", "c", "d"], 1);

console.log(basecasecheck);//[ [ 'a', 'b', 'c', 'd' ] ]

I think in recursive step will be some kind of call like below:

chunkArrayInGroups(arr, size + 1)

For now I didn’t figured out what methods I wanna use, but I have a general idea

So I need to know how function should behave when size < 1 to add some more base cases

Like I said before, I don’t know what algorithm you have written up, so it is hard to say what your base case should be. Are you going to mutate the original array or not? That would change the overall approach and base case.

Your size should not change at all during this process…

Makes sense, I’ll work on recursive step and will provide more info after that

I guess I gave little more info than needed in the original post.

My question:

What is expected behaviour for chunkArrayInGroups(arr, size) when size < 1?

There are no such tests in the challenge step. Should I be bothered with this at all?

The challenge does not specify but I would probably expect an empty array since an array of size zero has to be empty.

That is up to you.

1 Like