@newdash/newdash
Version:
javascript/typescript utility library
34 lines (33 loc) • 1.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortedIndexBy = void 0;
const baseSortedIndexBy_1 = __importDefault(require("./.internal/baseSortedIndexBy"));
const getIteratee_1 = __importDefault(require("./.internal/getIteratee"));
/**
* This method is like `sortedIndex` except that it accepts `iteratee`
* which is invoked for `value` and each element of `array` to compute their
* sort ranking. The iteratee is invoked with one argument: (value).
*
* @since 5.11.0
* @category Array
* @param array The sorted array to inspect.
* @param value The value to evaluate.
* @param iteratee The iteratee invoked per element.
* @returns Returns the index at which `value` should be inserted into `array`.
* @example
*
* ```js
* const objects = [{ 'n': 4 }, { 'n': 5 }]
*
* sortedIndexBy(objects, { 'n': 4 }, ({ n }) => n)
* // => 0
* ```
*/
function sortedIndexBy(array, value, iteratee) {
return (0, baseSortedIndexBy_1.default)(array, value, (0, getIteratee_1.default)(iteratee, 2));
}
exports.sortedIndexBy = sortedIndexBy;
exports.default = sortedIndexBy;