mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
933 B
27 lines
933 B
9 years ago
|
var baseSlice = require('./_baseSlice');
|
||
10 years ago
|
|
||
|
/**
|
||
9 years ago
|
* The base implementation of methods like `_.dropWhile` and `_.takeWhile`
|
||
|
* without support for iteratee shorthands.
|
||
10 years ago
|
*
|
||
|
* @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;
|
||
|
|
||
9 years ago
|
while ((fromRight ? index-- : ++index < length) &&
|
||
|
predicate(array[index], index, array)) {}
|
||
|
|
||
10 years ago
|
return isDrop
|
||
|
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
||
|
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
|
||
|
}
|
||
|
|
||
|
module.exports = baseWhile;
|