Skip to content

Commit

Permalink
fix: fill result of splitArray
Browse files Browse the repository at this point in the history
  • Loading branch information
abichinger committed Nov 4, 2023
1 parent 1b42d11 commit 7b09c1e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,15 @@ function unimplemented(): never {
throw new Error('not implemented')
}

function splitArray<T>(arr: T[], chunkSize: number): T[][] {
function splitArray<T>(arr: T[], chunkSize: number, fill: boolean = true): (T|null)[][] {
const res = []

for (let i = 0; i < arr.length; i += chunkSize) {
res.push(arr.slice(i, i + chunkSize))
const slice: (T | null)[] = arr.slice(i, i + chunkSize)
while (fill && slice.length < chunkSize) {
slice.push(null);
}
res.push(slice)
}

return res
Expand Down

0 comments on commit 7b09c1e

Please sign in to comment.