JavaScript basic algorithm

function chunkArrayInGroups(arr, size) {
  if (arr.length <= size) {
    return [arr];
  } else {
    return [arr.slice(0, size)].concat(
      chunkArrayInGroups(arr.slice(size), size)
    );
  }
}

From what I understand about slice, it takes two arguments which are start and end but the end is not included. So in the above line of code, size was an end argument for the first slice which I think will end up giving one less element than the required size considering the index pattern of array. How was this reconciled please

Secondly, Is there a difference between the two sizes (first and second argument) in the last line of code

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.