@newdash/newdash
Version:
javascript/typescript utility library
34 lines (33 loc) • 1.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const baseWhile_1 = __importDefault(require("./.internal/baseWhile"));
/**
* Creates a slice of `array` with elements taken from the end. Elements are
* taken until `predicate` returns falsey. The predicate is invoked with
* three arguments: (value, index, array).
*
* @since 3.0.0
* @category Array
* @param {Array} array The array to query.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the slice of `array`.
* @example
*
* const users = [
* { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'active': true },
* { 'user': 'pebbles', 'active': true }
* ]
*
* takeRightWhile(users, ({ active }) => active)
* // => objects for ['fred', 'pebbles']
*/
function takeRightWhile(array, predicate) {
return (array != null && array.length)
? (0, baseWhile_1.default)(array, predicate, false, true)
: [];
}
exports.default = takeRightWhile;