From c33d98ab2f99c348fa6e4d8339c34b4dcd49bb9a Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 18 Sep 2015 11:59:05 +0500 Subject: [PATCH] lodash: changed _.pullAt() method --- lodash/lodash-tests.ts | 24 +++++++++++++++++++++++- lodash/lodash.d.ts | 38 +++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index fc36241c5..0e274fd68 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -298,6 +298,29 @@ result = _([1, 2, 3]).last(); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); +// _.pullAt +{ + let testPullAtArray: TResult[]; + let testPullAtList: _.List; + let result: TResult[]; + result = _.pullAt(testPullAtArray); + result = _.pullAt(testPullAtArray, 1); + result = _.pullAt(testPullAtArray, [2, 3], 1); + result = _.pullAt(testPullAtArray, 4, [2, 3], 1); + result = _.pullAt(testPullAtList); + result = _.pullAt(testPullAtList, 1); + result = _.pullAt(testPullAtList, [2, 3], 1); + result = _.pullAt(testPullAtList, 4, [2, 3], 1); + result = _(testPullAtArray).pullAt().value(); + result = _(testPullAtArray).pullAt(1).value(); + result = _(testPullAtArray).pullAt([2, 3], 1).value(); + result = _(testPullAtArray).pullAt(4, [2, 3], 1).value(); + result = _(testPullAtList).pullAt().value(); + result = _(testPullAtList).pullAt(1).value(); + result = _(testPullAtList).pullAt([2, 3], 1).value(); + result = _(testPullAtList).pullAt(4, [2, 3], 1).value(); +} + result = <_.Dictionary>_.zipObject(['moe', 'larry'], [30, 40]); result = <_.LoDashObjectWrapper<_.Dictionary>>_(['moe', 'larry']).zipObject([30, 40]); result = <_.Dictionary>_.object(['moe', 'larry'], [30, 40]); @@ -308,7 +331,6 @@ result = <_.Dictionary>_.object([['moe', 30], ['larry', 40]]); result = <_.LoDashObjectWrapper<_.Dictionary>>_([['moe', 30], ['larry', 40]]).object(); result = _.pull([1, 2, 3, 1, 2, 3], 2, 3); -result = _.pullAt([1, 2, 3, 1, 2, 3], 2, 3); result = _.remove([1, 2, 3, 4, 5, 6], function (num: number) { return num % 2 == 0; }); result = _.remove(foodsOrganic, 'organic'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index db2405580..e9cd37ff4 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1104,24 +1104,36 @@ declare module _ { ...values: T[]): T[]; } + //_.pullAt interface LoDashStatic { /** - * Removes all provided values from the given array using strict equality for comparisons, - * i.e. ===. + * Removes elements from array corresponding to the given indexes and returns an array of the removed elements. + * Indexes may be specified as an array of indexes or as individual arguments. + * + * Note: Unlike _.at, this method mutates array. + * * @param array The array to modify. - * @param values The values to remove. - * @return array. - **/ - pullAt( - array: Array, - ...values: any[]): any[]; + * @param indexes The indexes of elements to remove, specified as individual indexes or arrays of indexes. + * @return Returns the new array of removed elements. + */ + pullAt( + array: T[]|List, + ...indexes: (number|number[])[] + ): T[]; + } + interface LoDashArrayWrapper { /** - * @see _.pull - **/ - pullAt( - array: List, - ...values: any[]): any[]; + * @see _.pullAt + */ + pullAt(...indexes: (number|number[])[]): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.pullAt + */ + pullAt(...indexes: (number|number[])[]): LoDashArrayWrapper; } //_.remove