let chunk = function(arr, num){ num = num*1 || 1; let ret = []; arr.forEach(function(item, i){ if(i % num === 0){ ret.push([]); } ret[ret.length - 1].push(item); }); return ret;};