@arrows/array
Version:
Functional tools for JS arrays
34 lines (33 loc) • 1.25 kB
TypeScript
declare type Curry1<T> = (arr: T[]) => number;
declare type Curry2<T> = {
(fromIndex: number): Curry1<T>;
(fromIndex: number, arr: T[]): number;
};
declare type Curry3 = {
<T>(element: T): Curry2<T>;
<T>(element: T, fromIndex: number): Curry1<T>;
};
declare type _LastIndexOf = <T>(element: T, fromIndex: number, arr: T[]) => number;
declare type CurriedLastIndexOf = _LastIndexOf & Curry3;
declare type _LastIndexOfAll = <T>(element: T, arr: T[]) => number;
declare type _LastIndexOfAll2 = <T>(element: T) => (arr: T[]) => number;
declare type LastIndexOfAll = _LastIndexOfAll & _LastIndexOfAll2;
declare type LastIndexOf = CurriedLastIndexOf & {
all: LastIndexOfAll;
};
/**
* Functional wrapper for Array.prototype.lastIndexOf
*
* Retrieves the index of the last occurrence of a specified value in an array.
* The array is searched backwards, starting at fromIndex.
*
* @param element The value to locate in the array
* @param fromIndex The array index at which to begin the search
* @param arr Initial array
* @returns Index of the matching element or -1
*
* @method all Version with implicit fromIndex (arr.length - 1)
*/
declare const lastIndexOf: LastIndexOf;
export { lastIndexOf };
export default lastIndexOf;