UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

39 lines (38 loc) 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.dropRightWhile = void 0; const baseWhile_1 = __importDefault(require("./.internal/baseWhile")); /** * Creates a slice of `array` excluding elements dropped from the end. * Elements are dropped until `predicate` returns falsey. The predicate is * invoked with three arguments: (value, index, array). * * @since 5.16.0 * @category Array * @param array The array to query. * @param predicate The function invoked per iteration. * @returns Returns the slice of `array`. * @example * * * ```js * const users = [ * { 'user': 'barney', 'active': false }, * { 'user': 'fred', 'active': true }, * { 'user': 'pebbles', 'active': true } * ] * * dropRightWhile(users, ({ active }) => active) * // => objects for ['barney'] * ``` */ function dropRightWhile(array, predicate) { return (array != null && array.length) ? (0, baseWhile_1.default)(array, predicate, true, true) : []; } exports.dropRightWhile = dropRightWhile; exports.default = dropRightWhile;