Advertisement
Guest User

Untitled

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