function _chunk(array, size) { var index = 0, resIndex = 0, arrayLength = array.length, length = Math.ceil(arrayLength / size), result = Array(length) while (index < arrayLength) { result[resIndex++] = baseSlice(array, index, (index += size)) } return result } function baseSlice(array, start, end) { var length = array.length, end = end > length ? length : end, length = end - start >>> 0, result = Array(length), index = -1; start >>>= 0 while (++index < length) { result[index] = array[start + index] } return result } console.log(_chunk([1, 2, 5), 2)); / / [[1, 2], [5]]Copy the code

>>> essentially guarantees that the variable is meaningful (numeric), positive integer, and within a valid array range

0.1 >>> 0 Returns 0

1.2 >>> 0 Returns 1

-1 >>> 0 Returns 4294967295

Idea: Calculate the length of the resulting array and return it by dividing the array into size arrays using the baseSlice function. Then loop through the _chunk function to assign the new array and return it