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]]