From 5b4dc54465a0c07efd0d5f61532ca0fdc6ee013e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Sat, 17 Aug 2019 13:53:11 -0300 Subject: [PATCH] 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 --- chunk.js | 5 +++-- test/{chunk.js => chunk.test.js} | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-) rename test/{chunk.js => chunk.test.js} (87%) diff --git a/chunk.js b/chunk.js index f06b0e93b..8d57b4b19 100644 --- a/chunk.js +++ b/chunk.js @@ -1,4 +1,5 @@ import slice from './slice.js' +import toInteger from './toInteger.js' /** * Creates an array of elements split into groups the length of `size`. @@ -18,8 +19,8 @@ import slice from './slice.js' * chunk(['a', 'b', 'c', 'd'], 3) * // => [['a', 'b', 'c'], ['d']] */ -function chunk(array, size) { - size = Math.max(size, 0) +function chunk(array, size = 1) { + size = Math.max(toInteger(size), 0) const length = array == null ? 0 : array.length if (!length || size < 1) { return [] diff --git a/test/chunk.js b/test/chunk.test.js similarity index 87% rename from test/chunk.js rename to test/chunk.test.js index 74121e10d..f8bdc69d2 100644 --- a/test/chunk.js +++ b/test/chunk.test.js @@ -42,9 +42,4 @@ describe('chunk', function() { it('should coerce `size` to an integer', function() { assert.deepStrictEqual(chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]); }); - - it('should work as an iteratee for methods like `_.map`', function() { - var actual = lodashStable.map([[1, 2], [3, 4]], chunk); - assert.deepStrictEqual(actual, [[[1], [2]], [[3], [4]]]); - }); });