mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
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
This commit is contained in:
committed by
John-David Dalton
parent
37cd5dc97a
commit
5b4dc54465
5
chunk.js
5
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 []
|
||||
|
||||
Reference in New Issue
Block a user