MCPcopy
hub / github.com/lodash/lodash / chunk

Function chunk

lodash.js:6934–6952  ·  view source on GitHub ↗

* Creates an array of elements split into groups the length of `size`. * If `array` can't be split evenly, the final chunk will be the remaining * elements. * * @static * @memberOf _ * @since 3.0.0 * @category Array * @param {Array} array The array to process.

(array, size, guard)

Source from the content-addressed store, hash-verified

6932 * // => [['a', 'b', 'c'], ['d']]
6933 */
6934 function chunk(array, size, guard) {
6935 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6936 size = 1;
6937 } else {
6938 size = nativeMax(toInteger(size), 0);
6939 }
6940 var length = array == null ? 0 : array.length;
6941 if (!length || size < 1) {
6942 return [];
6943 }
6944 var index = 0,
6945 resIndex = 0,
6946 result = Array(nativeCeil(length / size));
6947
6948 while (index < length) {
6949 result[resIndex++] = baseSlice(array, index, (index += size));
6950 }
6951 return result;
6952 }
6953
6954 /**
6955 * Creates an array with all falsey values removed. The values `false`, `null`,

Callers

nothing calls this directly

Calls 3

isIterateeCallFunction · 0.85
toIntegerFunction · 0.85
baseSliceFunction · 0.85

Tested by

no test coverage detected