Projekt

Obecné

Profil

Stáhnout (1.83 KB) Statistiky
| Větev: | Revize:
1
var arrayEvery = require('./_arrayEvery'),
2
    baseEvery = require('./_baseEvery'),
3
    baseIteratee = require('./_baseIteratee'),
4
    isArray = require('./isArray'),
5
    isIterateeCall = require('./_isIterateeCall');
6

    
7
/**
8
 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9
 * Iteration is stopped once `predicate` returns falsey. The predicate is
10
 * invoked with three arguments: (value, index|key, collection).
11
 *
12
 * **Note:** This method returns `true` for
13
 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
14
 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
15
 * elements of empty collections.
16
 *
17
 * @static
18
 * @memberOf _
19
 * @since 0.1.0
20
 * @category Collection
21
 * @param {Array|Object} collection The collection to iterate over.
22
 * @param {Function} [predicate=_.identity] The function invoked per iteration.
23
 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
24
 * @returns {boolean} Returns `true` if all elements pass the predicate check,
25
 *  else `false`.
26
 * @example
27
 *
28
 * _.every([true, 1, null, 'yes'], Boolean);
29
 * // => false
30
 *
31
 * var users = [
32
 *   { 'user': 'barney', 'age': 36, 'active': false },
33
 *   { 'user': 'fred',   'age': 40, 'active': false }
34
 * ];
35
 *
36
 * // The `_.matches` iteratee shorthand.
37
 * _.every(users, { 'user': 'barney', 'active': false });
38
 * // => false
39
 *
40
 * // The `_.matchesProperty` iteratee shorthand.
41
 * _.every(users, ['active', false]);
42
 * // => true
43
 *
44
 * // The `_.property` iteratee shorthand.
45
 * _.every(users, 'active');
46
 * // => false
47
 */
48
function every(collection, predicate, guard) {
49
  var func = isArray(collection) ? arrayEvery : baseEvery;
50
  if (guard && isIterateeCall(collection, predicate, guard)) {
51
    predicate = undefined;
52
  }
53
  return func(collection, baseIteratee(predicate, 3));
54
}
55

    
56
module.exports = every;
(320-320/590)