Skip to content

Commit

Permalink
Update chunk-array.md
Browse files Browse the repository at this point in the history
  • Loading branch information
LuziferSenpai authored Jan 9, 2025
1 parent a8e4919 commit a1297c8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snippets/javascript/array-manipulation/chunk-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function chunkArray(array, chunkSize) {
if (!Array.isArray(array)) {
throw new TypeError('Expected an array as the first argument.');
}
if (typeof chunkSize !== 'number' || chunkSize <= 0) {
if (typeof chunkSize !== 'number' || Number.isNaN(chunkSize) || chunkSize <= 0) {
throw new RangeError('Chunk size must be a positive number.');
}

Expand All @@ -30,4 +30,4 @@ function chunkArray(array, chunkSize) {
// Usage:
const data = [1, 2, 3, 4, 5, 6, 7, 8];
const chunked = chunkArray(data, 3); // Returns: [[1, 2, 3], [4, 5, 6], [7, 8]]
```
```

0 comments on commit a1297c8

Please sign in to comment.