Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 1x 1x 5x 5x 5x 5x 13x 7x 7x 13x 13x 5x 5x | import { purry } from './purry'; /** * Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements. * @param array the array * @param size the length of the chunk * @signature * R.chunk(array, size) * @example * R.chunk(['a', 'b', 'c', 'd'], 2) // => [['a', 'b'], ['c', 'd']] * R.chunk(['a', 'b', 'c', 'd'], 3) // => [['a', 'b', 'c'], ['d']] * @data_first * @category Array */ export function chunk<T>(array: T[], size: number): T[][]; /** * Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements. * @param size the length of the chunk * @signature * R.chunk(size)(array) * @example * R.chunk(2)(['a', 'b', 'c', 'd']) // => [['a', 'b'], ['c', 'd']] * R.chunk(3)(['a', 'b', 'c', 'd']) // => [['a', 'b', 'c'], ['d']] * @data_last * @category Array */ export function chunk<T>(size: number): (array: T[]) => T[][]; export function chunk() { return purry(_chunk, arguments); } function _chunk<T>(array: T[], size: number) { const ret: T[][] = []; let current: T[] | null = null; array.forEach(x => { if (!current) { current = []; ret.push(current); } current.push(x); if (current.length === size) { current = null; } }); return ret; } |