wrapperReverse.js 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var LazyWrapper = require('./_LazyWrapper'),
  2. LodashWrapper = require('./_LodashWrapper'),
  3. reverse = require('./reverse'),
  4. thru = require('./thru');
  5. /**
  6. * This method is the wrapper version of `_.reverse`.
  7. *
  8. * **Note:** This method mutates the wrapped array.
  9. *
  10. * @name reverse
  11. * @memberOf _
  12. * @since 0.1.0
  13. * @category Seq
  14. * @returns {Object} Returns the new `lodash` wrapper instance.
  15. * @example
  16. *
  17. * var array = [1, 2, 3];
  18. *
  19. * _(array).reverse().value()
  20. * // => [3, 2, 1]
  21. *
  22. * console.log(array);
  23. * // => [3, 2, 1]
  24. */
  25. function wrapperReverse() {
  26. var value = this.__wrapped__;
  27. if (value instanceof LazyWrapper) {
  28. var wrapped = value;
  29. if (this.__actions__.length) {
  30. wrapped = new LazyWrapper(this);
  31. }
  32. wrapped = wrapped.reverse();
  33. wrapped.__actions__.push({
  34. 'func': thru,
  35. 'args': [reverse],
  36. 'thisArg': undefined
  37. });
  38. return new LodashWrapper(wrapped, this.__chain__);
  39. }
  40. return this.thru(reverse);
  41. }
  42. module.exports = wrapperReverse;