SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 22 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_baseSlice'], function(baseSlice) {
2015-12-16 17:49:07 -08:00
/**
2015-12-16 17:53:20 -08:00
* The base implementation of methods like `_.dropWhile` and `_.takeWhile`
* without support for iteratee shorthands.
2015-12-16 17:49:07 -08:00
*
* @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) {
var length = array.length,
index = fromRight ? length : -1;
2015-12-16 17:53:20 -08:00
while ((fromRight ? index-- : ++index < length) &&
predicate(array[index], index, array)) {}
2015-12-16 17:49:07 -08:00
return isDrop
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
}
return baseWhile;
});