From 21572bf9a7a2c3691296f15767bd2933f9415479 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Mon, 5 Oct 2015 05:54:55 +0500 Subject: [PATCH] lodash: changed _.lastIndexOf() method --- lodash/lodash-tests.ts | 25 +++++++++++++++++++++-- lodash/lodash.d.ts | 46 ++++++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 1d5525300d..1e05faf552 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -348,8 +348,29 @@ result = _.indexOf([1, 1, 2, 2, 3, 3], 2, true); result = _.last([1, 2, 3]); result = _([1, 2, 3]).last(); -result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); -result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); +// _.lastIndexOf +module TestLastIndexOf { + let array: TResult[]; + let list: _.List; + let value: TResult; + let result: number; + + result = _.lastIndexOf(array, value); + result = _.lastIndexOf(array, value, true); + result = _.lastIndexOf(array, value, 42); + + result = _.lastIndexOf(list, value); + result = _.lastIndexOf(list, value, true); + result = _.lastIndexOf(list, value, 42); + + result = _(array).lastIndexOf(value); + result = _(array).lastIndexOf(value, true); + result = _(array).lastIndexOf(value, 42); + + result = _(list).lastIndexOf(value); + result = _(list).lastIndexOf(value, true); + result = _(list).lastIndexOf(value, 42); +} // _.pull { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 102811a169..15c8e971b2 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -889,26 +889,38 @@ declare module _ { //_.lastIndexOf interface LoDashStatic { /** - * Gets the index at which the last occurrence of value is found using strict equality - * for comparisons, i.e. ===. If fromIndex is negative, it is used as the offset from the - * end of the collection. - * @param array The array to search. - * @param value The value to search for. - * @param fromIndex The index to search from. - * @return The index of the matched value or -1. - **/ - lastIndexOf( - array: Array, - value: T, - fromIndex?: number): number; - - /** - * @see _.lastIndexOf - **/ + * This method is like _.indexOf except that it iterates over elements of array from right to left. + * + * @param array The array to search. + * @param value The value to search for. + * @param fromIndex The index to search from or true to perform a binary search on a sorted array. + * @return Returns the index of the matched value, else -1. + */ lastIndexOf( array: List, value: T, - fromIndex?: number): number; + fromIndex?: boolean|number + ): number; + } + + interface LoDashArrayWrapper { + /** + * @see _.lastIndexOf + */ + lastIndexOf( + value: T, + fromIndex?: boolean|number + ): number; + } + + interface LoDashObjectWrapper { + /** + * @see _.lastIndexOf + */ + lastIndexOf( + value: TResult, + fromIndex?: boolean|number + ): number; } //_.pull