From 474d691952462d02e82580182cee9f439df867de Mon Sep 17 00:00:00 2001 From: DomiR Date: Wed, 13 Jan 2016 22:29:32 +0100 Subject: [PATCH] (feature) Split _.indexOf & _.lastIndexOf into _.sortedIndexOf & _.sortedLastIndexOf --- lodash/lodash-tests.ts | 23 +++++++++++ lodash/lodash.d.ts | 90 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 104 insertions(+), 9 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 41b80f49c..983d73f21 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -858,6 +858,29 @@ module TestIndexOf { } } +// _.sortedIndexOf +module TestIndexOf { + let array: TResult[]; + let list: _.List; + let value: TResult; + + { + let result: number; + + result = _.sortedIndexOf(array, value); + result = _.sortedIndexOf(list, value); + result = _(array).sortedIndexOf(value); + result = _(list).sortedIndexOf(value); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(array).chain().sortedIndexOf(value); + result = _(list).chain().sortedIndexOf(value); + } +} + //_.initial module TestInitial { let array: TResult[]; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 793aaca1f..f4f34bfc7 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -28,8 +28,8 @@ TODO: - [x] Renamed _.trimLeft & _.trimRight to _.trimStart & _.trimEnd - [x] Renamed _.trunc to _.truncate -- [ ] Split _.indexOf & _.lastIndexOf into _.sortedIndexOf & _.sortedLastIndexOf -- [ ] Split _.max & _.min into _.maxBy & _.minBy +- [x] Split _.indexOf & _.lastIndexOf into _.sortedIndexOf & _.sortedLastIndexOf +- [x] Split _.max & _.min into _.maxBy & _.minBy - [ ] Split _.omit & _.pick into _.omitBy & _.pickBy - [ ] Split _.sample into _.sampleSize - [ ] Split _.sortedIndex into _.sortedIndexBy @@ -1382,14 +1382,27 @@ declare module _ { //_.indexOf interface LoDashStatic { /** - * Gets the index at which the first occurrence of value is found in array using SameValueZero for equality - * comparisons. If fromIndex is negative, it’s used as the offset from the end of array. If array is sorted - * providing true for fromIndex performs a faster binary search. + * Gets the index at which the first occurrence of `value` is found in `array` + * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it's used as the offset + * from the end of `array`. If `array` is sorted providing `true` for `fromIndex` + * performs a faster binary search. * - * @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 The index to search from or true to perform a binary search on a sorted array. + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to search. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.indexOf([1, 2, 1, 2], 2); + * // => 1 + * + * // using `fromIndex` + * _.indexOf([1, 2, 1, 2], 2, 2); + * // => 3 */ indexOf( array: List, @@ -1438,6 +1451,65 @@ declare module _ { ): LoDashExplicitWrapper; } + //_.sortedIndexOf + interface LoDashStatic { + /** + * This method is like `_.indexOf` except that it performs a binary + * search on a sorted `array`. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to search. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.sortedIndexOf([1, 1, 2, 2], 2); + * // => 2 + */ + sortedIndexOf( + array: List, + value: T + ): number; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.sortedIndexOf + */ + sortedIndexOf( + value: T + ): number; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.sortedIndexOf + */ + sortedIndexOf( + value: TValue + ): number; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sortedIndexOf + */ + sortedIndexOf( + value: T + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sortedIndexOf + */ + sortedIndexOf( + value: TValue + ): LoDashExplicitWrapper; + } + //_.initial interface LoDashStatic { /**