@arrows/array
Version:
Functional tools for JS arrays
32 lines (31 loc) • 1.08 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.indexOf = void 0;
const curry_1 = require("@arrows/composition/curry");
const indexOfAll = (element, arr) => arr.indexOf(element);
const _indexOf = (element, fromIndex, arr) => arr.indexOf(element, fromIndex);
const curriedIndexOf = curry_1.default(_indexOf);
/**
* Functional wrapper for Array.prototype.indexOf
*
* Retrieves the index of the first occurrence of a value in an array.
*
* @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 (0).
*/
const indexOf = Object.assign(curriedIndexOf, {
/**
* Version with implicit fromIndex (0).
*
* @param element The value to locate in the array
* @param arr Initial array
* @returns Index of the matching element or -1
*/
all: curry_1.default(indexOfAll),
});
exports.indexOf = indexOf;
exports.default = indexOf;
;