1Array.prototype.chunk = function(n) {
2 if (!this.length) {
3 return [];
4 }
5 return [this.slice(0, n)].concat(this.slice(n).chunk(n));
6};
7console.log([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].chunk(5));
1Array.prototype.chunk = function(size) {
2 let result = [];
3
4 while(this.length) {
5 result.push(this.splice(0, size));
6 }
7
8 return result;
9}
10
11const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
12console.log(arr.chunk(2));