Skip to content

Instantly share code, notes, and snippets.

@thinsoldier
Last active August 17, 2016 05:16
Show Gist options
  • Save thinsoldier/0ba8be1e6534bc6002dc9eb6838d73bd to your computer and use it in GitHub Desktop.
Save thinsoldier/0ba8be1e6534bc6002dc9eb6838d73bd to your computer and use it in GitHub Desktop.
// https://www.freecodecamp.com/challenges/chunky-monkey/
function chunkArrayInGroups(arr, size) {
// avoid infinite loop
if( arr.length === 0 || size === 0)
{ return false; }
var chunkedList = [];
for ( var i=0; i < arr.length; i += size)
{
var temp = arr.slice(i, i+size);
chunkedList.push(temp);
}
return chunkedList;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment