UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

38 lines (37 loc) 1.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.dropWhile = void 0; const baseWhile_1 = __importDefault(require("./.internal/baseWhile")); /** * Creates a slice of `array` excluding elements dropped from the beginning. * Elements are dropped until `predicate` returns falsey. The predicate is * invoked with three arguments: (value, index, array). * * @since 5.0.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': true }, * { 'user': 'fred', 'active': true }, * { 'user': 'pebbles', 'active': false } * ] * * dropWhile(users, ({ active }) => active) * // => objects for ['pebbles'] * ``` */ function dropWhile(array, predicate) { return (array != null && array.length) ? (0, baseWhile_1.default)(array, predicate, true) : []; } exports.dropWhile = dropWhile; exports.default = dropWhile;