Files
lodash/.internal/baseWhile.js
John-David Dalton e5e8f35c06 Remove baseSlice.
2017-04-17 21:06:27 -07:00

26 lines
862 B
JavaScript

import slice from '../slice.js'
/**
* 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
? slice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
: slice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index))
}
export default baseWhile