選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

_baseWhile.js 933B

1234567891011121314151617181920212223242526
  1. var baseSlice = require('./_baseSlice');
  2. /**
  3. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  4. * without support for iteratee shorthands.
  5. *
  6. * @private
  7. * @param {Array} array The array to query.
  8. * @param {Function} predicate The function invoked per iteration.
  9. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  10. * @param {boolean} [fromRight] Specify iterating from right to left.
  11. * @returns {Array} Returns the slice of `array`.
  12. */
  13. function baseWhile(array, predicate, isDrop, fromRight) {
  14. var length = array.length,
  15. index = fromRight ? length : -1;
  16. while ((fromRight ? index-- : ++index < length) &&
  17. predicate(array[index], index, array)) {}
  18. return isDrop
  19. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  20. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  21. }
  22. module.exports = baseWhile;