Split array to smaller arrays containing n elements at max
325771
function groupToElements(array, n) {
  var lists = _.groupBy(array, function(element, index){
    return Math.floor(index / n);
  });

  return _.toArray(lists);
}
961002
def split_seq(iterable, size):
    """"""
    elm = iter(iterable)
    item = list(itertools.islice(elm, size))
    while item:
        yield item
        item = list(itertools.islice(elm, size))
104788
private void select_sort_split(int p, int n) {
        int pa, pb, pi, pn;
        int f, v;

        pa = p; /* pa is start of group being picked out. */
        pn = p + n - 1; /* pn is last position of subarray. */
        while (pa < pn) {
            for (pi = pb = pa + 1, f = KEY(pa); pi <= pn; ++pi)
                if ((v = KEY(pi)) < f) {
                    f = v; /* f is smallest key found. */
                    SWAP(pi, pa); /* place smallest element at beginning. */
                    pb = pa + 1; /* pb is position for elements equal to f. */
                } else if (v == f) { /* if equal to smallest key. */
                    SWAP(pi, pb); /* place next to other smallest elements. */
                    ++pb;
                }
            update_group(pa, pb - 1); /* update group values for new group. */
            pa = pb; /* continue sorting rest of the subarray. */
        }
        if (pa == pn) { /* check if last part is single element. */
            V[start + I[pa]] = pa;
            I[pa] = -1; /* sorted group. */
        }
    }
575373
def _array(group_idx, a, size, fill_value, dtype=None):
    """"""
    if fill_value is not None and not (np.isscalar(fill_value) or
                                       len(fill_value) == 0):
        raise ValueError("fill_value must be None, a scalar or an empty "
                         "sequence")
    order_group_idx = np.argsort(group_idx, kind='mergesort')
    counts = np.bincount(group_idx, minlength=size)
    ret = np.split(a[order_group_idx], np.cumsum(counts)[:-1])
    ret = np.asanyarray(ret)
    if fill_value is None or np.isscalar(fill_value):
        _fill_untouched(group_idx, ret, fill_value)
    return ret
425756
function convertUint8ArraysToArrays(sources) {
  var targets = [];
  for (var n = 0; n < sources.length; n++) {
    var source = sources[n];
    var target = new Array(source.length);
    for (var i = 0; i < source.length; i++) {
      target[i] = source[i];
    }
    targets.push(target);
  }
  return targets;
}
229097
public static String[] splitToArray(String str, String separator, int limit, boolean isTrim, boolean ignoreEmpty){
		return toArray(split(str, separator, limit, isTrim, ignoreEmpty));
	}
97588
public function split(int $max): iterable
    {
        $pos = 0;
        $total = count($this->values);
        while ($pos < $total) {
            $clone = clone $this;
            $clone->values = array_slice($this->values, $pos, $max);
            $pos += $max;
            yield $clone;
        }
    }
995531
function arraySampleSize(array, n) {
      return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
    }
795187
def split(s):
  """"""
  l = [_split(x) for x in _SPLIT_RE.split(s)]
  return [item for sublist in l for item in sublist]
93358
def splitter(iterable, chunksize=60):
    """"""
    return (iterable[0+i:chunksize+i]
            for i in range(0, len(iterable), chunksize))
313515
def extend_array(edges, binsz, lo, hi):
    """"""

    numlo = int(np.ceil((edges[0] - lo) / binsz))
    numhi = int(np.ceil((hi - edges[-1]) / binsz))

    edges = copy.deepcopy(edges)
    if numlo > 0:
        edges_lo = np.linspace(edges[0] - numlo * binsz, edges[0], numlo + 1)
        edges = np.concatenate((edges_lo[:-1], edges))

    if numhi > 0:
        edges_hi = np.linspace(edges[-1], edges[-1] + numhi * binsz, numhi + 1)
        edges = np.concatenate((edges, edges_hi[1:]))

    return edges
1057838
def sort_and_distribute(array, splits=2):
   
   if not isinstance(array, (list,tuple)): raise TypeError("array must be a list")
   if not isinstance(splits, int): raise TypeError("splits must be an integer")
   remaining = sorted(array)
   if sys.version_info < (3, 0):
      myrange = xrange(splits)
   else:
      myrange = range(splits)
   groups = [[] for i in myrange]
   while len(remaining) > 0:
      for i in myrange:
         if len(remaining) > 0: groups[i].append(remaining.pop(0))
   return groups
606007
def split_into(max_num_chunks, list_to_chunk):
    
    max_chunk_size = math.ceil(len(list_to_chunk) / max_num_chunks)
    return chunks_of(max_chunk_size, list_to_chunk)
915525
def _heapify_max(x):
    """"""
    n = len(x)
    for i in reversed(range(n//2)):
        _siftup_max(x, i)
663872
def split(self, indices_or_sections, axis=0):
        """"""
        if not isinstance(indices_or_sections, numbers.Integral):
            raise Error('splitting by array of indices is not yet implemented')
        n = indices_or_sections
        if self.shape[axis] % n != 0:
            raise ValueError("Array split doesn't result in an equal division")
        step = self.shape[axis] / n
        pieces = []
        start = 0
        while start < self.shape[axis]:
            stop = start + step
            ix = [slice(None)] * self.ndim
            ix[axis] = slice(start, stop)
            ix = tuple(ix)
            pieces.append(self[ix])
            start += step
        return pieces
1279320
def chunked(l, n):
    """"""
    return [l[i:i + n] for i in range(0, len(l), n)]
861782
def split_input(cls, mapper_spec):
    """"""
    filelists = mapper_spec.params[cls.FILES_PARAM]
    max_values_count = mapper_spec.params.get(cls.MAX_VALUES_COUNT_PARAM, -1)
    max_values_size = mapper_spec.params.get(cls.MAX_VALUES_SIZE_PARAM, -1)
    return [cls([0] * len(files), max_values_count, max_values_size)
            for files in filelists]