"How do I write a JavaScript function that splits an array into groups and returns them as a two-dimensional array?"

I was struggling with this FreeCodeCamp lesson/exercise and I ended up finding the solution here on StackOverFlow:

function chunkArrayInGroups(arr, size) {
	var result = [];
    while (arr.length > size) {
        result.push(arr.splice(0, size));
    if (arr.length)
  return result;

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Show Comments

var.pop( )

Web Development Tips & Tricks