Spot the bug TypeScript
1
// Split items into `groupCount` round-robin buckets.
2
function partition<T>(items: T[], groupCount: number): T[][] {3
const buckets: T[][] = Array(groupCount).fill([]);
4
items.forEach((item, i) => {5
buckets[i % groupCount].push(item);
6
});
7
return buckets;
8
}
9
10
const result = partition(["a", "b", "c", "d"], 2);
11
console.log(result[0]); // expected: ["a", "c"]
12
console.log(result[1]); // expected: ["b", "d"]