mirror of https://github.com/fantasticit/think.git
11 lines
214 B
TypeScript
11 lines
214 B
TypeScript
|
export function chunk<T>(arr: Array<T>, size = 1) {
|
||
|
const res: Array<T[]> = [];
|
||
|
|
||
|
for (let i = 0; i < arr.length; i += size) {
|
||
|
const slice = arr.slice(i, i + size);
|
||
|
res.push(slice);
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|