2025-05-22 15:24:22 0阅读 0喜欢
881访问人次
Camila Waz 2025-05-22 15:27:07
2025-05-22 15:12:09 0阅读 0喜欢
2025-05-22 15:10:36 0阅读 0喜欢
2025-05-22 15:09:26 0阅读 0喜欢
2025-05-22 15:08:51 0阅读 0喜欢
2025-05-22 15:06:49 0阅读 0喜欢
124
2021-07-30 16:08:54 124阅读 0喜欢
function createGroups(arr, numGroups) {
  const perGroup = Math.ceil(arr.length / numGroups);
  return new Array(numGroups)
  .fill('')
  .map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup));
}
console.log(createGroups(['cat', 'dog', 'pig', 'frog'], 2));
// 输出结果 [["cat", "dog"], ["pig", "frog"]]

console.log(createGroups([1, 2, 3, 4, 5], 3));
// 输出结果 [[1, 2], [3, 4], [5]]