mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Change default size of _.chunk to 0.
This commit is contained in:
20
lodash.js
20
lodash.js
@@ -4187,8 +4187,7 @@
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Array
|
* @category Array
|
||||||
* @param {Array} array The array to process.
|
* @param {Array} array The array to process.
|
||||||
* @param {number} [size=1] The length of each chunk.
|
* @param {number} [size=0] The length of each chunk.
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
|
|
||||||
* @returns {Array} Returns the new array containing chunks.
|
* @returns {Array} Returns the new array containing chunks.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -4198,11 +4197,10 @@
|
|||||||
* _.chunk(['a', 'b', 'c', 'd'], 3);
|
* _.chunk(['a', 'b', 'c', 'd'], 3);
|
||||||
* // => [['a', 'b', 'c'], ['d']]
|
* // => [['a', 'b', 'c'], ['d']]
|
||||||
*/
|
*/
|
||||||
function chunk(array, size, guard) {
|
function chunk(array, size) {
|
||||||
if (guard ? isIterateeCall(array, size, guard) : size == null) {
|
size = nativeMax(nativeFloor(size) || 0, 0);
|
||||||
size = 1;
|
if (size < 1) {
|
||||||
} else {
|
return [];
|
||||||
size = nativeMax(nativeFloor(size) || 1, 1);
|
|
||||||
}
|
}
|
||||||
var index = 0,
|
var index = 0,
|
||||||
length = array ? array.length : 0,
|
length = array ? array.length : 0,
|
||||||
@@ -6146,10 +6144,10 @@
|
|||||||
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
||||||
*
|
*
|
||||||
* The guarded methods are:
|
* The guarded methods are:
|
||||||
* `ary`, `callback`, `chunk`, `create`, `curry`, `curryRight`, `drop`,
|
* `ary`, `callback`, `create`, `curry`, `curryRight`, `drop`, `dropRight`,
|
||||||
* `dropRight`, `every`, `fill`, `invert`, `parseInt`, `random`, `range`,
|
* `every`, `fill`, `invert`, `parseInt`, `random`, `range`, `sample`,
|
||||||
* `sample`, `slice`, `some`, `sortBy`, `sumBy`, `take`, `takeRight`,
|
* `slice`, `some`, `sortBy`, `sumBy`, `take`, `takeRight`, `template`,
|
||||||
* `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, `uniqBy`, and `words`
|
* `trim`, `trimLeft`, `trimRight`, `trunc`, `uniqBy`, and `words`
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -1794,9 +1794,9 @@
|
|||||||
deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
|
deepEqual(actual, [[0, 1, 2, 3], [4, 5]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should ensure the minimum `chunkSize` is `1`', 1, function() {
|
test('should ensure the minimum `size` is `0`', 1, function() {
|
||||||
var values = falsey.concat(-1, -Infinity),
|
var values = falsey.concat(-1, -Infinity),
|
||||||
expected = _.map(values, _.constant([[0], [1], [2], [3], [4], [5]]));
|
expected = _.map(values, _.constant([]));
|
||||||
|
|
||||||
var actual = _.map(values, function(value, index) {
|
var actual = _.map(values, function(value, index) {
|
||||||
return index ? _.chunk(array, value) : _.chunk(array);
|
return index ? _.chunk(array, value) : _.chunk(array);
|
||||||
@@ -1808,11 +1808,6 @@
|
|||||||
test('should floor `size` values', 1, function() {
|
test('should floor `size` values', 1, function() {
|
||||||
deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
|
deepEqual(_.chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work as an iteratee for methods like `_.map`', 1, function() {
|
|
||||||
var actual = _.map([[1, 2], [3, 4]], _.chunk);
|
|
||||||
deepEqual(actual, [[[1], [2]], [[3], [4]]]);
|
|
||||||
});
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user