Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this was actually very hard challenge, because i could not figure out how to iterate in the loop
- function chunkArrayInGroups(arr, size) {
- var newarr=[];
- //here i set the loop to iterate by arr.length, and i to be incremented by size, because we need to iterate by size.
- for (var i=0; i<arr.length; i+=size){
- //then i push the iteration values inside a new array.
- newarr.push(arr.slice(i,i+size));
- }
- console.log(newarr);
- }
- chunkArrayInGroups([0, 1, 2, 3, 4, 5,6,7,8], 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement