Skip to content

Commit

Permalink
perf(chunk): remove clone (#574)
Browse files Browse the repository at this point in the history
* perf(chunk): remove clone

* fix: resolved bug
  • Loading branch information
kyranet committed Apr 10, 2023
1 parent 64723e3 commit 049047b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`ESLint Config > should export rules 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Prettier Config > should export rules 1`] = `
{
Expand Down
3 changes: 1 addition & 2 deletions packages/utilities/src/lib/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export function chunk<T>(array: readonly T[], chunkSize: number): T[][] {
if (!Array.isArray(array)) throw new TypeError('entries must be an array.');
if (!Number.isInteger(chunkSize)) throw new TypeError('chunkSize must be an integer.');
if (chunkSize < 1) throw new RangeError('chunkSize must be 1 or greater.');
const clone: T[] = array.slice();
const chunks: T[][] = [];
while (clone.length) chunks.push(clone.splice(0, chunkSize));
for (let i = 0; i < array.length; i += chunkSize) chunks.push(array.slice(i, i + chunkSize));
return chunks;
}

0 comments on commit 049047b

Please sign in to comment.