Merge pull request #4102 from peferron/master

lodash: add _.chunk
This commit is contained in:
Masahiro Wakame
2015-04-15 23:42:49 +09:00
2 changed files with 34 additions and 1 deletions
+9
View File
@@ -139,6 +139,15 @@ result = <_.Dictionary<string>>_(<{ [index: string]: string; }>{ 'key1': 'test1'
// /*************
// * Arrays *
// *************/
result = <any[][]>_.chunk([1, '2', '3', false]);
result = <_.LoDashArrayWrapper<any>>_([1, '2', '3', false]).chunk();
result = <any[][]>_.chunk([1, '2', '3', false], 2);
result = <_.LoDashArrayWrapper<any>>_([1, '2', '3', false]).chunk(2);
result = <number[][]>_.chunk([1, 2, 3, 4]);
result = <_.LoDashArrayWrapper<number>>_([1, 2, 3, 4]).chunk();
result = <number[][]>_.chunk([1, 2, 3, 4], 2);
result = <_.LoDashArrayWrapper<number>>_([1, 2, 3, 4]).chunk(2);
result = <any[]>_.compact([0, 1, false, 2, '', 3]);
result = <_.LoDashArrayWrapper<any>>_([0, 1, false, 2, '', 3]).compact();
+25 -1
View File
@@ -17,7 +17,7 @@ declare module _ {
* explicitly included in the build.
*
* The chainable wrapper functions are:
* after, assign, bind, bindAll, bindKey, chain, compact, compose, concat, countBy,
* after, assign, bind, bindAll, bindKey, chain, chunk, compact, compose, concat, countBy,
* createCallback, curry, debounce, defaults, defer, delay, difference, filter, flatten,
* forEach, forEachRight, forIn, forInRight, forOwn, forOwnRight, functions, groupBy,
* indexBy, initial, intersection, invert, invoke, keys, map, max, memoize, merge, min,
@@ -254,6 +254,30 @@ declare module _ {
/*********
* Arrays *
**********/
//_.chunk
interface LoDashStatic {
/**
* Creates an array of elements split into groups the length of size. If collection cant be
* split evenly, the final chunk will be the remaining elements.
* @param array The array to process.
* @param size The length of each chunk.
* @return Returns the new array containing chunks.
**/
chunk<T>(array: Array<T>, size?: number): T[][];
/**
* @see _.chunk
**/
chunk<T>(array: List<T>, size?: number): T[][];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.chunk
**/
chunk(size?: number): LoDashArrayWrapper<T>;
}
//_.compact
interface LoDashStatic {