~webapps/unity-js-scopes/node.js

« back to all changes in this revision

Viewing changes to tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/internal/baseWhile.js

  • Committer: Marcus Tomlinson
  • Date: 2015-11-13 07:59:04 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20151113075904-h0swczmoq1rvstfc
Node v4 (stable)

Show diffs side-by-side

added added

removed removed

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