Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / chain / wrapperReverse.js
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
28   var interceptor = function(value) {
29     return value.reverse();
30   };
31   if (value instanceof LazyWrapper) {
32     var wrapped = value;
33     if (this.__actions__.length) {
34       wrapped = new LazyWrapper(this);
35     }
36     wrapped = wrapped.reverse();
37     wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
38     return new LodashWrapper(wrapped, this.__chain__);
39   }
40   return this.thru(interceptor);
41 }
42
43 module.exports = wrapperReverse;