Last active
May 13, 2018 11:35
-
-
Save AdrianSkar/496b8f0df3987a19e7e416806e4aac48 to your computer and use it in GitHub Desktop.
[JS] fCC's exercise Chunky monkey: https://codepen.io/adrianskar/pen/zjjpdG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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