📜  js 从数组创建批次 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:19.843000             🧑  作者: Mango

代码示例1
function splitToBulks(arr: T[], bulkSize: number = 20): T[][] {
  const bulks: T[][] = [];
  for (let i = 0; i < Math.ceil(arr.length / bulkSize); i++) {
      bulks.push(arr.slice(i * bulkSize, (i + 1) * bulkSize));
  }
  return bulks;
}