UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

37 lines (36 loc) 1.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortedLastIndexOf = void 0; const baseSortedIndex_1 = __importDefault(require("./.internal/baseSortedIndex")); const eq_1 = __importDefault(require("./eq")); /** * This method is like `lastIndexOf` except that it performs a binary * search on a sorted `array`. * * @since 5.11.0 * @category Array * @param array The array to inspect. * @param value The value to search for. * @returns Returns the index of the matched value, else `-1`. * @example * * ```js * sortedLastIndexOf([4, 5, 5, 5, 6], 5) * // => 3 * ``` */ function sortedLastIndexOf(array, value) { const length = array == null ? 0 : array.length; if (length) { const index = (0, baseSortedIndex_1.default)(array, value, true) - 1; if ((0, eq_1.default)(array[index], value)) { return index; } } return -1; } exports.sortedLastIndexOf = sortedLastIndexOf; exports.default = sortedLastIndexOf;