Ohm-Management - Projektarbeit B-ME
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.

some.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var arraySome = require('./_arraySome'),
  2. baseIteratee = require('./_baseIteratee'),
  3. baseSome = require('./_baseSome'),
  4. isArray = require('./isArray'),
  5. isIterateeCall = require('./_isIterateeCall');
  6. /**
  7. * Checks if `predicate` returns truthy for **any** element of `collection`.
  8. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9. * invoked with three arguments: (value, index|key, collection).
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 0.1.0
  14. * @category Collection
  15. * @param {Array|Object} collection The collection to iterate over.
  16. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  17. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  18. * @returns {boolean} Returns `true` if any element passes the predicate check,
  19. * else `false`.
  20. * @example
  21. *
  22. * _.some([null, 0, 'yes', false], Boolean);
  23. * // => true
  24. *
  25. * var users = [
  26. * { 'user': 'barney', 'active': true },
  27. * { 'user': 'fred', 'active': false }
  28. * ];
  29. *
  30. * // The `_.matches` iteratee shorthand.
  31. * _.some(users, { 'user': 'barney', 'active': false });
  32. * // => false
  33. *
  34. * // The `_.matchesProperty` iteratee shorthand.
  35. * _.some(users, ['active', false]);
  36. * // => true
  37. *
  38. * // The `_.property` iteratee shorthand.
  39. * _.some(users, 'active');
  40. * // => true
  41. */
  42. function some(collection, predicate, guard) {
  43. var func = isArray(collection) ? arraySome : baseSome;
  44. if (guard && isIterateeCall(collection, predicate, guard)) {
  45. predicate = undefined;
  46. }
  47. return func(collection, baseIteratee(predicate, 3));
  48. }
  49. module.exports = some;