CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
chunk.js51 linesDownload Raw Back to lodash
1var baseSlice = require('./_baseSlice'),2    isIterateeCall = require('./_isIterateeCall'),3    toInteger = require('./toInteger');4 5/* Built-in method references for those with the same name as other `lodash` methods. */6var nativeCeil = Math.ceil,7    nativeMax = Math.max;8 9/**10 * Creates an array of elements split into groups the length of `size`.11 * If `array` can't be split evenly, the final chunk will be the remaining12 * elements.13 *14 * @static15 * @memberOf _16 * @since 3.0.017 * @category Array18 * @param {Array} array The array to process.19 * @param {number} [size=1] The length of each chunk20 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.21 * @returns {Array} Returns the new array of chunks.22 * @example23 *24 * _.chunk(['a', 'b', 'c', 'd'], 2);25 * // => [['a', 'b'], ['c', 'd']]26 *27 * _.chunk(['a', 'b', 'c', 'd'], 3);28 * // => [['a', 'b', 'c'], ['d']]29 */30function chunk(array, size, guard) {31  if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {32    size = 1;33  } else {34    size = nativeMax(toInteger(size), 0);35  }36  var length = array == null ? 0 : array.length;37  if (!length || size < 1) {38    return [];39  }40  var index = 0,41      resIndex = 0,42      result = Array(nativeCeil(length / size));43 44  while (index < length) {45    result[resIndex++] = baseSlice(array, index, (index += size));46  }47  return result;48}49 50module.exports = chunk;51 
basant307/AI_Governance_Project · CoolFace