reverse.js 844 B

1234567891011121314151617181920212223242526272829303132333435
  1. /** Used for built-in method references. */
  2. var arrayProto = Array.prototype;
  3. /* Built-in method references for those with the same name as other `lodash` methods. */
  4. var nativeReverse = arrayProto.reverse;
  5. /**
  6. * Reverses `array` so that the first element becomes the last, the second
  7. * element becomes the second to last, and so on.
  8. *
  9. * **Note:** This method mutates `array` and is based on
  10. * [`Array#reverse`](https://mdn.io/Array/reverse).
  11. *
  12. * @static
  13. * @memberOf _
  14. * @since 4.0.0
  15. * @category Array
  16. * @param {Array} array The array to modify.
  17. * @returns {Array} Returns `array`.
  18. * @example
  19. *
  20. * var array = [1, 2, 3];
  21. *
  22. * _.reverse(array);
  23. * // => [3, 2, 1]
  24. *
  25. * console.log(array);
  26. * // => [3, 2, 1]
  27. */
  28. function reverse(array) {
  29. return array == null ? array : nativeReverse.call(array);
  30. }
  31. module.exports = reverse;