Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var LazyWrapper = require('../internal/LazyWrapper'),
2
LodashWrapper = require('../internal/LodashWrapper'),
3
thru = require('./thru');
4
5
/**
6
* Reverses the wrapped array so the first element becomes the last, the
7
* second element becomes the second to last, and so on.
8
*
9
* **Note:** This method mutates the wrapped array.
10
*
11
* @name reverse
12
* @memberOf _
13
* @category Chain
14
* @returns {Object} Returns the new reversed `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
if (this.__actions__.length) {
29
value = new LazyWrapper(this);
30
}
31
return new LodashWrapper(value.reverse(), this.__chain__);
32
}
33
return this.thru(function(value) {
34
return value.reverse();
35
});
36
}
37
38
module.exports = wrapperReverse;
39
40