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.

dropRightWhile.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var baseIteratee = require('./_baseIteratee'),
  2. baseWhile = require('./_baseWhile');
  3. /**
  4. * Creates a slice of `array` excluding elements dropped from the end.
  5. * Elements are dropped until `predicate` returns falsey. The predicate is
  6. * invoked with three arguments: (value, index, array).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 3.0.0
  11. * @category Array
  12. * @param {Array} array The array to query.
  13. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  14. * @returns {Array} Returns the slice of `array`.
  15. * @example
  16. *
  17. * var users = [
  18. * { 'user': 'barney', 'active': true },
  19. * { 'user': 'fred', 'active': false },
  20. * { 'user': 'pebbles', 'active': false }
  21. * ];
  22. *
  23. * _.dropRightWhile(users, function(o) { return !o.active; });
  24. * // => objects for ['barney']
  25. *
  26. * // The `_.matches` iteratee shorthand.
  27. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  28. * // => objects for ['barney', 'fred']
  29. *
  30. * // The `_.matchesProperty` iteratee shorthand.
  31. * _.dropRightWhile(users, ['active', false]);
  32. * // => objects for ['barney']
  33. *
  34. * // The `_.property` iteratee shorthand.
  35. * _.dropRightWhile(users, 'active');
  36. * // => objects for ['barney', 'fred', 'pebbles']
  37. */
  38. function dropRightWhile(array, predicate) {
  39. return (array && array.length)
  40. ? baseWhile(array, baseIteratee(predicate, 3), true, true)
  41. : [];
  42. }
  43. module.exports = dropRightWhile;