mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Optimize _.chunk.
This commit is contained in:
@@ -3370,12 +3370,13 @@
|
|||||||
* // => [['a', 'b', 'c'], ['d']]
|
* // => [['a', 'b', 'c'], ['d']]
|
||||||
*/
|
*/
|
||||||
function chunk(array, size, guard) {
|
function chunk(array, size, guard) {
|
||||||
|
size = (guard || size == null) ? 1 : nativeMax(+size || 1, 1);
|
||||||
|
|
||||||
var index = 0,
|
var index = 0,
|
||||||
length = array ? array.length : 0,
|
length = array ? array.length : 0,
|
||||||
resIndex = -1,
|
resIndex = -1,
|
||||||
result = [];
|
result = Array(ceil(length / size));
|
||||||
|
|
||||||
size = (guard || size == null) ? 1 : nativeMax(+size || 1, 1);
|
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
result[++resIndex] = slice(array, index, (index += size));
|
result[++resIndex] = slice(array, index, (index += size));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user