Skip to content

Commit 5b4dc54

Browse files
blikblumjdalton
authored andcommitted
Coerce to integer and set default value for chunk size parameter (#4413)
* Enable chunk module tests * Coerce to integer and set default value for chunk size param
1 parent 37cd5dc commit 5b4dc54

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

chunk.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import slice from './slice.js'
2+
import toInteger from './toInteger.js'
23

34
/**
45
* Creates an array of elements split into groups the length of `size`.
@@ -18,8 +19,8 @@ import slice from './slice.js'
1819
* chunk(['a', 'b', 'c', 'd'], 3)
1920
* // => [['a', 'b', 'c'], ['d']]
2021
*/
21-
function chunk(array, size) {
22-
size = Math.max(size, 0)
22+
function chunk(array, size = 1) {
23+
size = Math.max(toInteger(size), 0)
2324
const length = array == null ? 0 : array.length
2425
if (!length || size < 1) {
2526
return []

test/chunk.js renamed to test/chunk.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,4 @@ describe('chunk', function() {
4242
it('should coerce `size` to an integer', function() {
4343
assert.deepStrictEqual(chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
4444
});
45-
46-
it('should work as an iteratee for methods like `_.map`', function() {
47-
var actual = lodashStable.map([[1, 2], [3, 4]], chunk);
48-
assert.deepStrictEqual(actual, [[[1], [2]], [[3], [4]]]);
49-
});
5045
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy