@newdash/newdash
Version:
javascript/typescript utility library
27 lines (26 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 slice_1 = __importDefault(require("../slice"));
/**
* The base implementation of methods like `dropWhile` and `takeWhile`.
*
* @private
* @param {Array} array The array to query.
* @param {Function} predicate The function invoked per iteration.
* @param {boolean} [isDrop] Specify dropping elements instead of taking them.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Array} Returns the slice of `array`.
*/
function baseWhile(array, predicate, isDrop, fromRight) {
const { length } = array;
let index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length) &&
predicate(array[index], index, array)) { }
return isDrop
? (0, slice_1.default)(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
: (0, slice_1.default)(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
}
exports.default = baseWhile;