Skip to content

Instantly share code, notes, and snippets.

@twhite96
Created June 18, 2016 03:28
Show Gist options
  • Save twhite96/75e1dab5c8683ac22197487bd718b0a4 to your computer and use it in GitHub Desktop.
Save twhite96/75e1dab5c8683ac22197487bd718b0a4 to your computer and use it in GitHub Desktop.
Chunky Monkey algorithm Free Code Camp solution
function chunkArrayInGroups(arr, size) {
var newArray = [];
var oldArray = arr.length/size;
for (var i = 0; i < oldArray; i++) {
var array = arr.splice(0, size);
newArray.push(array);
}
return newArray;
// Break it up.
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2);
@twhite96
Copy link
Author

Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.

Remember to use Read-Search-Ask if you get stuck. Write your own code.

Here are some helpful links:

Array.push()
Array.slice()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment