mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Avoid type coercion of size in _.chunk unless needed.
This commit is contained in:
10
lodash.js
10
lodash.js
@@ -3125,7 +3125,7 @@
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Creates an array of elements split into groups the length of `chunkSize`.
|
||||
* Creates an array of elements split into groups the length of `size`.
|
||||
* If `collection` can't be split evenly, the final chunk will be the remaining
|
||||
* elements.
|
||||
*
|
||||
@@ -3133,7 +3133,7 @@
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {Array} array The array to process.
|
||||
* @param {numer} [chunkSize=1] The size of each chunk.
|
||||
* @param {numer} [size=1] The length of each chunk.
|
||||
* @returns {Array} Returns the new array containing chunks.
|
||||
* @example
|
||||
*
|
||||
@@ -3143,15 +3143,15 @@
|
||||
* _.chunk(['a', 'b', 'c', 'd'], 3);
|
||||
* // => [['a', 'b', 'c'], ['d']]
|
||||
*/
|
||||
function chunk(array, chunkSize) {
|
||||
function chunk(array, size) {
|
||||
var index = 0,
|
||||
length = array ? array.length : 0,
|
||||
resIndex = -1,
|
||||
result = [];
|
||||
|
||||
chunkSize = nativeMax(+chunkSize || 1, 1);
|
||||
size = typeof size == 'undefined' ? 1 : nativeMax(+size || 1, 1);
|
||||
while (index < length) {
|
||||
result[++resIndex] = slice(array, index, (index += chunkSize));
|
||||
result[++resIndex] = slice(array, index, (index += size));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user