Skip to content

Instantly share code, notes, and snippets.

@AdrianSkar
Last active May 13, 2018 11:35
Show Gist options
  • Save AdrianSkar/496b8f0df3987a19e7e416806e4aac48 to your computer and use it in GitHub Desktop.
Save AdrianSkar/496b8f0df3987a19e7e416806e4aac48 to your computer and use it in GitHub Desktop.
[JS] fCC's exercise Chunky monkey: https://codepen.io/adrianskar/pen/zjjpdG
function chunkArrayInGroups(arr, size) {
var newarr=[];
for (i=arr.length, y=0; i>0; i-=size, y+=size){
newarr.push(arr.slice(y, size+y));
}
/* Simpler using just one var but calculates arr.length on each iteration
for (i=0; i<arr.length; i+=size){
newarr.push(arr.slice(i, i+size));
}*/
return newarr;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment