Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / index.js
1 /**
2  * @license
3  * lodash 3.10.1 (Custom Build) <https://lodash.com/>
4  * Build: `lodash modern -d -o ./index.js`
5  * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
6  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7  * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8  * Available under MIT license <https://lodash.com/license>
9  */
10 ;(function() {
11
12   /** Used as a safe reference for `undefined` in pre-ES5 environments. */
13   var undefined;
14
15   /** Used as the semantic version number. */
16   var VERSION = '3.10.1';
17
18   /** Used to compose bitmasks for wrapper metadata. */
19   var BIND_FLAG = 1,
20       BIND_KEY_FLAG = 2,
21       CURRY_BOUND_FLAG = 4,
22       CURRY_FLAG = 8,
23       CURRY_RIGHT_FLAG = 16,
24       PARTIAL_FLAG = 32,
25       PARTIAL_RIGHT_FLAG = 64,
26       ARY_FLAG = 128,
27       REARG_FLAG = 256;
28
29   /** Used as default options for `_.trunc`. */
30   var DEFAULT_TRUNC_LENGTH = 30,
31       DEFAULT_TRUNC_OMISSION = '...';
32
33   /** Used to detect when a function becomes hot. */
34   var HOT_COUNT = 150,
35       HOT_SPAN = 16;
36
37   /** Used as the size to enable large array optimizations. */
38   var LARGE_ARRAY_SIZE = 200;
39
40   /** Used to indicate the type of lazy iteratees. */
41   var LAZY_FILTER_FLAG = 1,
42       LAZY_MAP_FLAG = 2;
43
44   /** Used as the `TypeError` message for "Functions" methods. */
45   var FUNC_ERROR_TEXT = 'Expected a function';
46
47   /** Used as the internal argument placeholder. */
48   var PLACEHOLDER = '__lodash_placeholder__';
49
50   /** `Object#toString` result references. */
51   var argsTag = '[object Arguments]',
52       arrayTag = '[object Array]',
53       boolTag = '[object Boolean]',
54       dateTag = '[object Date]',
55       errorTag = '[object Error]',
56       funcTag = '[object Function]',
57       mapTag = '[object Map]',
58       numberTag = '[object Number]',
59       objectTag = '[object Object]',
60       regexpTag = '[object RegExp]',
61       setTag = '[object Set]',
62       stringTag = '[object String]',
63       weakMapTag = '[object WeakMap]';
64
65   var arrayBufferTag = '[object ArrayBuffer]',
66       float32Tag = '[object Float32Array]',
67       float64Tag = '[object Float64Array]',
68       int8Tag = '[object Int8Array]',
69       int16Tag = '[object Int16Array]',
70       int32Tag = '[object Int32Array]',
71       uint8Tag = '[object Uint8Array]',
72       uint8ClampedTag = '[object Uint8ClampedArray]',
73       uint16Tag = '[object Uint16Array]',
74       uint32Tag = '[object Uint32Array]';
75
76   /** Used to match empty string literals in compiled template source. */
77   var reEmptyStringLeading = /\b__p \+= '';/g,
78       reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
79       reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
80
81   /** Used to match HTML entities and HTML characters. */
82   var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
83       reUnescapedHtml = /[&<>"'`]/g,
84       reHasEscapedHtml = RegExp(reEscapedHtml.source),
85       reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
86
87   /** Used to match template delimiters. */
88   var reEscape = /<%-([\s\S]+?)%>/g,
89       reEvaluate = /<%([\s\S]+?)%>/g,
90       reInterpolate = /<%=([\s\S]+?)%>/g;
91
92   /** Used to match property names within property paths. */
93   var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
94       reIsPlainProp = /^\w*$/,
95       rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
96
97   /**
98    * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
99    * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
100    */
101   var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
102       reHasRegExpChars = RegExp(reRegExpChars.source);
103
104   /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
105   var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
106
107   /** Used to match backslashes in property paths. */
108   var reEscapeChar = /\\(\\)?/g;
109
110   /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
111   var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
112
113   /** Used to match `RegExp` flags from their coerced string values. */
114   var reFlags = /\w*$/;
115
116   /** Used to detect hexadecimal string values. */
117   var reHasHexPrefix = /^0[xX]/;
118
119   /** Used to detect host constructors (Safari > 5). */
120   var reIsHostCtor = /^\[object .+?Constructor\]$/;
121
122   /** Used to detect unsigned integer values. */
123   var reIsUint = /^\d+$/;
124
125   /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
126   var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
127
128   /** Used to ensure capturing order of template delimiters. */
129   var reNoMatch = /($^)/;
130
131   /** Used to match unescaped characters in compiled string literals. */
132   var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
133
134   /** Used to match words to create compound words. */
135   var reWords = (function() {
136     var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
137         lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
138
139     return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
140   }());
141
142   /** Used to assign default `context` object properties. */
143   var contextProps = [
144     'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
145     'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
146     'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
147     'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
148     'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
149   ];
150
151   /** Used to make template sourceURLs easier to identify. */
152   var templateCounter = -1;
153
154   /** Used to identify `toStringTag` values of typed arrays. */
155   var typedArrayTags = {};
156   typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
157   typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
158   typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
159   typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
160   typedArrayTags[uint32Tag] = true;
161   typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
162   typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
163   typedArrayTags[dateTag] = typedArrayTags[errorTag] =
164   typedArrayTags[funcTag] = typedArrayTags[mapTag] =
165   typedArrayTags[numberTag] = typedArrayTags[objectTag] =
166   typedArrayTags[regexpTag] = typedArrayTags[setTag] =
167   typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
168
169   /** Used to identify `toStringTag` values supported by `_.clone`. */
170   var cloneableTags = {};
171   cloneableTags[argsTag] = cloneableTags[arrayTag] =
172   cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
173   cloneableTags[dateTag] = cloneableTags[float32Tag] =
174   cloneableTags[float64Tag] = cloneableTags[int8Tag] =
175   cloneableTags[int16Tag] = cloneableTags[int32Tag] =
176   cloneableTags[numberTag] = cloneableTags[objectTag] =
177   cloneableTags[regexpTag] = cloneableTags[stringTag] =
178   cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
179   cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
180   cloneableTags[errorTag] = cloneableTags[funcTag] =
181   cloneableTags[mapTag] = cloneableTags[setTag] =
182   cloneableTags[weakMapTag] = false;
183
184   /** Used to map latin-1 supplementary letters to basic latin letters. */
185   var deburredLetters = {
186     '\xc0': 'A',  '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
187     '\xe0': 'a',  '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
188     '\xc7': 'C',  '\xe7': 'c',
189     '\xd0': 'D',  '\xf0': 'd',
190     '\xc8': 'E',  '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
191     '\xe8': 'e',  '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
192     '\xcC': 'I',  '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
193     '\xeC': 'i',  '\xed': 'i', '\xee': 'i', '\xef': 'i',
194     '\xd1': 'N',  '\xf1': 'n',
195     '\xd2': 'O',  '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
196     '\xf2': 'o',  '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
197     '\xd9': 'U',  '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
198     '\xf9': 'u',  '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
199     '\xdd': 'Y',  '\xfd': 'y', '\xff': 'y',
200     '\xc6': 'Ae', '\xe6': 'ae',
201     '\xde': 'Th', '\xfe': 'th',
202     '\xdf': 'ss'
203   };
204
205   /** Used to map characters to HTML entities. */
206   var htmlEscapes = {
207     '&': '&amp;',
208     '<': '&lt;',
209     '>': '&gt;',
210     '"': '&quot;',
211     "'": '&#39;',
212     '`': '&#96;'
213   };
214
215   /** Used to map HTML entities to characters. */
216   var htmlUnescapes = {
217     '&amp;': '&',
218     '&lt;': '<',
219     '&gt;': '>',
220     '&quot;': '"',
221     '&#39;': "'",
222     '&#96;': '`'
223   };
224
225   /** Used to determine if values are of the language type `Object`. */
226   var objectTypes = {
227     'function': true,
228     'object': true
229   };
230
231   /** Used to escape characters for inclusion in compiled regexes. */
232   var regexpEscapes = {
233     '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
234     '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
235     'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
236     'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
237     'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
238   };
239
240   /** Used to escape characters for inclusion in compiled string literals. */
241   var stringEscapes = {
242     '\\': '\\',
243     "'": "'",
244     '\n': 'n',
245     '\r': 'r',
246     '\u2028': 'u2028',
247     '\u2029': 'u2029'
248   };
249
250   /** Detect free variable `exports`. */
251   var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
252
253   /** Detect free variable `module`. */
254   var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
255
256   /** Detect free variable `global` from Node.js. */
257   var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
258
259   /** Detect free variable `self`. */
260   var freeSelf = objectTypes[typeof self] && self && self.Object && self;
261
262   /** Detect free variable `window`. */
263   var freeWindow = objectTypes[typeof window] && window && window.Object && window;
264
265   /** Detect the popular CommonJS extension `module.exports`. */
266   var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
267
268   /**
269    * Used as a reference to the global object.
270    *
271    * The `this` value is used if it's the global object to avoid Greasemonkey's
272    * restricted `window` object, otherwise the `window` object is used.
273    */
274   var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
275
276   /*--------------------------------------------------------------------------*/
277
278   /**
279    * The base implementation of `compareAscending` which compares values and
280    * sorts them in ascending order without guaranteeing a stable sort.
281    *
282    * @private
283    * @param {*} value The value to compare.
284    * @param {*} other The other value to compare.
285    * @returns {number} Returns the sort order indicator for `value`.
286    */
287   function baseCompareAscending(value, other) {
288     if (value !== other) {
289       var valIsNull = value === null,
290           valIsUndef = value === undefined,
291           valIsReflexive = value === value;
292
293       var othIsNull = other === null,
294           othIsUndef = other === undefined,
295           othIsReflexive = other === other;
296
297       if ((value > other && !othIsNull) || !valIsReflexive ||
298           (valIsNull && !othIsUndef && othIsReflexive) ||
299           (valIsUndef && othIsReflexive)) {
300         return 1;
301       }
302       if ((value < other && !valIsNull) || !othIsReflexive ||
303           (othIsNull && !valIsUndef && valIsReflexive) ||
304           (othIsUndef && valIsReflexive)) {
305         return -1;
306       }
307     }
308     return 0;
309   }
310
311   /**
312    * The base implementation of `_.findIndex` and `_.findLastIndex` without
313    * support for callback shorthands and `this` binding.
314    *
315    * @private
316    * @param {Array} array The array to search.
317    * @param {Function} predicate The function invoked per iteration.
318    * @param {boolean} [fromRight] Specify iterating from right to left.
319    * @returns {number} Returns the index of the matched value, else `-1`.
320    */
321   function baseFindIndex(array, predicate, fromRight) {
322     var length = array.length,
323         index = fromRight ? length : -1;
324
325     while ((fromRight ? index-- : ++index < length)) {
326       if (predicate(array[index], index, array)) {
327         return index;
328       }
329     }
330     return -1;
331   }
332
333   /**
334    * The base implementation of `_.indexOf` without support for binary searches.
335    *
336    * @private
337    * @param {Array} array The array to search.
338    * @param {*} value The value to search for.
339    * @param {number} fromIndex The index to search from.
340    * @returns {number} Returns the index of the matched value, else `-1`.
341    */
342   function baseIndexOf(array, value, fromIndex) {
343     if (value !== value) {
344       return indexOfNaN(array, fromIndex);
345     }
346     var index = fromIndex - 1,
347         length = array.length;
348
349     while (++index < length) {
350       if (array[index] === value) {
351         return index;
352       }
353     }
354     return -1;
355   }
356
357   /**
358    * The base implementation of `_.isFunction` without support for environments
359    * with incorrect `typeof` results.
360    *
361    * @private
362    * @param {*} value The value to check.
363    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
364    */
365   function baseIsFunction(value) {
366     // Avoid a Chakra JIT bug in compatibility modes of IE 11.
367     // See https://github.com/jashkenas/underscore/issues/1621 for more details.
368     return typeof value == 'function' || false;
369   }
370
371   /**
372    * Converts `value` to a string if it's not one. An empty string is returned
373    * for `null` or `undefined` values.
374    *
375    * @private
376    * @param {*} value The value to process.
377    * @returns {string} Returns the string.
378    */
379   function baseToString(value) {
380     return value == null ? '' : (value + '');
381   }
382
383   /**
384    * Used by `_.trim` and `_.trimLeft` to get the index of the first character
385    * of `string` that is not found in `chars`.
386    *
387    * @private
388    * @param {string} string The string to inspect.
389    * @param {string} chars The characters to find.
390    * @returns {number} Returns the index of the first character not found in `chars`.
391    */
392   function charsLeftIndex(string, chars) {
393     var index = -1,
394         length = string.length;
395
396     while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
397     return index;
398   }
399
400   /**
401    * Used by `_.trim` and `_.trimRight` to get the index of the last character
402    * of `string` that is not found in `chars`.
403    *
404    * @private
405    * @param {string} string The string to inspect.
406    * @param {string} chars The characters to find.
407    * @returns {number} Returns the index of the last character not found in `chars`.
408    */
409   function charsRightIndex(string, chars) {
410     var index = string.length;
411
412     while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
413     return index;
414   }
415
416   /**
417    * Used by `_.sortBy` to compare transformed elements of a collection and stable
418    * sort them in ascending order.
419    *
420    * @private
421    * @param {Object} object The object to compare.
422    * @param {Object} other The other object to compare.
423    * @returns {number} Returns the sort order indicator for `object`.
424    */
425   function compareAscending(object, other) {
426     return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
427   }
428
429   /**
430    * Used by `_.sortByOrder` to compare multiple properties of a value to another
431    * and stable sort them.
432    *
433    * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
434    * a value is sorted in ascending order if its corresponding order is "asc", and
435    * descending if "desc".
436    *
437    * @private
438    * @param {Object} object The object to compare.
439    * @param {Object} other The other object to compare.
440    * @param {boolean[]} orders The order to sort by for each property.
441    * @returns {number} Returns the sort order indicator for `object`.
442    */
443   function compareMultiple(object, other, orders) {
444     var index = -1,
445         objCriteria = object.criteria,
446         othCriteria = other.criteria,
447         length = objCriteria.length,
448         ordersLength = orders.length;
449
450     while (++index < length) {
451       var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
452       if (result) {
453         if (index >= ordersLength) {
454           return result;
455         }
456         var order = orders[index];
457         return result * ((order === 'asc' || order === true) ? 1 : -1);
458       }
459     }
460     // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
461     // that causes it, under certain circumstances, to provide the same value for
462     // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
463     // for more details.
464     //
465     // This also ensures a stable sort in V8 and other engines.
466     // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
467     return object.index - other.index;
468   }
469
470   /**
471    * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
472    *
473    * @private
474    * @param {string} letter The matched letter to deburr.
475    * @returns {string} Returns the deburred letter.
476    */
477   function deburrLetter(letter) {
478     return deburredLetters[letter];
479   }
480
481   /**
482    * Used by `_.escape` to convert characters to HTML entities.
483    *
484    * @private
485    * @param {string} chr The matched character to escape.
486    * @returns {string} Returns the escaped character.
487    */
488   function escapeHtmlChar(chr) {
489     return htmlEscapes[chr];
490   }
491
492   /**
493    * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
494    *
495    * @private
496    * @param {string} chr The matched character to escape.
497    * @param {string} leadingChar The capture group for a leading character.
498    * @param {string} whitespaceChar The capture group for a whitespace character.
499    * @returns {string} Returns the escaped character.
500    */
501   function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
502     if (leadingChar) {
503       chr = regexpEscapes[chr];
504     } else if (whitespaceChar) {
505       chr = stringEscapes[chr];
506     }
507     return '\\' + chr;
508   }
509
510   /**
511    * Used by `_.template` to escape characters for inclusion in compiled string literals.
512    *
513    * @private
514    * @param {string} chr The matched character to escape.
515    * @returns {string} Returns the escaped character.
516    */
517   function escapeStringChar(chr) {
518     return '\\' + stringEscapes[chr];
519   }
520
521   /**
522    * Gets the index at which the first occurrence of `NaN` is found in `array`.
523    *
524    * @private
525    * @param {Array} array The array to search.
526    * @param {number} fromIndex The index to search from.
527    * @param {boolean} [fromRight] Specify iterating from right to left.
528    * @returns {number} Returns the index of the matched `NaN`, else `-1`.
529    */
530   function indexOfNaN(array, fromIndex, fromRight) {
531     var length = array.length,
532         index = fromIndex + (fromRight ? 0 : -1);
533
534     while ((fromRight ? index-- : ++index < length)) {
535       var other = array[index];
536       if (other !== other) {
537         return index;
538       }
539     }
540     return -1;
541   }
542
543   /**
544    * Checks if `value` is object-like.
545    *
546    * @private
547    * @param {*} value The value to check.
548    * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
549    */
550   function isObjectLike(value) {
551     return !!value && typeof value == 'object';
552   }
553
554   /**
555    * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
556    * character code is whitespace.
557    *
558    * @private
559    * @param {number} charCode The character code to inspect.
560    * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
561    */
562   function isSpace(charCode) {
563     return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
564       (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
565   }
566
567   /**
568    * Replaces all `placeholder` elements in `array` with an internal placeholder
569    * and returns an array of their indexes.
570    *
571    * @private
572    * @param {Array} array The array to modify.
573    * @param {*} placeholder The placeholder to replace.
574    * @returns {Array} Returns the new array of placeholder indexes.
575    */
576   function replaceHolders(array, placeholder) {
577     var index = -1,
578         length = array.length,
579         resIndex = -1,
580         result = [];
581
582     while (++index < length) {
583       if (array[index] === placeholder) {
584         array[index] = PLACEHOLDER;
585         result[++resIndex] = index;
586       }
587     }
588     return result;
589   }
590
591   /**
592    * An implementation of `_.uniq` optimized for sorted arrays without support
593    * for callback shorthands and `this` binding.
594    *
595    * @private
596    * @param {Array} array The array to inspect.
597    * @param {Function} [iteratee] The function invoked per iteration.
598    * @returns {Array} Returns the new duplicate-value-free array.
599    */
600   function sortedUniq(array, iteratee) {
601     var seen,
602         index = -1,
603         length = array.length,
604         resIndex = -1,
605         result = [];
606
607     while (++index < length) {
608       var value = array[index],
609           computed = iteratee ? iteratee(value, index, array) : value;
610
611       if (!index || seen !== computed) {
612         seen = computed;
613         result[++resIndex] = value;
614       }
615     }
616     return result;
617   }
618
619   /**
620    * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
621    * character of `string`.
622    *
623    * @private
624    * @param {string} string The string to inspect.
625    * @returns {number} Returns the index of the first non-whitespace character.
626    */
627   function trimmedLeftIndex(string) {
628     var index = -1,
629         length = string.length;
630
631     while (++index < length && isSpace(string.charCodeAt(index))) {}
632     return index;
633   }
634
635   /**
636    * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
637    * character of `string`.
638    *
639    * @private
640    * @param {string} string The string to inspect.
641    * @returns {number} Returns the index of the last non-whitespace character.
642    */
643   function trimmedRightIndex(string) {
644     var index = string.length;
645
646     while (index-- && isSpace(string.charCodeAt(index))) {}
647     return index;
648   }
649
650   /**
651    * Used by `_.unescape` to convert HTML entities to characters.
652    *
653    * @private
654    * @param {string} chr The matched character to unescape.
655    * @returns {string} Returns the unescaped character.
656    */
657   function unescapeHtmlChar(chr) {
658     return htmlUnescapes[chr];
659   }
660
661   /*--------------------------------------------------------------------------*/
662
663   /**
664    * Create a new pristine `lodash` function using the given `context` object.
665    *
666    * @static
667    * @memberOf _
668    * @category Utility
669    * @param {Object} [context=root] The context object.
670    * @returns {Function} Returns a new `lodash` function.
671    * @example
672    *
673    * _.mixin({ 'foo': _.constant('foo') });
674    *
675    * var lodash = _.runInContext();
676    * lodash.mixin({ 'bar': lodash.constant('bar') });
677    *
678    * _.isFunction(_.foo);
679    * // => true
680    * _.isFunction(_.bar);
681    * // => false
682    *
683    * lodash.isFunction(lodash.foo);
684    * // => false
685    * lodash.isFunction(lodash.bar);
686    * // => true
687    *
688    * // using `context` to mock `Date#getTime` use in `_.now`
689    * var mock = _.runInContext({
690    *   'Date': function() {
691    *     return { 'getTime': getTimeMock };
692    *   }
693    * });
694    *
695    * // or creating a suped-up `defer` in Node.js
696    * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
697    */
698   function runInContext(context) {
699     // Avoid issues with some ES3 environments that attempt to use values, named
700     // after built-in constructors like `Object`, for the creation of literals.
701     // ES5 clears this up by stating that literals must use built-in constructors.
702     // See https://es5.github.io/#x11.1.5 for more details.
703     context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
704
705     /** Native constructor references. */
706     var Array = context.Array,
707         Date = context.Date,
708         Error = context.Error,
709         Function = context.Function,
710         Math = context.Math,
711         Number = context.Number,
712         Object = context.Object,
713         RegExp = context.RegExp,
714         String = context.String,
715         TypeError = context.TypeError;
716
717     /** Used for native method references. */
718     var arrayProto = Array.prototype,
719         objectProto = Object.prototype,
720         stringProto = String.prototype;
721
722     /** Used to resolve the decompiled source of functions. */
723     var fnToString = Function.prototype.toString;
724
725     /** Used to check objects for own properties. */
726     var hasOwnProperty = objectProto.hasOwnProperty;
727
728     /** Used to generate unique IDs. */
729     var idCounter = 0;
730
731     /**
732      * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
733      * of values.
734      */
735     var objToString = objectProto.toString;
736
737     /** Used to restore the original `_` reference in `_.noConflict`. */
738     var oldDash = root._;
739
740     /** Used to detect if a method is native. */
741     var reIsNative = RegExp('^' +
742       fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
743       .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
744     );
745
746     /** Native method references. */
747     var ArrayBuffer = context.ArrayBuffer,
748         clearTimeout = context.clearTimeout,
749         parseFloat = context.parseFloat,
750         pow = Math.pow,
751         propertyIsEnumerable = objectProto.propertyIsEnumerable,
752         Set = getNative(context, 'Set'),
753         setTimeout = context.setTimeout,
754         splice = arrayProto.splice,
755         Uint8Array = context.Uint8Array,
756         WeakMap = getNative(context, 'WeakMap');
757
758     /* Native method references for those with the same name as other `lodash` methods. */
759     var nativeCeil = Math.ceil,
760         nativeCreate = getNative(Object, 'create'),
761         nativeFloor = Math.floor,
762         nativeIsArray = getNative(Array, 'isArray'),
763         nativeIsFinite = context.isFinite,
764         nativeKeys = getNative(Object, 'keys'),
765         nativeMax = Math.max,
766         nativeMin = Math.min,
767         nativeNow = getNative(Date, 'now'),
768         nativeParseInt = context.parseInt,
769         nativeRandom = Math.random;
770
771     /** Used as references for `-Infinity` and `Infinity`. */
772     var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
773         POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
774
775     /** Used as references for the maximum length and index of an array. */
776     var MAX_ARRAY_LENGTH = 4294967295,
777         MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
778         HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
779
780     /**
781      * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
782      * of an array-like value.
783      */
784     var MAX_SAFE_INTEGER = 9007199254740991;
785
786     /** Used to store function metadata. */
787     var metaMap = WeakMap && new WeakMap;
788
789     /** Used to lookup unminified function names. */
790     var realNames = {};
791
792     /*------------------------------------------------------------------------*/
793
794     /**
795      * Creates a `lodash` object which wraps `value` to enable implicit chaining.
796      * Methods that operate on and return arrays, collections, and functions can
797      * be chained together. Methods that retrieve a single value or may return a
798      * primitive value will automatically end the chain returning the unwrapped
799      * value. Explicit chaining may be enabled using `_.chain`. The execution of
800      * chained methods is lazy, that is, execution is deferred until `_#value`
801      * is implicitly or explicitly called.
802      *
803      * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
804      * fusion is an optimization strategy which merge iteratee calls; this can help
805      * to avoid the creation of intermediate data structures and greatly reduce the
806      * number of iteratee executions.
807      *
808      * Chaining is supported in custom builds as long as the `_#value` method is
809      * directly or indirectly included in the build.
810      *
811      * In addition to lodash methods, wrappers have `Array` and `String` methods.
812      *
813      * The wrapper `Array` methods are:
814      * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
815      * `splice`, and `unshift`
816      *
817      * The wrapper `String` methods are:
818      * `replace` and `split`
819      *
820      * The wrapper methods that support shortcut fusion are:
821      * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
822      * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
823      * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
824      * and `where`
825      *
826      * The chainable wrapper methods are:
827      * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
828      * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
829      * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
830      * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
831      * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
832      * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
833      * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
834      * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
835      * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
836      * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
837      * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
838      * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
839      * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
840      * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
841      * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
842      * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
843      * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
844      *
845      * The wrapper methods that are **not** chainable by default are:
846      * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
847      * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
848      * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
849      * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
850      * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
851      * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
852      * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
853      * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
854      * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
855      * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
856      * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
857      * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
858      * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
859      * `unescape`, `uniqueId`, `value`, and `words`
860      *
861      * The wrapper method `sample` will return a wrapped value when `n` is provided,
862      * otherwise an unwrapped value is returned.
863      *
864      * @name _
865      * @constructor
866      * @category Chain
867      * @param {*} value The value to wrap in a `lodash` instance.
868      * @returns {Object} Returns the new `lodash` wrapper instance.
869      * @example
870      *
871      * var wrapped = _([1, 2, 3]);
872      *
873      * // returns an unwrapped value
874      * wrapped.reduce(function(total, n) {
875      *   return total + n;
876      * });
877      * // => 6
878      *
879      * // returns a wrapped value
880      * var squares = wrapped.map(function(n) {
881      *   return n * n;
882      * });
883      *
884      * _.isArray(squares);
885      * // => false
886      *
887      * _.isArray(squares.value());
888      * // => true
889      */
890     function lodash(value) {
891       if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
892         if (value instanceof LodashWrapper) {
893           return value;
894         }
895         if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
896           return wrapperClone(value);
897         }
898       }
899       return new LodashWrapper(value);
900     }
901
902     /**
903      * The function whose prototype all chaining wrappers inherit from.
904      *
905      * @private
906      */
907     function baseLodash() {
908       // No operation performed.
909     }
910
911     /**
912      * The base constructor for creating `lodash` wrapper objects.
913      *
914      * @private
915      * @param {*} value The value to wrap.
916      * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
917      * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
918      */
919     function LodashWrapper(value, chainAll, actions) {
920       this.__wrapped__ = value;
921       this.__actions__ = actions || [];
922       this.__chain__ = !!chainAll;
923     }
924
925     /**
926      * An object environment feature flags.
927      *
928      * @static
929      * @memberOf _
930      * @type Object
931      */
932     var support = lodash.support = {};
933
934     /**
935      * By default, the template delimiters used by lodash are like those in
936      * embedded Ruby (ERB). Change the following template settings to use
937      * alternative delimiters.
938      *
939      * @static
940      * @memberOf _
941      * @type Object
942      */
943     lodash.templateSettings = {
944
945       /**
946        * Used to detect `data` property values to be HTML-escaped.
947        *
948        * @memberOf _.templateSettings
949        * @type RegExp
950        */
951       'escape': reEscape,
952
953       /**
954        * Used to detect code to be evaluated.
955        *
956        * @memberOf _.templateSettings
957        * @type RegExp
958        */
959       'evaluate': reEvaluate,
960
961       /**
962        * Used to detect `data` property values to inject.
963        *
964        * @memberOf _.templateSettings
965        * @type RegExp
966        */
967       'interpolate': reInterpolate,
968
969       /**
970        * Used to reference the data object in the template text.
971        *
972        * @memberOf _.templateSettings
973        * @type string
974        */
975       'variable': '',
976
977       /**
978        * Used to import variables into the compiled template.
979        *
980        * @memberOf _.templateSettings
981        * @type Object
982        */
983       'imports': {
984
985         /**
986          * A reference to the `lodash` function.
987          *
988          * @memberOf _.templateSettings.imports
989          * @type Function
990          */
991         '_': lodash
992       }
993     };
994
995     /*------------------------------------------------------------------------*/
996
997     /**
998      * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
999      *
1000      * @private
1001      * @param {*} value The value to wrap.
1002      */
1003     function LazyWrapper(value) {
1004       this.__wrapped__ = value;
1005       this.__actions__ = [];
1006       this.__dir__ = 1;
1007       this.__filtered__ = false;
1008       this.__iteratees__ = [];
1009       this.__takeCount__ = POSITIVE_INFINITY;
1010       this.__views__ = [];
1011     }
1012
1013     /**
1014      * Creates a clone of the lazy wrapper object.
1015      *
1016      * @private
1017      * @name clone
1018      * @memberOf LazyWrapper
1019      * @returns {Object} Returns the cloned `LazyWrapper` object.
1020      */
1021     function lazyClone() {
1022       var result = new LazyWrapper(this.__wrapped__);
1023       result.__actions__ = arrayCopy(this.__actions__);
1024       result.__dir__ = this.__dir__;
1025       result.__filtered__ = this.__filtered__;
1026       result.__iteratees__ = arrayCopy(this.__iteratees__);
1027       result.__takeCount__ = this.__takeCount__;
1028       result.__views__ = arrayCopy(this.__views__);
1029       return result;
1030     }
1031
1032     /**
1033      * Reverses the direction of lazy iteration.
1034      *
1035      * @private
1036      * @name reverse
1037      * @memberOf LazyWrapper
1038      * @returns {Object} Returns the new reversed `LazyWrapper` object.
1039      */
1040     function lazyReverse() {
1041       if (this.__filtered__) {
1042         var result = new LazyWrapper(this);
1043         result.__dir__ = -1;
1044         result.__filtered__ = true;
1045       } else {
1046         result = this.clone();
1047         result.__dir__ *= -1;
1048       }
1049       return result;
1050     }
1051
1052     /**
1053      * Extracts the unwrapped value from its lazy wrapper.
1054      *
1055      * @private
1056      * @name value
1057      * @memberOf LazyWrapper
1058      * @returns {*} Returns the unwrapped value.
1059      */
1060     function lazyValue() {
1061       var array = this.__wrapped__.value(),
1062           dir = this.__dir__,
1063           isArr = isArray(array),
1064           isRight = dir < 0,
1065           arrLength = isArr ? array.length : 0,
1066           view = getView(0, arrLength, this.__views__),
1067           start = view.start,
1068           end = view.end,
1069           length = end - start,
1070           index = isRight ? end : (start - 1),
1071           iteratees = this.__iteratees__,
1072           iterLength = iteratees.length,
1073           resIndex = 0,
1074           takeCount = nativeMin(length, this.__takeCount__);
1075
1076       if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
1077         return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
1078       }
1079       var result = [];
1080
1081       outer:
1082       while (length-- && resIndex < takeCount) {
1083         index += dir;
1084
1085         var iterIndex = -1,
1086             value = array[index];
1087
1088         while (++iterIndex < iterLength) {
1089           var data = iteratees[iterIndex],
1090               iteratee = data.iteratee,
1091               type = data.type,
1092               computed = iteratee(value);
1093
1094           if (type == LAZY_MAP_FLAG) {
1095             value = computed;
1096           } else if (!computed) {
1097             if (type == LAZY_FILTER_FLAG) {
1098               continue outer;
1099             } else {
1100               break outer;
1101             }
1102           }
1103         }
1104         result[resIndex++] = value;
1105       }
1106       return result;
1107     }
1108
1109     /*------------------------------------------------------------------------*/
1110
1111     /**
1112      * Creates a cache object to store key/value pairs.
1113      *
1114      * @private
1115      * @static
1116      * @name Cache
1117      * @memberOf _.memoize
1118      */
1119     function MapCache() {
1120       this.__data__ = {};
1121     }
1122
1123     /**
1124      * Removes `key` and its value from the cache.
1125      *
1126      * @private
1127      * @name delete
1128      * @memberOf _.memoize.Cache
1129      * @param {string} key The key of the value to remove.
1130      * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
1131      */
1132     function mapDelete(key) {
1133       return this.has(key) && delete this.__data__[key];
1134     }
1135
1136     /**
1137      * Gets the cached value for `key`.
1138      *
1139      * @private
1140      * @name get
1141      * @memberOf _.memoize.Cache
1142      * @param {string} key The key of the value to get.
1143      * @returns {*} Returns the cached value.
1144      */
1145     function mapGet(key) {
1146       return key == '__proto__' ? undefined : this.__data__[key];
1147     }
1148
1149     /**
1150      * Checks if a cached value for `key` exists.
1151      *
1152      * @private
1153      * @name has
1154      * @memberOf _.memoize.Cache
1155      * @param {string} key The key of the entry to check.
1156      * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1157      */
1158     function mapHas(key) {
1159       return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
1160     }
1161
1162     /**
1163      * Sets `value` to `key` of the cache.
1164      *
1165      * @private
1166      * @name set
1167      * @memberOf _.memoize.Cache
1168      * @param {string} key The key of the value to cache.
1169      * @param {*} value The value to cache.
1170      * @returns {Object} Returns the cache object.
1171      */
1172     function mapSet(key, value) {
1173       if (key != '__proto__') {
1174         this.__data__[key] = value;
1175       }
1176       return this;
1177     }
1178
1179     /*------------------------------------------------------------------------*/
1180
1181     /**
1182      *
1183      * Creates a cache object to store unique values.
1184      *
1185      * @private
1186      * @param {Array} [values] The values to cache.
1187      */
1188     function SetCache(values) {
1189       var length = values ? values.length : 0;
1190
1191       this.data = { 'hash': nativeCreate(null), 'set': new Set };
1192       while (length--) {
1193         this.push(values[length]);
1194       }
1195     }
1196
1197     /**
1198      * Checks if `value` is in `cache` mimicking the return signature of
1199      * `_.indexOf` by returning `0` if the value is found, else `-1`.
1200      *
1201      * @private
1202      * @param {Object} cache The cache to search.
1203      * @param {*} value The value to search for.
1204      * @returns {number} Returns `0` if `value` is found, else `-1`.
1205      */
1206     function cacheIndexOf(cache, value) {
1207       var data = cache.data,
1208           result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
1209
1210       return result ? 0 : -1;
1211     }
1212
1213     /**
1214      * Adds `value` to the cache.
1215      *
1216      * @private
1217      * @name push
1218      * @memberOf SetCache
1219      * @param {*} value The value to cache.
1220      */
1221     function cachePush(value) {
1222       var data = this.data;
1223       if (typeof value == 'string' || isObject(value)) {
1224         data.set.add(value);
1225       } else {
1226         data.hash[value] = true;
1227       }
1228     }
1229
1230     /*------------------------------------------------------------------------*/
1231
1232     /**
1233      * Creates a new array joining `array` with `other`.
1234      *
1235      * @private
1236      * @param {Array} array The array to join.
1237      * @param {Array} other The other array to join.
1238      * @returns {Array} Returns the new concatenated array.
1239      */
1240     function arrayConcat(array, other) {
1241       var index = -1,
1242           length = array.length,
1243           othIndex = -1,
1244           othLength = other.length,
1245           result = Array(length + othLength);
1246
1247       while (++index < length) {
1248         result[index] = array[index];
1249       }
1250       while (++othIndex < othLength) {
1251         result[index++] = other[othIndex];
1252       }
1253       return result;
1254     }
1255
1256     /**
1257      * Copies the values of `source` to `array`.
1258      *
1259      * @private
1260      * @param {Array} source The array to copy values from.
1261      * @param {Array} [array=[]] The array to copy values to.
1262      * @returns {Array} Returns `array`.
1263      */
1264     function arrayCopy(source, array) {
1265       var index = -1,
1266           length = source.length;
1267
1268       array || (array = Array(length));
1269       while (++index < length) {
1270         array[index] = source[index];
1271       }
1272       return array;
1273     }
1274
1275     /**
1276      * A specialized version of `_.forEach` for arrays without support for callback
1277      * shorthands and `this` binding.
1278      *
1279      * @private
1280      * @param {Array} array The array to iterate over.
1281      * @param {Function} iteratee The function invoked per iteration.
1282      * @returns {Array} Returns `array`.
1283      */
1284     function arrayEach(array, iteratee) {
1285       var index = -1,
1286           length = array.length;
1287
1288       while (++index < length) {
1289         if (iteratee(array[index], index, array) === false) {
1290           break;
1291         }
1292       }
1293       return array;
1294     }
1295
1296     /**
1297      * A specialized version of `_.forEachRight` for arrays without support for
1298      * callback shorthands and `this` binding.
1299      *
1300      * @private
1301      * @param {Array} array The array to iterate over.
1302      * @param {Function} iteratee The function invoked per iteration.
1303      * @returns {Array} Returns `array`.
1304      */
1305     function arrayEachRight(array, iteratee) {
1306       var length = array.length;
1307
1308       while (length--) {
1309         if (iteratee(array[length], length, array) === false) {
1310           break;
1311         }
1312       }
1313       return array;
1314     }
1315
1316     /**
1317      * A specialized version of `_.every` for arrays without support for callback
1318      * shorthands and `this` binding.
1319      *
1320      * @private
1321      * @param {Array} array The array to iterate over.
1322      * @param {Function} predicate The function invoked per iteration.
1323      * @returns {boolean} Returns `true` if all elements pass the predicate check,
1324      *  else `false`.
1325      */
1326     function arrayEvery(array, predicate) {
1327       var index = -1,
1328           length = array.length;
1329
1330       while (++index < length) {
1331         if (!predicate(array[index], index, array)) {
1332           return false;
1333         }
1334       }
1335       return true;
1336     }
1337
1338     /**
1339      * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
1340      * with one argument: (value).
1341      *
1342      * @private
1343      * @param {Array} array The array to iterate over.
1344      * @param {Function} iteratee The function invoked per iteration.
1345      * @param {Function} comparator The function used to compare values.
1346      * @param {*} exValue The initial extremum value.
1347      * @returns {*} Returns the extremum value.
1348      */
1349     function arrayExtremum(array, iteratee, comparator, exValue) {
1350       var index = -1,
1351           length = array.length,
1352           computed = exValue,
1353           result = computed;
1354
1355       while (++index < length) {
1356         var value = array[index],
1357             current = +iteratee(value);
1358
1359         if (comparator(current, computed)) {
1360           computed = current;
1361           result = value;
1362         }
1363       }
1364       return result;
1365     }
1366
1367     /**
1368      * A specialized version of `_.filter` for arrays without support for callback
1369      * shorthands and `this` binding.
1370      *
1371      * @private
1372      * @param {Array} array The array to iterate over.
1373      * @param {Function} predicate The function invoked per iteration.
1374      * @returns {Array} Returns the new filtered array.
1375      */
1376     function arrayFilter(array, predicate) {
1377       var index = -1,
1378           length = array.length,
1379           resIndex = -1,
1380           result = [];
1381
1382       while (++index < length) {
1383         var value = array[index];
1384         if (predicate(value, index, array)) {
1385           result[++resIndex] = value;
1386         }
1387       }
1388       return result;
1389     }
1390
1391     /**
1392      * A specialized version of `_.map` for arrays without support for callback
1393      * shorthands and `this` binding.
1394      *
1395      * @private
1396      * @param {Array} array The array to iterate over.
1397      * @param {Function} iteratee The function invoked per iteration.
1398      * @returns {Array} Returns the new mapped array.
1399      */
1400     function arrayMap(array, iteratee) {
1401       var index = -1,
1402           length = array.length,
1403           result = Array(length);
1404
1405       while (++index < length) {
1406         result[index] = iteratee(array[index], index, array);
1407       }
1408       return result;
1409     }
1410
1411     /**
1412      * Appends the elements of `values` to `array`.
1413      *
1414      * @private
1415      * @param {Array} array The array to modify.
1416      * @param {Array} values The values to append.
1417      * @returns {Array} Returns `array`.
1418      */
1419     function arrayPush(array, values) {
1420       var index = -1,
1421           length = values.length,
1422           offset = array.length;
1423
1424       while (++index < length) {
1425         array[offset + index] = values[index];
1426       }
1427       return array;
1428     }
1429
1430     /**
1431      * A specialized version of `_.reduce` for arrays without support for callback
1432      * shorthands and `this` binding.
1433      *
1434      * @private
1435      * @param {Array} array The array to iterate over.
1436      * @param {Function} iteratee The function invoked per iteration.
1437      * @param {*} [accumulator] The initial value.
1438      * @param {boolean} [initFromArray] Specify using the first element of `array`
1439      *  as the initial value.
1440      * @returns {*} Returns the accumulated value.
1441      */
1442     function arrayReduce(array, iteratee, accumulator, initFromArray) {
1443       var index = -1,
1444           length = array.length;
1445
1446       if (initFromArray && length) {
1447         accumulator = array[++index];
1448       }
1449       while (++index < length) {
1450         accumulator = iteratee(accumulator, array[index], index, array);
1451       }
1452       return accumulator;
1453     }
1454
1455     /**
1456      * A specialized version of `_.reduceRight` for arrays without support for
1457      * callback shorthands and `this` binding.
1458      *
1459      * @private
1460      * @param {Array} array The array to iterate over.
1461      * @param {Function} iteratee The function invoked per iteration.
1462      * @param {*} [accumulator] The initial value.
1463      * @param {boolean} [initFromArray] Specify using the last element of `array`
1464      *  as the initial value.
1465      * @returns {*} Returns the accumulated value.
1466      */
1467     function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
1468       var length = array.length;
1469       if (initFromArray && length) {
1470         accumulator = array[--length];
1471       }
1472       while (length--) {
1473         accumulator = iteratee(accumulator, array[length], length, array);
1474       }
1475       return accumulator;
1476     }
1477
1478     /**
1479      * A specialized version of `_.some` for arrays without support for callback
1480      * shorthands and `this` binding.
1481      *
1482      * @private
1483      * @param {Array} array The array to iterate over.
1484      * @param {Function} predicate The function invoked per iteration.
1485      * @returns {boolean} Returns `true` if any element passes the predicate check,
1486      *  else `false`.
1487      */
1488     function arraySome(array, predicate) {
1489       var index = -1,
1490           length = array.length;
1491
1492       while (++index < length) {
1493         if (predicate(array[index], index, array)) {
1494           return true;
1495         }
1496       }
1497       return false;
1498     }
1499
1500     /**
1501      * A specialized version of `_.sum` for arrays without support for callback
1502      * shorthands and `this` binding..
1503      *
1504      * @private
1505      * @param {Array} array The array to iterate over.
1506      * @param {Function} iteratee The function invoked per iteration.
1507      * @returns {number} Returns the sum.
1508      */
1509     function arraySum(array, iteratee) {
1510       var length = array.length,
1511           result = 0;
1512
1513       while (length--) {
1514         result += +iteratee(array[length]) || 0;
1515       }
1516       return result;
1517     }
1518
1519     /**
1520      * Used by `_.defaults` to customize its `_.assign` use.
1521      *
1522      * @private
1523      * @param {*} objectValue The destination object property value.
1524      * @param {*} sourceValue The source object property value.
1525      * @returns {*} Returns the value to assign to the destination object.
1526      */
1527     function assignDefaults(objectValue, sourceValue) {
1528       return objectValue === undefined ? sourceValue : objectValue;
1529     }
1530
1531     /**
1532      * Used by `_.template` to customize its `_.assign` use.
1533      *
1534      * **Note:** This function is like `assignDefaults` except that it ignores
1535      * inherited property values when checking if a property is `undefined`.
1536      *
1537      * @private
1538      * @param {*} objectValue The destination object property value.
1539      * @param {*} sourceValue The source object property value.
1540      * @param {string} key The key associated with the object and source values.
1541      * @param {Object} object The destination object.
1542      * @returns {*} Returns the value to assign to the destination object.
1543      */
1544     function assignOwnDefaults(objectValue, sourceValue, key, object) {
1545       return (objectValue === undefined || !hasOwnProperty.call(object, key))
1546         ? sourceValue
1547         : objectValue;
1548     }
1549
1550     /**
1551      * A specialized version of `_.assign` for customizing assigned values without
1552      * support for argument juggling, multiple sources, and `this` binding `customizer`
1553      * functions.
1554      *
1555      * @private
1556      * @param {Object} object The destination object.
1557      * @param {Object} source The source object.
1558      * @param {Function} customizer The function to customize assigned values.
1559      * @returns {Object} Returns `object`.
1560      */
1561     function assignWith(object, source, customizer) {
1562       var index = -1,
1563           props = keys(source),
1564           length = props.length;
1565
1566       while (++index < length) {
1567         var key = props[index],
1568             value = object[key],
1569             result = customizer(value, source[key], key, object, source);
1570
1571         if ((result === result ? (result !== value) : (value === value)) ||
1572             (value === undefined && !(key in object))) {
1573           object[key] = result;
1574         }
1575       }
1576       return object;
1577     }
1578
1579     /**
1580      * The base implementation of `_.assign` without support for argument juggling,
1581      * multiple sources, and `customizer` functions.
1582      *
1583      * @private
1584      * @param {Object} object The destination object.
1585      * @param {Object} source The source object.
1586      * @returns {Object} Returns `object`.
1587      */
1588     function baseAssign(object, source) {
1589       return source == null
1590         ? object
1591         : baseCopy(source, keys(source), object);
1592     }
1593
1594     /**
1595      * The base implementation of `_.at` without support for string collections
1596      * and individual key arguments.
1597      *
1598      * @private
1599      * @param {Array|Object} collection The collection to iterate over.
1600      * @param {number[]|string[]} props The property names or indexes of elements to pick.
1601      * @returns {Array} Returns the new array of picked elements.
1602      */
1603     function baseAt(collection, props) {
1604       var index = -1,
1605           isNil = collection == null,
1606           isArr = !isNil && isArrayLike(collection),
1607           length = isArr ? collection.length : 0,
1608           propsLength = props.length,
1609           result = Array(propsLength);
1610
1611       while(++index < propsLength) {
1612         var key = props[index];
1613         if (isArr) {
1614           result[index] = isIndex(key, length) ? collection[key] : undefined;
1615         } else {
1616           result[index] = isNil ? undefined : collection[key];
1617         }
1618       }
1619       return result;
1620     }
1621
1622     /**
1623      * Copies properties of `source` to `object`.
1624      *
1625      * @private
1626      * @param {Object} source The object to copy properties from.
1627      * @param {Array} props The property names to copy.
1628      * @param {Object} [object={}] The object to copy properties to.
1629      * @returns {Object} Returns `object`.
1630      */
1631     function baseCopy(source, props, object) {
1632       object || (object = {});
1633
1634       var index = -1,
1635           length = props.length;
1636
1637       while (++index < length) {
1638         var key = props[index];
1639         object[key] = source[key];
1640       }
1641       return object;
1642     }
1643
1644     /**
1645      * The base implementation of `_.callback` which supports specifying the
1646      * number of arguments to provide to `func`.
1647      *
1648      * @private
1649      * @param {*} [func=_.identity] The value to convert to a callback.
1650      * @param {*} [thisArg] The `this` binding of `func`.
1651      * @param {number} [argCount] The number of arguments to provide to `func`.
1652      * @returns {Function} Returns the callback.
1653      */
1654     function baseCallback(func, thisArg, argCount) {
1655       var type = typeof func;
1656       if (type == 'function') {
1657         return thisArg === undefined
1658           ? func
1659           : bindCallback(func, thisArg, argCount);
1660       }
1661       if (func == null) {
1662         return identity;
1663       }
1664       if (type == 'object') {
1665         return baseMatches(func);
1666       }
1667       return thisArg === undefined
1668         ? property(func)
1669         : baseMatchesProperty(func, thisArg);
1670     }
1671
1672     /**
1673      * The base implementation of `_.clone` without support for argument juggling
1674      * and `this` binding `customizer` functions.
1675      *
1676      * @private
1677      * @param {*} value The value to clone.
1678      * @param {boolean} [isDeep] Specify a deep clone.
1679      * @param {Function} [customizer] The function to customize cloning values.
1680      * @param {string} [key] The key of `value`.
1681      * @param {Object} [object] The object `value` belongs to.
1682      * @param {Array} [stackA=[]] Tracks traversed source objects.
1683      * @param {Array} [stackB=[]] Associates clones with source counterparts.
1684      * @returns {*} Returns the cloned value.
1685      */
1686     function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
1687       var result;
1688       if (customizer) {
1689         result = object ? customizer(value, key, object) : customizer(value);
1690       }
1691       if (result !== undefined) {
1692         return result;
1693       }
1694       if (!isObject(value)) {
1695         return value;
1696       }
1697       var isArr = isArray(value);
1698       if (isArr) {
1699         result = initCloneArray(value);
1700         if (!isDeep) {
1701           return arrayCopy(value, result);
1702         }
1703       } else {
1704         var tag = objToString.call(value),
1705             isFunc = tag == funcTag;
1706
1707         if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
1708           result = initCloneObject(isFunc ? {} : value);
1709           if (!isDeep) {
1710             return baseAssign(result, value);
1711           }
1712         } else {
1713           return cloneableTags[tag]
1714             ? initCloneByTag(value, tag, isDeep)
1715             : (object ? value : {});
1716         }
1717       }
1718       // Check for circular references and return its corresponding clone.
1719       stackA || (stackA = []);
1720       stackB || (stackB = []);
1721
1722       var length = stackA.length;
1723       while (length--) {
1724         if (stackA[length] == value) {
1725           return stackB[length];
1726         }
1727       }
1728       // Add the source value to the stack of traversed objects and associate it with its clone.
1729       stackA.push(value);
1730       stackB.push(result);
1731
1732       // Recursively populate clone (susceptible to call stack limits).
1733       (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
1734         result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
1735       });
1736       return result;
1737     }
1738
1739     /**
1740      * The base implementation of `_.create` without support for assigning
1741      * properties to the created object.
1742      *
1743      * @private
1744      * @param {Object} prototype The object to inherit from.
1745      * @returns {Object} Returns the new object.
1746      */
1747     var baseCreate = (function() {
1748       function object() {}
1749       return function(prototype) {
1750         if (isObject(prototype)) {
1751           object.prototype = prototype;
1752           var result = new object;
1753           object.prototype = undefined;
1754         }
1755         return result || {};
1756       };
1757     }());
1758
1759     /**
1760      * The base implementation of `_.delay` and `_.defer` which accepts an index
1761      * of where to slice the arguments to provide to `func`.
1762      *
1763      * @private
1764      * @param {Function} func The function to delay.
1765      * @param {number} wait The number of milliseconds to delay invocation.
1766      * @param {Object} args The arguments provide to `func`.
1767      * @returns {number} Returns the timer id.
1768      */
1769     function baseDelay(func, wait, args) {
1770       if (typeof func != 'function') {
1771         throw new TypeError(FUNC_ERROR_TEXT);
1772       }
1773       return setTimeout(function() { func.apply(undefined, args); }, wait);
1774     }
1775
1776     /**
1777      * The base implementation of `_.difference` which accepts a single array
1778      * of values to exclude.
1779      *
1780      * @private
1781      * @param {Array} array The array to inspect.
1782      * @param {Array} values The values to exclude.
1783      * @returns {Array} Returns the new array of filtered values.
1784      */
1785     function baseDifference(array, values) {
1786       var length = array ? array.length : 0,
1787           result = [];
1788
1789       if (!length) {
1790         return result;
1791       }
1792       var index = -1,
1793           indexOf = getIndexOf(),
1794           isCommon = indexOf == baseIndexOf,
1795           cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
1796           valuesLength = values.length;
1797
1798       if (cache) {
1799         indexOf = cacheIndexOf;
1800         isCommon = false;
1801         values = cache;
1802       }
1803       outer:
1804       while (++index < length) {
1805         var value = array[index];
1806
1807         if (isCommon && value === value) {
1808           var valuesIndex = valuesLength;
1809           while (valuesIndex--) {
1810             if (values[valuesIndex] === value) {
1811               continue outer;
1812             }
1813           }
1814           result.push(value);
1815         }
1816         else if (indexOf(values, value, 0) < 0) {
1817           result.push(value);
1818         }
1819       }
1820       return result;
1821     }
1822
1823     /**
1824      * The base implementation of `_.forEach` without support for callback
1825      * shorthands and `this` binding.
1826      *
1827      * @private
1828      * @param {Array|Object|string} collection The collection to iterate over.
1829      * @param {Function} iteratee The function invoked per iteration.
1830      * @returns {Array|Object|string} Returns `collection`.
1831      */
1832     var baseEach = createBaseEach(baseForOwn);
1833
1834     /**
1835      * The base implementation of `_.forEachRight` without support for callback
1836      * shorthands and `this` binding.
1837      *
1838      * @private
1839      * @param {Array|Object|string} collection The collection to iterate over.
1840      * @param {Function} iteratee The function invoked per iteration.
1841      * @returns {Array|Object|string} Returns `collection`.
1842      */
1843     var baseEachRight = createBaseEach(baseForOwnRight, true);
1844
1845     /**
1846      * The base implementation of `_.every` without support for callback
1847      * shorthands and `this` binding.
1848      *
1849      * @private
1850      * @param {Array|Object|string} collection The collection to iterate over.
1851      * @param {Function} predicate The function invoked per iteration.
1852      * @returns {boolean} Returns `true` if all elements pass the predicate check,
1853      *  else `false`
1854      */
1855     function baseEvery(collection, predicate) {
1856       var result = true;
1857       baseEach(collection, function(value, index, collection) {
1858         result = !!predicate(value, index, collection);
1859         return result;
1860       });
1861       return result;
1862     }
1863
1864     /**
1865      * Gets the extremum value of `collection` invoking `iteratee` for each value
1866      * in `collection` to generate the criterion by which the value is ranked.
1867      * The `iteratee` is invoked with three arguments: (value, index|key, collection).
1868      *
1869      * @private
1870      * @param {Array|Object|string} collection The collection to iterate over.
1871      * @param {Function} iteratee The function invoked per iteration.
1872      * @param {Function} comparator The function used to compare values.
1873      * @param {*} exValue The initial extremum value.
1874      * @returns {*} Returns the extremum value.
1875      */
1876     function baseExtremum(collection, iteratee, comparator, exValue) {
1877       var computed = exValue,
1878           result = computed;
1879
1880       baseEach(collection, function(value, index, collection) {
1881         var current = +iteratee(value, index, collection);
1882         if (comparator(current, computed) || (current === exValue && current === result)) {
1883           computed = current;
1884           result = value;
1885         }
1886       });
1887       return result;
1888     }
1889
1890     /**
1891      * The base implementation of `_.fill` without an iteratee call guard.
1892      *
1893      * @private
1894      * @param {Array} array The array to fill.
1895      * @param {*} value The value to fill `array` with.
1896      * @param {number} [start=0] The start position.
1897      * @param {number} [end=array.length] The end position.
1898      * @returns {Array} Returns `array`.
1899      */
1900     function baseFill(array, value, start, end) {
1901       var length = array.length;
1902
1903       start = start == null ? 0 : (+start || 0);
1904       if (start < 0) {
1905         start = -start > length ? 0 : (length + start);
1906       }
1907       end = (end === undefined || end > length) ? length : (+end || 0);
1908       if (end < 0) {
1909         end += length;
1910       }
1911       length = start > end ? 0 : (end >>> 0);
1912       start >>>= 0;
1913
1914       while (start < length) {
1915         array[start++] = value;
1916       }
1917       return array;
1918     }
1919
1920     /**
1921      * The base implementation of `_.filter` without support for callback
1922      * shorthands and `this` binding.
1923      *
1924      * @private
1925      * @param {Array|Object|string} collection The collection to iterate over.
1926      * @param {Function} predicate The function invoked per iteration.
1927      * @returns {Array} Returns the new filtered array.
1928      */
1929     function baseFilter(collection, predicate) {
1930       var result = [];
1931       baseEach(collection, function(value, index, collection) {
1932         if (predicate(value, index, collection)) {
1933           result.push(value);
1934         }
1935       });
1936       return result;
1937     }
1938
1939     /**
1940      * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
1941      * without support for callback shorthands and `this` binding, which iterates
1942      * over `collection` using the provided `eachFunc`.
1943      *
1944      * @private
1945      * @param {Array|Object|string} collection The collection to search.
1946      * @param {Function} predicate The function invoked per iteration.
1947      * @param {Function} eachFunc The function to iterate over `collection`.
1948      * @param {boolean} [retKey] Specify returning the key of the found element
1949      *  instead of the element itself.
1950      * @returns {*} Returns the found element or its key, else `undefined`.
1951      */
1952     function baseFind(collection, predicate, eachFunc, retKey) {
1953       var result;
1954       eachFunc(collection, function(value, key, collection) {
1955         if (predicate(value, key, collection)) {
1956           result = retKey ? key : value;
1957           return false;
1958         }
1959       });
1960       return result;
1961     }
1962
1963     /**
1964      * The base implementation of `_.flatten` with added support for restricting
1965      * flattening and specifying the start index.
1966      *
1967      * @private
1968      * @param {Array} array The array to flatten.
1969      * @param {boolean} [isDeep] Specify a deep flatten.
1970      * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
1971      * @param {Array} [result=[]] The initial result value.
1972      * @returns {Array} Returns the new flattened array.
1973      */
1974     function baseFlatten(array, isDeep, isStrict, result) {
1975       result || (result = []);
1976
1977       var index = -1,
1978           length = array.length;
1979
1980       while (++index < length) {
1981         var value = array[index];
1982         if (isObjectLike(value) && isArrayLike(value) &&
1983             (isStrict || isArray(value) || isArguments(value))) {
1984           if (isDeep) {
1985             // Recursively flatten arrays (susceptible to call stack limits).
1986             baseFlatten(value, isDeep, isStrict, result);
1987           } else {
1988             arrayPush(result, value);
1989           }
1990         } else if (!isStrict) {
1991           result[result.length] = value;
1992         }
1993       }
1994       return result;
1995     }
1996
1997     /**
1998      * The base implementation of `baseForIn` and `baseForOwn` which iterates
1999      * over `object` properties returned by `keysFunc` invoking `iteratee` for
2000      * each property. Iteratee functions may exit iteration early by explicitly
2001      * returning `false`.
2002      *
2003      * @private
2004      * @param {Object} object The object to iterate over.
2005      * @param {Function} iteratee The function invoked per iteration.
2006      * @param {Function} keysFunc The function to get the keys of `object`.
2007      * @returns {Object} Returns `object`.
2008      */
2009     var baseFor = createBaseFor();
2010
2011     /**
2012      * This function is like `baseFor` except that it iterates over properties
2013      * in the opposite order.
2014      *
2015      * @private
2016      * @param {Object} object The object to iterate over.
2017      * @param {Function} iteratee The function invoked per iteration.
2018      * @param {Function} keysFunc The function to get the keys of `object`.
2019      * @returns {Object} Returns `object`.
2020      */
2021     var baseForRight = createBaseFor(true);
2022
2023     /**
2024      * The base implementation of `_.forIn` without support for callback
2025      * shorthands and `this` binding.
2026      *
2027      * @private
2028      * @param {Object} object The object to iterate over.
2029      * @param {Function} iteratee The function invoked per iteration.
2030      * @returns {Object} Returns `object`.
2031      */
2032     function baseForIn(object, iteratee) {
2033       return baseFor(object, iteratee, keysIn);
2034     }
2035
2036     /**
2037      * The base implementation of `_.forOwn` without support for callback
2038      * shorthands and `this` binding.
2039      *
2040      * @private
2041      * @param {Object} object The object to iterate over.
2042      * @param {Function} iteratee The function invoked per iteration.
2043      * @returns {Object} Returns `object`.
2044      */
2045     function baseForOwn(object, iteratee) {
2046       return baseFor(object, iteratee, keys);
2047     }
2048
2049     /**
2050      * The base implementation of `_.forOwnRight` without support for callback
2051      * shorthands and `this` binding.
2052      *
2053      * @private
2054      * @param {Object} object The object to iterate over.
2055      * @param {Function} iteratee The function invoked per iteration.
2056      * @returns {Object} Returns `object`.
2057      */
2058     function baseForOwnRight(object, iteratee) {
2059       return baseForRight(object, iteratee, keys);
2060     }
2061
2062     /**
2063      * The base implementation of `_.functions` which creates an array of
2064      * `object` function property names filtered from those provided.
2065      *
2066      * @private
2067      * @param {Object} object The object to inspect.
2068      * @param {Array} props The property names to filter.
2069      * @returns {Array} Returns the new array of filtered property names.
2070      */
2071     function baseFunctions(object, props) {
2072       var index = -1,
2073           length = props.length,
2074           resIndex = -1,
2075           result = [];
2076
2077       while (++index < length) {
2078         var key = props[index];
2079         if (isFunction(object[key])) {
2080           result[++resIndex] = key;
2081         }
2082       }
2083       return result;
2084     }
2085
2086     /**
2087      * The base implementation of `get` without support for string paths
2088      * and default values.
2089      *
2090      * @private
2091      * @param {Object} object The object to query.
2092      * @param {Array} path The path of the property to get.
2093      * @param {string} [pathKey] The key representation of path.
2094      * @returns {*} Returns the resolved value.
2095      */
2096     function baseGet(object, path, pathKey) {
2097       if (object == null) {
2098         return;
2099       }
2100       if (pathKey !== undefined && pathKey in toObject(object)) {
2101         path = [pathKey];
2102       }
2103       var index = 0,
2104           length = path.length;
2105
2106       while (object != null && index < length) {
2107         object = object[path[index++]];
2108       }
2109       return (index && index == length) ? object : undefined;
2110     }
2111
2112     /**
2113      * The base implementation of `_.isEqual` without support for `this` binding
2114      * `customizer` functions.
2115      *
2116      * @private
2117      * @param {*} value The value to compare.
2118      * @param {*} other The other value to compare.
2119      * @param {Function} [customizer] The function to customize comparing values.
2120      * @param {boolean} [isLoose] Specify performing partial comparisons.
2121      * @param {Array} [stackA] Tracks traversed `value` objects.
2122      * @param {Array} [stackB] Tracks traversed `other` objects.
2123      * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2124      */
2125     function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
2126       if (value === other) {
2127         return true;
2128       }
2129       if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2130         return value !== value && other !== other;
2131       }
2132       return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
2133     }
2134
2135     /**
2136      * A specialized version of `baseIsEqual` for arrays and objects which performs
2137      * deep comparisons and tracks traversed objects enabling objects with circular
2138      * references to be compared.
2139      *
2140      * @private
2141      * @param {Object} object The object to compare.
2142      * @param {Object} other The other object to compare.
2143      * @param {Function} equalFunc The function to determine equivalents of values.
2144      * @param {Function} [customizer] The function to customize comparing objects.
2145      * @param {boolean} [isLoose] Specify performing partial comparisons.
2146      * @param {Array} [stackA=[]] Tracks traversed `value` objects.
2147      * @param {Array} [stackB=[]] Tracks traversed `other` objects.
2148      * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2149      */
2150     function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
2151       var objIsArr = isArray(object),
2152           othIsArr = isArray(other),
2153           objTag = arrayTag,
2154           othTag = arrayTag;
2155
2156       if (!objIsArr) {
2157         objTag = objToString.call(object);
2158         if (objTag == argsTag) {
2159           objTag = objectTag;
2160         } else if (objTag != objectTag) {
2161           objIsArr = isTypedArray(object);
2162         }
2163       }
2164       if (!othIsArr) {
2165         othTag = objToString.call(other);
2166         if (othTag == argsTag) {
2167           othTag = objectTag;
2168         } else if (othTag != objectTag) {
2169           othIsArr = isTypedArray(other);
2170         }
2171       }
2172       var objIsObj = objTag == objectTag,
2173           othIsObj = othTag == objectTag,
2174           isSameTag = objTag == othTag;
2175
2176       if (isSameTag && !(objIsArr || objIsObj)) {
2177         return equalByTag(object, other, objTag);
2178       }
2179       if (!isLoose) {
2180         var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2181             othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2182
2183         if (objIsWrapped || othIsWrapped) {
2184           return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
2185         }
2186       }
2187       if (!isSameTag) {
2188         return false;
2189       }
2190       // Assume cyclic values are equal.
2191       // For more information on detecting circular references see https://es5.github.io/#JO.
2192       stackA || (stackA = []);
2193       stackB || (stackB = []);
2194
2195       var length = stackA.length;
2196       while (length--) {
2197         if (stackA[length] == object) {
2198           return stackB[length] == other;
2199         }
2200       }
2201       // Add `object` and `other` to the stack of traversed objects.
2202       stackA.push(object);
2203       stackB.push(other);
2204
2205       var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
2206
2207       stackA.pop();
2208       stackB.pop();
2209
2210       return result;
2211     }
2212
2213     /**
2214      * The base implementation of `_.isMatch` without support for callback
2215      * shorthands and `this` binding.
2216      *
2217      * @private
2218      * @param {Object} object The object to inspect.
2219      * @param {Array} matchData The propery names, values, and compare flags to match.
2220      * @param {Function} [customizer] The function to customize comparing objects.
2221      * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2222      */
2223     function baseIsMatch(object, matchData, customizer) {
2224       var index = matchData.length,
2225           length = index,
2226           noCustomizer = !customizer;
2227
2228       if (object == null) {
2229         return !length;
2230       }
2231       object = toObject(object);
2232       while (index--) {
2233         var data = matchData[index];
2234         if ((noCustomizer && data[2])
2235               ? data[1] !== object[data[0]]
2236               : !(data[0] in object)
2237             ) {
2238           return false;
2239         }
2240       }
2241       while (++index < length) {
2242         data = matchData[index];
2243         var key = data[0],
2244             objValue = object[key],
2245             srcValue = data[1];
2246
2247         if (noCustomizer && data[2]) {
2248           if (objValue === undefined && !(key in object)) {
2249             return false;
2250           }
2251         } else {
2252           var result = customizer ? customizer(objValue, srcValue, key) : undefined;
2253           if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
2254             return false;
2255           }
2256         }
2257       }
2258       return true;
2259     }
2260
2261     /**
2262      * The base implementation of `_.map` without support for callback shorthands
2263      * and `this` binding.
2264      *
2265      * @private
2266      * @param {Array|Object|string} collection The collection to iterate over.
2267      * @param {Function} iteratee The function invoked per iteration.
2268      * @returns {Array} Returns the new mapped array.
2269      */
2270     function baseMap(collection, iteratee) {
2271       var index = -1,
2272           result = isArrayLike(collection) ? Array(collection.length) : [];
2273
2274       baseEach(collection, function(value, key, collection) {
2275         result[++index] = iteratee(value, key, collection);
2276       });
2277       return result;
2278     }
2279
2280     /**
2281      * The base implementation of `_.matches` which does not clone `source`.
2282      *
2283      * @private
2284      * @param {Object} source The object of property values to match.
2285      * @returns {Function} Returns the new function.
2286      */
2287     function baseMatches(source) {
2288       var matchData = getMatchData(source);
2289       if (matchData.length == 1 && matchData[0][2]) {
2290         var key = matchData[0][0],
2291             value = matchData[0][1];
2292
2293         return function(object) {
2294           if (object == null) {
2295             return false;
2296           }
2297           return object[key] === value && (value !== undefined || (key in toObject(object)));
2298         };
2299       }
2300       return function(object) {
2301         return baseIsMatch(object, matchData);
2302       };
2303     }
2304
2305     /**
2306      * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
2307      *
2308      * @private
2309      * @param {string} path The path of the property to get.
2310      * @param {*} srcValue The value to compare.
2311      * @returns {Function} Returns the new function.
2312      */
2313     function baseMatchesProperty(path, srcValue) {
2314       var isArr = isArray(path),
2315           isCommon = isKey(path) && isStrictComparable(srcValue),
2316           pathKey = (path + '');
2317
2318       path = toPath(path);
2319       return function(object) {
2320         if (object == null) {
2321           return false;
2322         }
2323         var key = pathKey;
2324         object = toObject(object);
2325         if ((isArr || !isCommon) && !(key in object)) {
2326           object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
2327           if (object == null) {
2328             return false;
2329           }
2330           key = last(path);
2331           object = toObject(object);
2332         }
2333         return object[key] === srcValue
2334           ? (srcValue !== undefined || (key in object))
2335           : baseIsEqual(srcValue, object[key], undefined, true);
2336       };
2337     }
2338
2339     /**
2340      * The base implementation of `_.merge` without support for argument juggling,
2341      * multiple sources, and `this` binding `customizer` functions.
2342      *
2343      * @private
2344      * @param {Object} object The destination object.
2345      * @param {Object} source The source object.
2346      * @param {Function} [customizer] The function to customize merged values.
2347      * @param {Array} [stackA=[]] Tracks traversed source objects.
2348      * @param {Array} [stackB=[]] Associates values with source counterparts.
2349      * @returns {Object} Returns `object`.
2350      */
2351     function baseMerge(object, source, customizer, stackA, stackB) {
2352       if (!isObject(object)) {
2353         return object;
2354       }
2355       var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
2356           props = isSrcArr ? undefined : keys(source);
2357
2358       arrayEach(props || source, function(srcValue, key) {
2359         if (props) {
2360           key = srcValue;
2361           srcValue = source[key];
2362         }
2363         if (isObjectLike(srcValue)) {
2364           stackA || (stackA = []);
2365           stackB || (stackB = []);
2366           baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
2367         }
2368         else {
2369           var value = object[key],
2370               result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2371               isCommon = result === undefined;
2372
2373           if (isCommon) {
2374             result = srcValue;
2375           }
2376           if ((result !== undefined || (isSrcArr && !(key in object))) &&
2377               (isCommon || (result === result ? (result !== value) : (value === value)))) {
2378             object[key] = result;
2379           }
2380         }
2381       });
2382       return object;
2383     }
2384
2385     /**
2386      * A specialized version of `baseMerge` for arrays and objects which performs
2387      * deep merges and tracks traversed objects enabling objects with circular
2388      * references to be merged.
2389      *
2390      * @private
2391      * @param {Object} object The destination object.
2392      * @param {Object} source The source object.
2393      * @param {string} key The key of the value to merge.
2394      * @param {Function} mergeFunc The function to merge values.
2395      * @param {Function} [customizer] The function to customize merged values.
2396      * @param {Array} [stackA=[]] Tracks traversed source objects.
2397      * @param {Array} [stackB=[]] Associates values with source counterparts.
2398      * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2399      */
2400     function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
2401       var length = stackA.length,
2402           srcValue = source[key];
2403
2404       while (length--) {
2405         if (stackA[length] == srcValue) {
2406           object[key] = stackB[length];
2407           return;
2408         }
2409       }
2410       var value = object[key],
2411           result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2412           isCommon = result === undefined;
2413
2414       if (isCommon) {
2415         result = srcValue;
2416         if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
2417           result = isArray(value)
2418             ? value
2419             : (isArrayLike(value) ? arrayCopy(value) : []);
2420         }
2421         else if (isPlainObject(srcValue) || isArguments(srcValue)) {
2422           result = isArguments(value)
2423             ? toPlainObject(value)
2424             : (isPlainObject(value) ? value : {});
2425         }
2426         else {
2427           isCommon = false;
2428         }
2429       }
2430       // Add the source value to the stack of traversed objects and associate
2431       // it with its merged value.
2432       stackA.push(srcValue);
2433       stackB.push(result);
2434
2435       if (isCommon) {
2436         // Recursively merge objects and arrays (susceptible to call stack limits).
2437         object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
2438       } else if (result === result ? (result !== value) : (value === value)) {
2439         object[key] = result;
2440       }
2441     }
2442
2443     /**
2444      * The base implementation of `_.property` without support for deep paths.
2445      *
2446      * @private
2447      * @param {string} key The key of the property to get.
2448      * @returns {Function} Returns the new function.
2449      */
2450     function baseProperty(key) {
2451       return function(object) {
2452         return object == null ? undefined : object[key];
2453       };
2454     }
2455
2456     /**
2457      * A specialized version of `baseProperty` which supports deep paths.
2458      *
2459      * @private
2460      * @param {Array|string} path The path of the property to get.
2461      * @returns {Function} Returns the new function.
2462      */
2463     function basePropertyDeep(path) {
2464       var pathKey = (path + '');
2465       path = toPath(path);
2466       return function(object) {
2467         return baseGet(object, path, pathKey);
2468       };
2469     }
2470
2471     /**
2472      * The base implementation of `_.pullAt` without support for individual
2473      * index arguments and capturing the removed elements.
2474      *
2475      * @private
2476      * @param {Array} array The array to modify.
2477      * @param {number[]} indexes The indexes of elements to remove.
2478      * @returns {Array} Returns `array`.
2479      */
2480     function basePullAt(array, indexes) {
2481       var length = array ? indexes.length : 0;
2482       while (length--) {
2483         var index = indexes[length];
2484         if (index != previous && isIndex(index)) {
2485           var previous = index;
2486           splice.call(array, index, 1);
2487         }
2488       }
2489       return array;
2490     }
2491
2492     /**
2493      * The base implementation of `_.random` without support for argument juggling
2494      * and returning floating-point numbers.
2495      *
2496      * @private
2497      * @param {number} min The minimum possible value.
2498      * @param {number} max The maximum possible value.
2499      * @returns {number} Returns the random number.
2500      */
2501     function baseRandom(min, max) {
2502       return min + nativeFloor(nativeRandom() * (max - min + 1));
2503     }
2504
2505     /**
2506      * The base implementation of `_.reduce` and `_.reduceRight` without support
2507      * for callback shorthands and `this` binding, which iterates over `collection`
2508      * using the provided `eachFunc`.
2509      *
2510      * @private
2511      * @param {Array|Object|string} collection The collection to iterate over.
2512      * @param {Function} iteratee The function invoked per iteration.
2513      * @param {*} accumulator The initial value.
2514      * @param {boolean} initFromCollection Specify using the first or last element
2515      *  of `collection` as the initial value.
2516      * @param {Function} eachFunc The function to iterate over `collection`.
2517      * @returns {*} Returns the accumulated value.
2518      */
2519     function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
2520       eachFunc(collection, function(value, index, collection) {
2521         accumulator = initFromCollection
2522           ? (initFromCollection = false, value)
2523           : iteratee(accumulator, value, index, collection);
2524       });
2525       return accumulator;
2526     }
2527
2528     /**
2529      * The base implementation of `setData` without support for hot loop detection.
2530      *
2531      * @private
2532      * @param {Function} func The function to associate metadata with.
2533      * @param {*} data The metadata.
2534      * @returns {Function} Returns `func`.
2535      */
2536     var baseSetData = !metaMap ? identity : function(func, data) {
2537       metaMap.set(func, data);
2538       return func;
2539     };
2540
2541     /**
2542      * The base implementation of `_.slice` without an iteratee call guard.
2543      *
2544      * @private
2545      * @param {Array} array The array to slice.
2546      * @param {number} [start=0] The start position.
2547      * @param {number} [end=array.length] The end position.
2548      * @returns {Array} Returns the slice of `array`.
2549      */
2550     function baseSlice(array, start, end) {
2551       var index = -1,
2552           length = array.length;
2553
2554       start = start == null ? 0 : (+start || 0);
2555       if (start < 0) {
2556         start = -start > length ? 0 : (length + start);
2557       }
2558       end = (end === undefined || end > length) ? length : (+end || 0);
2559       if (end < 0) {
2560         end += length;
2561       }
2562       length = start > end ? 0 : ((end - start) >>> 0);
2563       start >>>= 0;
2564
2565       var result = Array(length);
2566       while (++index < length) {
2567         result[index] = array[index + start];
2568       }
2569       return result;
2570     }
2571
2572     /**
2573      * The base implementation of `_.some` without support for callback shorthands
2574      * and `this` binding.
2575      *
2576      * @private
2577      * @param {Array|Object|string} collection The collection to iterate over.
2578      * @param {Function} predicate The function invoked per iteration.
2579      * @returns {boolean} Returns `true` if any element passes the predicate check,
2580      *  else `false`.
2581      */
2582     function baseSome(collection, predicate) {
2583       var result;
2584
2585       baseEach(collection, function(value, index, collection) {
2586         result = predicate(value, index, collection);
2587         return !result;
2588       });
2589       return !!result;
2590     }
2591
2592     /**
2593      * The base implementation of `_.sortBy` which uses `comparer` to define
2594      * the sort order of `array` and replaces criteria objects with their
2595      * corresponding values.
2596      *
2597      * @private
2598      * @param {Array} array The array to sort.
2599      * @param {Function} comparer The function to define sort order.
2600      * @returns {Array} Returns `array`.
2601      */
2602     function baseSortBy(array, comparer) {
2603       var length = array.length;
2604
2605       array.sort(comparer);
2606       while (length--) {
2607         array[length] = array[length].value;
2608       }
2609       return array;
2610     }
2611
2612     /**
2613      * The base implementation of `_.sortByOrder` without param guards.
2614      *
2615      * @private
2616      * @param {Array|Object|string} collection The collection to iterate over.
2617      * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
2618      * @param {boolean[]} orders The sort orders of `iteratees`.
2619      * @returns {Array} Returns the new sorted array.
2620      */
2621     function baseSortByOrder(collection, iteratees, orders) {
2622       var callback = getCallback(),
2623           index = -1;
2624
2625       iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
2626
2627       var result = baseMap(collection, function(value) {
2628         var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
2629         return { 'criteria': criteria, 'index': ++index, 'value': value };
2630       });
2631
2632       return baseSortBy(result, function(object, other) {
2633         return compareMultiple(object, other, orders);
2634       });
2635     }
2636
2637     /**
2638      * The base implementation of `_.sum` without support for callback shorthands
2639      * and `this` binding.
2640      *
2641      * @private
2642      * @param {Array|Object|string} collection The collection to iterate over.
2643      * @param {Function} iteratee The function invoked per iteration.
2644      * @returns {number} Returns the sum.
2645      */
2646     function baseSum(collection, iteratee) {
2647       var result = 0;
2648       baseEach(collection, function(value, index, collection) {
2649         result += +iteratee(value, index, collection) || 0;
2650       });
2651       return result;
2652     }
2653
2654     /**
2655      * The base implementation of `_.uniq` without support for callback shorthands
2656      * and `this` binding.
2657      *
2658      * @private
2659      * @param {Array} array The array to inspect.
2660      * @param {Function} [iteratee] The function invoked per iteration.
2661      * @returns {Array} Returns the new duplicate-value-free array.
2662      */
2663     function baseUniq(array, iteratee) {
2664       var index = -1,
2665           indexOf = getIndexOf(),
2666           length = array.length,
2667           isCommon = indexOf == baseIndexOf,
2668           isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
2669           seen = isLarge ? createCache() : null,
2670           result = [];
2671
2672       if (seen) {
2673         indexOf = cacheIndexOf;
2674         isCommon = false;
2675       } else {
2676         isLarge = false;
2677         seen = iteratee ? [] : result;
2678       }
2679       outer:
2680       while (++index < length) {
2681         var value = array[index],
2682             computed = iteratee ? iteratee(value, index, array) : value;
2683
2684         if (isCommon && value === value) {
2685           var seenIndex = seen.length;
2686           while (seenIndex--) {
2687             if (seen[seenIndex] === computed) {
2688               continue outer;
2689             }
2690           }
2691           if (iteratee) {
2692             seen.push(computed);
2693           }
2694           result.push(value);
2695         }
2696         else if (indexOf(seen, computed, 0) < 0) {
2697           if (iteratee || isLarge) {
2698             seen.push(computed);
2699           }
2700           result.push(value);
2701         }
2702       }
2703       return result;
2704     }
2705
2706     /**
2707      * The base implementation of `_.values` and `_.valuesIn` which creates an
2708      * array of `object` property values corresponding to the property names
2709      * of `props`.
2710      *
2711      * @private
2712      * @param {Object} object The object to query.
2713      * @param {Array} props The property names to get values for.
2714      * @returns {Object} Returns the array of property values.
2715      */
2716     function baseValues(object, props) {
2717       var index = -1,
2718           length = props.length,
2719           result = Array(length);
2720
2721       while (++index < length) {
2722         result[index] = object[props[index]];
2723       }
2724       return result;
2725     }
2726
2727     /**
2728      * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
2729      * and `_.takeWhile` without support for callback shorthands and `this` binding.
2730      *
2731      * @private
2732      * @param {Array} array The array to query.
2733      * @param {Function} predicate The function invoked per iteration.
2734      * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
2735      * @param {boolean} [fromRight] Specify iterating from right to left.
2736      * @returns {Array} Returns the slice of `array`.
2737      */
2738     function baseWhile(array, predicate, isDrop, fromRight) {
2739       var length = array.length,
2740           index = fromRight ? length : -1;
2741
2742       while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
2743       return isDrop
2744         ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
2745         : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
2746     }
2747
2748     /**
2749      * The base implementation of `wrapperValue` which returns the result of
2750      * performing a sequence of actions on the unwrapped `value`, where each
2751      * successive action is supplied the return value of the previous.
2752      *
2753      * @private
2754      * @param {*} value The unwrapped value.
2755      * @param {Array} actions Actions to peform to resolve the unwrapped value.
2756      * @returns {*} Returns the resolved value.
2757      */
2758     function baseWrapperValue(value, actions) {
2759       var result = value;
2760       if (result instanceof LazyWrapper) {
2761         result = result.value();
2762       }
2763       var index = -1,
2764           length = actions.length;
2765
2766       while (++index < length) {
2767         var action = actions[index];
2768         result = action.func.apply(action.thisArg, arrayPush([result], action.args));
2769       }
2770       return result;
2771     }
2772
2773     /**
2774      * Performs a binary search of `array` to determine the index at which `value`
2775      * should be inserted into `array` in order to maintain its sort order.
2776      *
2777      * @private
2778      * @param {Array} array The sorted array to inspect.
2779      * @param {*} value The value to evaluate.
2780      * @param {boolean} [retHighest] Specify returning the highest qualified index.
2781      * @returns {number} Returns the index at which `value` should be inserted
2782      *  into `array`.
2783      */
2784     function binaryIndex(array, value, retHighest) {
2785       var low = 0,
2786           high = array ? array.length : low;
2787
2788       if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
2789         while (low < high) {
2790           var mid = (low + high) >>> 1,
2791               computed = array[mid];
2792
2793           if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
2794             low = mid + 1;
2795           } else {
2796             high = mid;
2797           }
2798         }
2799         return high;
2800       }
2801       return binaryIndexBy(array, value, identity, retHighest);
2802     }
2803
2804     /**
2805      * This function is like `binaryIndex` except that it invokes `iteratee` for
2806      * `value` and each element of `array` to compute their sort ranking. The
2807      * iteratee is invoked with one argument; (value).
2808      *
2809      * @private
2810      * @param {Array} array The sorted array to inspect.
2811      * @param {*} value The value to evaluate.
2812      * @param {Function} iteratee The function invoked per iteration.
2813      * @param {boolean} [retHighest] Specify returning the highest qualified index.
2814      * @returns {number} Returns the index at which `value` should be inserted
2815      *  into `array`.
2816      */
2817     function binaryIndexBy(array, value, iteratee, retHighest) {
2818       value = iteratee(value);
2819
2820       var low = 0,
2821           high = array ? array.length : 0,
2822           valIsNaN = value !== value,
2823           valIsNull = value === null,
2824           valIsUndef = value === undefined;
2825
2826       while (low < high) {
2827         var mid = nativeFloor((low + high) / 2),
2828             computed = iteratee(array[mid]),
2829             isDef = computed !== undefined,
2830             isReflexive = computed === computed;
2831
2832         if (valIsNaN) {
2833           var setLow = isReflexive || retHighest;
2834         } else if (valIsNull) {
2835           setLow = isReflexive && isDef && (retHighest || computed != null);
2836         } else if (valIsUndef) {
2837           setLow = isReflexive && (retHighest || isDef);
2838         } else if (computed == null) {
2839           setLow = false;
2840         } else {
2841           setLow = retHighest ? (computed <= value) : (computed < value);
2842         }
2843         if (setLow) {
2844           low = mid + 1;
2845         } else {
2846           high = mid;
2847         }
2848       }
2849       return nativeMin(high, MAX_ARRAY_INDEX);
2850     }
2851
2852     /**
2853      * A specialized version of `baseCallback` which only supports `this` binding
2854      * and specifying the number of arguments to provide to `func`.
2855      *
2856      * @private
2857      * @param {Function} func The function to bind.
2858      * @param {*} thisArg The `this` binding of `func`.
2859      * @param {number} [argCount] The number of arguments to provide to `func`.
2860      * @returns {Function} Returns the callback.
2861      */
2862     function bindCallback(func, thisArg, argCount) {
2863       if (typeof func != 'function') {
2864         return identity;
2865       }
2866       if (thisArg === undefined) {
2867         return func;
2868       }
2869       switch (argCount) {
2870         case 1: return function(value) {
2871           return func.call(thisArg, value);
2872         };
2873         case 3: return function(value, index, collection) {
2874           return func.call(thisArg, value, index, collection);
2875         };
2876         case 4: return function(accumulator, value, index, collection) {
2877           return func.call(thisArg, accumulator, value, index, collection);
2878         };
2879         case 5: return function(value, other, key, object, source) {
2880           return func.call(thisArg, value, other, key, object, source);
2881         };
2882       }
2883       return function() {
2884         return func.apply(thisArg, arguments);
2885       };
2886     }
2887
2888     /**
2889      * Creates a clone of the given array buffer.
2890      *
2891      * @private
2892      * @param {ArrayBuffer} buffer The array buffer to clone.
2893      * @returns {ArrayBuffer} Returns the cloned array buffer.
2894      */
2895     function bufferClone(buffer) {
2896       var result = new ArrayBuffer(buffer.byteLength),
2897           view = new Uint8Array(result);
2898
2899       view.set(new Uint8Array(buffer));
2900       return result;
2901     }
2902
2903     /**
2904      * Creates an array that is the composition of partially applied arguments,
2905      * placeholders, and provided arguments into a single array of arguments.
2906      *
2907      * @private
2908      * @param {Array|Object} args The provided arguments.
2909      * @param {Array} partials The arguments to prepend to those provided.
2910      * @param {Array} holders The `partials` placeholder indexes.
2911      * @returns {Array} Returns the new array of composed arguments.
2912      */
2913     function composeArgs(args, partials, holders) {
2914       var holdersLength = holders.length,
2915           argsIndex = -1,
2916           argsLength = nativeMax(args.length - holdersLength, 0),
2917           leftIndex = -1,
2918           leftLength = partials.length,
2919           result = Array(leftLength + argsLength);
2920
2921       while (++leftIndex < leftLength) {
2922         result[leftIndex] = partials[leftIndex];
2923       }
2924       while (++argsIndex < holdersLength) {
2925         result[holders[argsIndex]] = args[argsIndex];
2926       }
2927       while (argsLength--) {
2928         result[leftIndex++] = args[argsIndex++];
2929       }
2930       return result;
2931     }
2932
2933     /**
2934      * This function is like `composeArgs` except that the arguments composition
2935      * is tailored for `_.partialRight`.
2936      *
2937      * @private
2938      * @param {Array|Object} args The provided arguments.
2939      * @param {Array} partials The arguments to append to those provided.
2940      * @param {Array} holders The `partials` placeholder indexes.
2941      * @returns {Array} Returns the new array of composed arguments.
2942      */
2943     function composeArgsRight(args, partials, holders) {
2944       var holdersIndex = -1,
2945           holdersLength = holders.length,
2946           argsIndex = -1,
2947           argsLength = nativeMax(args.length - holdersLength, 0),
2948           rightIndex = -1,
2949           rightLength = partials.length,
2950           result = Array(argsLength + rightLength);
2951
2952       while (++argsIndex < argsLength) {
2953         result[argsIndex] = args[argsIndex];
2954       }
2955       var offset = argsIndex;
2956       while (++rightIndex < rightLength) {
2957         result[offset + rightIndex] = partials[rightIndex];
2958       }
2959       while (++holdersIndex < holdersLength) {
2960         result[offset + holders[holdersIndex]] = args[argsIndex++];
2961       }
2962       return result;
2963     }
2964
2965     /**
2966      * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
2967      *
2968      * @private
2969      * @param {Function} setter The function to set keys and values of the accumulator object.
2970      * @param {Function} [initializer] The function to initialize the accumulator object.
2971      * @returns {Function} Returns the new aggregator function.
2972      */
2973     function createAggregator(setter, initializer) {
2974       return function(collection, iteratee, thisArg) {
2975         var result = initializer ? initializer() : {};
2976         iteratee = getCallback(iteratee, thisArg, 3);
2977
2978         if (isArray(collection)) {
2979           var index = -1,
2980               length = collection.length;
2981
2982           while (++index < length) {
2983             var value = collection[index];
2984             setter(result, value, iteratee(value, index, collection), collection);
2985           }
2986         } else {
2987           baseEach(collection, function(value, key, collection) {
2988             setter(result, value, iteratee(value, key, collection), collection);
2989           });
2990         }
2991         return result;
2992       };
2993     }
2994
2995     /**
2996      * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
2997      *
2998      * @private
2999      * @param {Function} assigner The function to assign values.
3000      * @returns {Function} Returns the new assigner function.
3001      */
3002     function createAssigner(assigner) {
3003       return restParam(function(object, sources) {
3004         var index = -1,
3005             length = object == null ? 0 : sources.length,
3006             customizer = length > 2 ? sources[length - 2] : undefined,
3007             guard = length > 2 ? sources[2] : undefined,
3008             thisArg = length > 1 ? sources[length - 1] : undefined;
3009
3010         if (typeof customizer == 'function') {
3011           customizer = bindCallback(customizer, thisArg, 5);
3012           length -= 2;
3013         } else {
3014           customizer = typeof thisArg == 'function' ? thisArg : undefined;
3015           length -= (customizer ? 1 : 0);
3016         }
3017         if (guard && isIterateeCall(sources[0], sources[1], guard)) {
3018           customizer = length < 3 ? undefined : customizer;
3019           length = 1;
3020         }
3021         while (++index < length) {
3022           var source = sources[index];
3023           if (source) {
3024             assigner(object, source, customizer);
3025           }
3026         }
3027         return object;
3028       });
3029     }
3030
3031     /**
3032      * Creates a `baseEach` or `baseEachRight` function.
3033      *
3034      * @private
3035      * @param {Function} eachFunc The function to iterate over a collection.
3036      * @param {boolean} [fromRight] Specify iterating from right to left.
3037      * @returns {Function} Returns the new base function.
3038      */
3039     function createBaseEach(eachFunc, fromRight) {
3040       return function(collection, iteratee) {
3041         var length = collection ? getLength(collection) : 0;
3042         if (!isLength(length)) {
3043           return eachFunc(collection, iteratee);
3044         }
3045         var index = fromRight ? length : -1,
3046             iterable = toObject(collection);
3047
3048         while ((fromRight ? index-- : ++index < length)) {
3049           if (iteratee(iterable[index], index, iterable) === false) {
3050             break;
3051           }
3052         }
3053         return collection;
3054       };
3055     }
3056
3057     /**
3058      * Creates a base function for `_.forIn` or `_.forInRight`.
3059      *
3060      * @private
3061      * @param {boolean} [fromRight] Specify iterating from right to left.
3062      * @returns {Function} Returns the new base function.
3063      */
3064     function createBaseFor(fromRight) {
3065       return function(object, iteratee, keysFunc) {
3066         var iterable = toObject(object),
3067             props = keysFunc(object),
3068             length = props.length,
3069             index = fromRight ? length : -1;
3070
3071         while ((fromRight ? index-- : ++index < length)) {
3072           var key = props[index];
3073           if (iteratee(iterable[key], key, iterable) === false) {
3074             break;
3075           }
3076         }
3077         return object;
3078       };
3079     }
3080
3081     /**
3082      * Creates a function that wraps `func` and invokes it with the `this`
3083      * binding of `thisArg`.
3084      *
3085      * @private
3086      * @param {Function} func The function to bind.
3087      * @param {*} [thisArg] The `this` binding of `func`.
3088      * @returns {Function} Returns the new bound function.
3089      */
3090     function createBindWrapper(func, thisArg) {
3091       var Ctor = createCtorWrapper(func);
3092
3093       function wrapper() {
3094         var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
3095         return fn.apply(thisArg, arguments);
3096       }
3097       return wrapper;
3098     }
3099
3100     /**
3101      * Creates a `Set` cache object to optimize linear searches of large arrays.
3102      *
3103      * @private
3104      * @param {Array} [values] The values to cache.
3105      * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
3106      */
3107     function createCache(values) {
3108       return (nativeCreate && Set) ? new SetCache(values) : null;
3109     }
3110
3111     /**
3112      * Creates a function that produces compound words out of the words in a
3113      * given string.
3114      *
3115      * @private
3116      * @param {Function} callback The function to combine each word.
3117      * @returns {Function} Returns the new compounder function.
3118      */
3119     function createCompounder(callback) {
3120       return function(string) {
3121         var index = -1,
3122             array = words(deburr(string)),
3123             length = array.length,
3124             result = '';
3125
3126         while (++index < length) {
3127           result = callback(result, array[index], index);
3128         }
3129         return result;
3130       };
3131     }
3132
3133     /**
3134      * Creates a function that produces an instance of `Ctor` regardless of
3135      * whether it was invoked as part of a `new` expression or by `call` or `apply`.
3136      *
3137      * @private
3138      * @param {Function} Ctor The constructor to wrap.
3139      * @returns {Function} Returns the new wrapped function.
3140      */
3141     function createCtorWrapper(Ctor) {
3142       return function() {
3143         // Use a `switch` statement to work with class constructors.
3144         // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
3145         // for more details.
3146         var args = arguments;
3147         switch (args.length) {
3148           case 0: return new Ctor;
3149           case 1: return new Ctor(args[0]);
3150           case 2: return new Ctor(args[0], args[1]);
3151           case 3: return new Ctor(args[0], args[1], args[2]);
3152           case 4: return new Ctor(args[0], args[1], args[2], args[3]);
3153           case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
3154           case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
3155           case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
3156         }
3157         var thisBinding = baseCreate(Ctor.prototype),
3158             result = Ctor.apply(thisBinding, args);
3159
3160         // Mimic the constructor's `return` behavior.
3161         // See https://es5.github.io/#x13.2.2 for more details.
3162         return isObject(result) ? result : thisBinding;
3163       };
3164     }
3165
3166     /**
3167      * Creates a `_.curry` or `_.curryRight` function.
3168      *
3169      * @private
3170      * @param {boolean} flag The curry bit flag.
3171      * @returns {Function} Returns the new curry function.
3172      */
3173     function createCurry(flag) {
3174       function curryFunc(func, arity, guard) {
3175         if (guard && isIterateeCall(func, arity, guard)) {
3176           arity = undefined;
3177         }
3178         var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
3179         result.placeholder = curryFunc.placeholder;
3180         return result;
3181       }
3182       return curryFunc;
3183     }
3184
3185     /**
3186      * Creates a `_.defaults` or `_.defaultsDeep` function.
3187      *
3188      * @private
3189      * @param {Function} assigner The function to assign values.
3190      * @param {Function} customizer The function to customize assigned values.
3191      * @returns {Function} Returns the new defaults function.
3192      */
3193     function createDefaults(assigner, customizer) {
3194       return restParam(function(args) {
3195         var object = args[0];
3196         if (object == null) {
3197           return object;
3198         }
3199         args.push(customizer);
3200         return assigner.apply(undefined, args);
3201       });
3202     }
3203
3204     /**
3205      * Creates a `_.max` or `_.min` function.
3206      *
3207      * @private
3208      * @param {Function} comparator The function used to compare values.
3209      * @param {*} exValue The initial extremum value.
3210      * @returns {Function} Returns the new extremum function.
3211      */
3212     function createExtremum(comparator, exValue) {
3213       return function(collection, iteratee, thisArg) {
3214         if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
3215           iteratee = undefined;
3216         }
3217         iteratee = getCallback(iteratee, thisArg, 3);
3218         if (iteratee.length == 1) {
3219           collection = isArray(collection) ? collection : toIterable(collection);
3220           var result = arrayExtremum(collection, iteratee, comparator, exValue);
3221           if (!(collection.length && result === exValue)) {
3222             return result;
3223           }
3224         }
3225         return baseExtremum(collection, iteratee, comparator, exValue);
3226       };
3227     }
3228
3229     /**
3230      * Creates a `_.find` or `_.findLast` function.
3231      *
3232      * @private
3233      * @param {Function} eachFunc The function to iterate over a collection.
3234      * @param {boolean} [fromRight] Specify iterating from right to left.
3235      * @returns {Function} Returns the new find function.
3236      */
3237     function createFind(eachFunc, fromRight) {
3238       return function(collection, predicate, thisArg) {
3239         predicate = getCallback(predicate, thisArg, 3);
3240         if (isArray(collection)) {
3241           var index = baseFindIndex(collection, predicate, fromRight);
3242           return index > -1 ? collection[index] : undefined;
3243         }
3244         return baseFind(collection, predicate, eachFunc);
3245       };
3246     }
3247
3248     /**
3249      * Creates a `_.findIndex` or `_.findLastIndex` function.
3250      *
3251      * @private
3252      * @param {boolean} [fromRight] Specify iterating from right to left.
3253      * @returns {Function} Returns the new find function.
3254      */
3255     function createFindIndex(fromRight) {
3256       return function(array, predicate, thisArg) {
3257         if (!(array && array.length)) {
3258           return -1;
3259         }
3260         predicate = getCallback(predicate, thisArg, 3);
3261         return baseFindIndex(array, predicate, fromRight);
3262       };
3263     }
3264
3265     /**
3266      * Creates a `_.findKey` or `_.findLastKey` function.
3267      *
3268      * @private
3269      * @param {Function} objectFunc The function to iterate over an object.
3270      * @returns {Function} Returns the new find function.
3271      */
3272     function createFindKey(objectFunc) {
3273       return function(object, predicate, thisArg) {
3274         predicate = getCallback(predicate, thisArg, 3);
3275         return baseFind(object, predicate, objectFunc, true);
3276       };
3277     }
3278
3279     /**
3280      * Creates a `_.flow` or `_.flowRight` function.
3281      *
3282      * @private
3283      * @param {boolean} [fromRight] Specify iterating from right to left.
3284      * @returns {Function} Returns the new flow function.
3285      */
3286     function createFlow(fromRight) {
3287       return function() {
3288         var wrapper,
3289             length = arguments.length,
3290             index = fromRight ? length : -1,
3291             leftIndex = 0,
3292             funcs = Array(length);
3293
3294         while ((fromRight ? index-- : ++index < length)) {
3295           var func = funcs[leftIndex++] = arguments[index];
3296           if (typeof func != 'function') {
3297             throw new TypeError(FUNC_ERROR_TEXT);
3298           }
3299           if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
3300             wrapper = new LodashWrapper([], true);
3301           }
3302         }
3303         index = wrapper ? -1 : length;
3304         while (++index < length) {
3305           func = funcs[index];
3306
3307           var funcName = getFuncName(func),
3308               data = funcName == 'wrapper' ? getData(func) : undefined;
3309
3310           if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
3311             wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
3312           } else {
3313             wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
3314           }
3315         }
3316         return function() {
3317           var args = arguments,
3318               value = args[0];
3319
3320           if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
3321             return wrapper.plant(value).value();
3322           }
3323           var index = 0,
3324               result = length ? funcs[index].apply(this, args) : value;
3325
3326           while (++index < length) {
3327             result = funcs[index].call(this, result);
3328           }
3329           return result;
3330         };
3331       };
3332     }
3333
3334     /**
3335      * Creates a function for `_.forEach` or `_.forEachRight`.
3336      *
3337      * @private
3338      * @param {Function} arrayFunc The function to iterate over an array.
3339      * @param {Function} eachFunc The function to iterate over a collection.
3340      * @returns {Function} Returns the new each function.
3341      */
3342     function createForEach(arrayFunc, eachFunc) {
3343       return function(collection, iteratee, thisArg) {
3344         return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
3345           ? arrayFunc(collection, iteratee)
3346           : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
3347       };
3348     }
3349
3350     /**
3351      * Creates a function for `_.forIn` or `_.forInRight`.
3352      *
3353      * @private
3354      * @param {Function} objectFunc The function to iterate over an object.
3355      * @returns {Function} Returns the new each function.
3356      */
3357     function createForIn(objectFunc) {
3358       return function(object, iteratee, thisArg) {
3359         if (typeof iteratee != 'function' || thisArg !== undefined) {
3360           iteratee = bindCallback(iteratee, thisArg, 3);
3361         }
3362         return objectFunc(object, iteratee, keysIn);
3363       };
3364     }
3365
3366     /**
3367      * Creates a function for `_.forOwn` or `_.forOwnRight`.
3368      *
3369      * @private
3370      * @param {Function} objectFunc The function to iterate over an object.
3371      * @returns {Function} Returns the new each function.
3372      */
3373     function createForOwn(objectFunc) {
3374       return function(object, iteratee, thisArg) {
3375         if (typeof iteratee != 'function' || thisArg !== undefined) {
3376           iteratee = bindCallback(iteratee, thisArg, 3);
3377         }
3378         return objectFunc(object, iteratee);
3379       };
3380     }
3381
3382     /**
3383      * Creates a function for `_.mapKeys` or `_.mapValues`.
3384      *
3385      * @private
3386      * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
3387      * @returns {Function} Returns the new map function.
3388      */
3389     function createObjectMapper(isMapKeys) {
3390       return function(object, iteratee, thisArg) {
3391         var result = {};
3392         iteratee = getCallback(iteratee, thisArg, 3);
3393
3394         baseForOwn(object, function(value, key, object) {
3395           var mapped = iteratee(value, key, object);
3396           key = isMapKeys ? mapped : key;
3397           value = isMapKeys ? value : mapped;
3398           result[key] = value;
3399         });
3400         return result;
3401       };
3402     }
3403
3404     /**
3405      * Creates a function for `_.padLeft` or `_.padRight`.
3406      *
3407      * @private
3408      * @param {boolean} [fromRight] Specify padding from the right.
3409      * @returns {Function} Returns the new pad function.
3410      */
3411     function createPadDir(fromRight) {
3412       return function(string, length, chars) {
3413         string = baseToString(string);
3414         return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
3415       };
3416     }
3417
3418     /**
3419      * Creates a `_.partial` or `_.partialRight` function.
3420      *
3421      * @private
3422      * @param {boolean} flag The partial bit flag.
3423      * @returns {Function} Returns the new partial function.
3424      */
3425     function createPartial(flag) {
3426       var partialFunc = restParam(function(func, partials) {
3427         var holders = replaceHolders(partials, partialFunc.placeholder);
3428         return createWrapper(func, flag, undefined, partials, holders);
3429       });
3430       return partialFunc;
3431     }
3432
3433     /**
3434      * Creates a function for `_.reduce` or `_.reduceRight`.
3435      *
3436      * @private
3437      * @param {Function} arrayFunc The function to iterate over an array.
3438      * @param {Function} eachFunc The function to iterate over a collection.
3439      * @returns {Function} Returns the new each function.
3440      */
3441     function createReduce(arrayFunc, eachFunc) {
3442       return function(collection, iteratee, accumulator, thisArg) {
3443         var initFromArray = arguments.length < 3;
3444         return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
3445           ? arrayFunc(collection, iteratee, accumulator, initFromArray)
3446           : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
3447       };
3448     }
3449
3450     /**
3451      * Creates a function that wraps `func` and invokes it with optional `this`
3452      * binding of, partial application, and currying.
3453      *
3454      * @private
3455      * @param {Function|string} func The function or method name to reference.
3456      * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3457      * @param {*} [thisArg] The `this` binding of `func`.
3458      * @param {Array} [partials] The arguments to prepend to those provided to the new function.
3459      * @param {Array} [holders] The `partials` placeholder indexes.
3460      * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
3461      * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
3462      * @param {Array} [argPos] The argument positions of the new function.
3463      * @param {number} [ary] The arity cap of `func`.
3464      * @param {number} [arity] The arity of `func`.
3465      * @returns {Function} Returns the new wrapped function.
3466      */
3467     function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
3468       var isAry = bitmask & ARY_FLAG,
3469           isBind = bitmask & BIND_FLAG,
3470           isBindKey = bitmask & BIND_KEY_FLAG,
3471           isCurry = bitmask & CURRY_FLAG,
3472           isCurryBound = bitmask & CURRY_BOUND_FLAG,
3473           isCurryRight = bitmask & CURRY_RIGHT_FLAG,
3474           Ctor = isBindKey ? undefined : createCtorWrapper(func);
3475
3476       function wrapper() {
3477         // Avoid `arguments` object use disqualifying optimizations by
3478         // converting it to an array before providing it to other functions.
3479         var length = arguments.length,
3480             index = length,
3481             args = Array(length);
3482
3483         while (index--) {
3484           args[index] = arguments[index];
3485         }
3486         if (partials) {
3487           args = composeArgs(args, partials, holders);
3488         }
3489         if (partialsRight) {
3490           args = composeArgsRight(args, partialsRight, holdersRight);
3491         }
3492         if (isCurry || isCurryRight) {
3493           var placeholder = wrapper.placeholder,
3494               argsHolders = replaceHolders(args, placeholder);
3495
3496           length -= argsHolders.length;
3497           if (length < arity) {
3498             var newArgPos = argPos ? arrayCopy(argPos) : undefined,
3499                 newArity = nativeMax(arity - length, 0),
3500                 newsHolders = isCurry ? argsHolders : undefined,
3501                 newHoldersRight = isCurry ? undefined : argsHolders,
3502                 newPartials = isCurry ? args : undefined,
3503                 newPartialsRight = isCurry ? undefined : args;
3504
3505             bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
3506             bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
3507
3508             if (!isCurryBound) {
3509               bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
3510             }
3511             var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
3512                 result = createHybridWrapper.apply(undefined, newData);
3513
3514             if (isLaziable(func)) {
3515               setData(result, newData);
3516             }
3517             result.placeholder = placeholder;
3518             return result;
3519           }
3520         }
3521         var thisBinding = isBind ? thisArg : this,
3522             fn = isBindKey ? thisBinding[func] : func;
3523
3524         if (argPos) {
3525           args = reorder(args, argPos);
3526         }
3527         if (isAry && ary < args.length) {
3528           args.length = ary;
3529         }
3530         if (this && this !== root && this instanceof wrapper) {
3531           fn = Ctor || createCtorWrapper(func);
3532         }
3533         return fn.apply(thisBinding, args);
3534       }
3535       return wrapper;
3536     }
3537
3538     /**
3539      * Creates the padding required for `string` based on the given `length`.
3540      * The `chars` string is truncated if the number of characters exceeds `length`.
3541      *
3542      * @private
3543      * @param {string} string The string to create padding for.
3544      * @param {number} [length=0] The padding length.
3545      * @param {string} [chars=' '] The string used as padding.
3546      * @returns {string} Returns the pad for `string`.
3547      */
3548     function createPadding(string, length, chars) {
3549       var strLength = string.length;
3550       length = +length;
3551
3552       if (strLength >= length || !nativeIsFinite(length)) {
3553         return '';
3554       }
3555       var padLength = length - strLength;
3556       chars = chars == null ? ' ' : (chars + '');
3557       return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
3558     }
3559
3560     /**
3561      * Creates a function that wraps `func` and invokes it with the optional `this`
3562      * binding of `thisArg` and the `partials` prepended to those provided to
3563      * the wrapper.
3564      *
3565      * @private
3566      * @param {Function} func The function to partially apply arguments to.
3567      * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3568      * @param {*} thisArg The `this` binding of `func`.
3569      * @param {Array} partials The arguments to prepend to those provided to the new function.
3570      * @returns {Function} Returns the new bound function.
3571      */
3572     function createPartialWrapper(func, bitmask, thisArg, partials) {
3573       var isBind = bitmask & BIND_FLAG,
3574           Ctor = createCtorWrapper(func);
3575
3576       function wrapper() {
3577         // Avoid `arguments` object use disqualifying optimizations by
3578         // converting it to an array before providing it `func`.
3579         var argsIndex = -1,
3580             argsLength = arguments.length,
3581             leftIndex = -1,
3582             leftLength = partials.length,
3583             args = Array(leftLength + argsLength);
3584
3585         while (++leftIndex < leftLength) {
3586           args[leftIndex] = partials[leftIndex];
3587         }
3588         while (argsLength--) {
3589           args[leftIndex++] = arguments[++argsIndex];
3590         }
3591         var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
3592         return fn.apply(isBind ? thisArg : this, args);
3593       }
3594       return wrapper;
3595     }
3596
3597     /**
3598      * Creates a `_.ceil`, `_.floor`, or `_.round` function.
3599      *
3600      * @private
3601      * @param {string} methodName The name of the `Math` method to use when rounding.
3602      * @returns {Function} Returns the new round function.
3603      */
3604     function createRound(methodName) {
3605       var func = Math[methodName];
3606       return function(number, precision) {
3607         precision = precision === undefined ? 0 : (+precision || 0);
3608         if (precision) {
3609           precision = pow(10, precision);
3610           return func(number * precision) / precision;
3611         }
3612         return func(number);
3613       };
3614     }
3615
3616     /**
3617      * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
3618      *
3619      * @private
3620      * @param {boolean} [retHighest] Specify returning the highest qualified index.
3621      * @returns {Function} Returns the new index function.
3622      */
3623     function createSortedIndex(retHighest) {
3624       return function(array, value, iteratee, thisArg) {
3625         var callback = getCallback(iteratee);
3626         return (iteratee == null && callback === baseCallback)
3627           ? binaryIndex(array, value, retHighest)
3628           : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
3629       };
3630     }
3631
3632     /**
3633      * Creates a function that either curries or invokes `func` with optional
3634      * `this` binding and partially applied arguments.
3635      *
3636      * @private
3637      * @param {Function|string} func The function or method name to reference.
3638      * @param {number} bitmask The bitmask of flags.
3639      *  The bitmask may be composed of the following flags:
3640      *     1 - `_.bind`
3641      *     2 - `_.bindKey`
3642      *     4 - `_.curry` or `_.curryRight` of a bound function
3643      *     8 - `_.curry`
3644      *    16 - `_.curryRight`
3645      *    32 - `_.partial`
3646      *    64 - `_.partialRight`
3647      *   128 - `_.rearg`
3648      *   256 - `_.ary`
3649      * @param {*} [thisArg] The `this` binding of `func`.
3650      * @param {Array} [partials] The arguments to be partially applied.
3651      * @param {Array} [holders] The `partials` placeholder indexes.
3652      * @param {Array} [argPos] The argument positions of the new function.
3653      * @param {number} [ary] The arity cap of `func`.
3654      * @param {number} [arity] The arity of `func`.
3655      * @returns {Function} Returns the new wrapped function.
3656      */
3657     function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
3658       var isBindKey = bitmask & BIND_KEY_FLAG;
3659       if (!isBindKey && typeof func != 'function') {
3660         throw new TypeError(FUNC_ERROR_TEXT);
3661       }
3662       var length = partials ? partials.length : 0;
3663       if (!length) {
3664         bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
3665         partials = holders = undefined;
3666       }
3667       length -= (holders ? holders.length : 0);
3668       if (bitmask & PARTIAL_RIGHT_FLAG) {
3669         var partialsRight = partials,
3670             holdersRight = holders;
3671
3672         partials = holders = undefined;
3673       }
3674       var data = isBindKey ? undefined : getData(func),
3675           newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
3676
3677       if (data) {
3678         mergeData(newData, data);
3679         bitmask = newData[1];
3680         arity = newData[9];
3681       }
3682       newData[9] = arity == null
3683         ? (isBindKey ? 0 : func.length)
3684         : (nativeMax(arity - length, 0) || 0);
3685
3686       if (bitmask == BIND_FLAG) {
3687         var result = createBindWrapper(newData[0], newData[2]);
3688       } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
3689         result = createPartialWrapper.apply(undefined, newData);
3690       } else {
3691         result = createHybridWrapper.apply(undefined, newData);
3692       }
3693       var setter = data ? baseSetData : setData;
3694       return setter(result, newData);
3695     }
3696
3697     /**
3698      * A specialized version of `baseIsEqualDeep` for arrays with support for
3699      * partial deep comparisons.
3700      *
3701      * @private
3702      * @param {Array} array The array to compare.
3703      * @param {Array} other The other array to compare.
3704      * @param {Function} equalFunc The function to determine equivalents of values.
3705      * @param {Function} [customizer] The function to customize comparing arrays.
3706      * @param {boolean} [isLoose] Specify performing partial comparisons.
3707      * @param {Array} [stackA] Tracks traversed `value` objects.
3708      * @param {Array} [stackB] Tracks traversed `other` objects.
3709      * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
3710      */
3711     function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
3712       var index = -1,
3713           arrLength = array.length,
3714           othLength = other.length;
3715
3716       if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
3717         return false;
3718       }
3719       // Ignore non-index properties.
3720       while (++index < arrLength) {
3721         var arrValue = array[index],
3722             othValue = other[index],
3723             result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
3724
3725         if (result !== undefined) {
3726           if (result) {
3727             continue;
3728           }
3729           return false;
3730         }
3731         // Recursively compare arrays (susceptible to call stack limits).
3732         if (isLoose) {
3733           if (!arraySome(other, function(othValue) {
3734                 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
3735               })) {
3736             return false;
3737           }
3738         } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
3739           return false;
3740         }
3741       }
3742       return true;
3743     }
3744
3745     /**
3746      * A specialized version of `baseIsEqualDeep` for comparing objects of
3747      * the same `toStringTag`.
3748      *
3749      * **Note:** This function only supports comparing values with tags of
3750      * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
3751      *
3752      * @private
3753      * @param {Object} object The object to compare.
3754      * @param {Object} other The other object to compare.
3755      * @param {string} tag The `toStringTag` of the objects to compare.
3756      * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3757      */
3758     function equalByTag(object, other, tag) {
3759       switch (tag) {
3760         case boolTag:
3761         case dateTag:
3762           // Coerce dates and booleans to numbers, dates to milliseconds and booleans
3763           // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
3764           return +object == +other;
3765
3766         case errorTag:
3767           return object.name == other.name && object.message == other.message;
3768
3769         case numberTag:
3770           // Treat `NaN` vs. `NaN` as equal.
3771           return (object != +object)
3772             ? other != +other
3773             : object == +other;
3774
3775         case regexpTag:
3776         case stringTag:
3777           // Coerce regexes to strings and treat strings primitives and string
3778           // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
3779           return object == (other + '');
3780       }
3781       return false;
3782     }
3783
3784     /**
3785      * A specialized version of `baseIsEqualDeep` for objects with support for
3786      * partial deep comparisons.
3787      *
3788      * @private
3789      * @param {Object} object The object to compare.
3790      * @param {Object} other The other object to compare.
3791      * @param {Function} equalFunc The function to determine equivalents of values.
3792      * @param {Function} [customizer] The function to customize comparing values.
3793      * @param {boolean} [isLoose] Specify performing partial comparisons.
3794      * @param {Array} [stackA] Tracks traversed `value` objects.
3795      * @param {Array} [stackB] Tracks traversed `other` objects.
3796      * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3797      */
3798     function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
3799       var objProps = keys(object),
3800           objLength = objProps.length,
3801           othProps = keys(other),
3802           othLength = othProps.length;
3803
3804       if (objLength != othLength && !isLoose) {
3805         return false;
3806       }
3807       var index = objLength;
3808       while (index--) {
3809         var key = objProps[index];
3810         if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
3811           return false;
3812         }
3813       }
3814       var skipCtor = isLoose;
3815       while (++index < objLength) {
3816         key = objProps[index];
3817         var objValue = object[key],
3818             othValue = other[key],
3819             result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
3820
3821         // Recursively compare objects (susceptible to call stack limits).
3822         if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
3823           return false;
3824         }
3825         skipCtor || (skipCtor = key == 'constructor');
3826       }
3827       if (!skipCtor) {
3828         var objCtor = object.constructor,
3829             othCtor = other.constructor;
3830
3831         // Non `Object` object instances with different constructors are not equal.
3832         if (objCtor != othCtor &&
3833             ('constructor' in object && 'constructor' in other) &&
3834             !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
3835               typeof othCtor == 'function' && othCtor instanceof othCtor)) {
3836           return false;
3837         }
3838       }
3839       return true;
3840     }
3841
3842     /**
3843      * Gets the appropriate "callback" function. If the `_.callback` method is
3844      * customized this function returns the custom method, otherwise it returns
3845      * the `baseCallback` function. If arguments are provided the chosen function
3846      * is invoked with them and its result is returned.
3847      *
3848      * @private
3849      * @returns {Function} Returns the chosen function or its result.
3850      */
3851     function getCallback(func, thisArg, argCount) {
3852       var result = lodash.callback || callback;
3853       result = result === callback ? baseCallback : result;
3854       return argCount ? result(func, thisArg, argCount) : result;
3855     }
3856
3857     /**
3858      * Gets metadata for `func`.
3859      *
3860      * @private
3861      * @param {Function} func The function to query.
3862      * @returns {*} Returns the metadata for `func`.
3863      */
3864     var getData = !metaMap ? noop : function(func) {
3865       return metaMap.get(func);
3866     };
3867
3868     /**
3869      * Gets the name of `func`.
3870      *
3871      * @private
3872      * @param {Function} func The function to query.
3873      * @returns {string} Returns the function name.
3874      */
3875     function getFuncName(func) {
3876       var result = func.name,
3877           array = realNames[result],
3878           length = array ? array.length : 0;
3879
3880       while (length--) {
3881         var data = array[length],
3882             otherFunc = data.func;
3883         if (otherFunc == null || otherFunc == func) {
3884           return data.name;
3885         }
3886       }
3887       return result;
3888     }
3889
3890     /**
3891      * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
3892      * customized this function returns the custom method, otherwise it returns
3893      * the `baseIndexOf` function. If arguments are provided the chosen function
3894      * is invoked with them and its result is returned.
3895      *
3896      * @private
3897      * @returns {Function|number} Returns the chosen function or its result.
3898      */
3899     function getIndexOf(collection, target, fromIndex) {
3900       var result = lodash.indexOf || indexOf;
3901       result = result === indexOf ? baseIndexOf : result;
3902       return collection ? result(collection, target, fromIndex) : result;
3903     }
3904
3905     /**
3906      * Gets the "length" property value of `object`.
3907      *
3908      * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
3909      * that affects Safari on at least iOS 8.1-8.3 ARM64.
3910      *
3911      * @private
3912      * @param {Object} object The object to query.
3913      * @returns {*} Returns the "length" value.
3914      */
3915     var getLength = baseProperty('length');
3916
3917     /**
3918      * Gets the propery names, values, and compare flags of `object`.
3919      *
3920      * @private
3921      * @param {Object} object The object to query.
3922      * @returns {Array} Returns the match data of `object`.
3923      */
3924     function getMatchData(object) {
3925       var result = pairs(object),
3926           length = result.length;
3927
3928       while (length--) {
3929         result[length][2] = isStrictComparable(result[length][1]);
3930       }
3931       return result;
3932     }
3933
3934     /**
3935      * Gets the native function at `key` of `object`.
3936      *
3937      * @private
3938      * @param {Object} object The object to query.
3939      * @param {string} key The key of the method to get.
3940      * @returns {*} Returns the function if it's native, else `undefined`.
3941      */
3942     function getNative(object, key) {
3943       var value = object == null ? undefined : object[key];
3944       return isNative(value) ? value : undefined;
3945     }
3946
3947     /**
3948      * Gets the view, applying any `transforms` to the `start` and `end` positions.
3949      *
3950      * @private
3951      * @param {number} start The start of the view.
3952      * @param {number} end The end of the view.
3953      * @param {Array} transforms The transformations to apply to the view.
3954      * @returns {Object} Returns an object containing the `start` and `end`
3955      *  positions of the view.
3956      */
3957     function getView(start, end, transforms) {
3958       var index = -1,
3959           length = transforms.length;
3960
3961       while (++index < length) {
3962         var data = transforms[index],
3963             size = data.size;
3964
3965         switch (data.type) {
3966           case 'drop':      start += size; break;
3967           case 'dropRight': end -= size; break;
3968           case 'take':      end = nativeMin(end, start + size); break;
3969           case 'takeRight': start = nativeMax(start, end - size); break;
3970         }
3971       }
3972       return { 'start': start, 'end': end };
3973     }
3974
3975     /**
3976      * Initializes an array clone.
3977      *
3978      * @private
3979      * @param {Array} array The array to clone.
3980      * @returns {Array} Returns the initialized clone.
3981      */
3982     function initCloneArray(array) {
3983       var length = array.length,
3984           result = new array.constructor(length);
3985
3986       // Add array properties assigned by `RegExp#exec`.
3987       if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
3988         result.index = array.index;
3989         result.input = array.input;
3990       }
3991       return result;
3992     }
3993
3994     /**
3995      * Initializes an object clone.
3996      *
3997      * @private
3998      * @param {Object} object The object to clone.
3999      * @returns {Object} Returns the initialized clone.
4000      */
4001     function initCloneObject(object) {
4002       var Ctor = object.constructor;
4003       if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
4004         Ctor = Object;
4005       }
4006       return new Ctor;
4007     }
4008
4009     /**
4010      * Initializes an object clone based on its `toStringTag`.
4011      *
4012      * **Note:** This function only supports cloning values with tags of
4013      * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4014      *
4015      * @private
4016      * @param {Object} object The object to clone.
4017      * @param {string} tag The `toStringTag` of the object to clone.
4018      * @param {boolean} [isDeep] Specify a deep clone.
4019      * @returns {Object} Returns the initialized clone.
4020      */
4021     function initCloneByTag(object, tag, isDeep) {
4022       var Ctor = object.constructor;
4023       switch (tag) {
4024         case arrayBufferTag:
4025           return bufferClone(object);
4026
4027         case boolTag:
4028         case dateTag:
4029           return new Ctor(+object);
4030
4031         case float32Tag: case float64Tag:
4032         case int8Tag: case int16Tag: case int32Tag:
4033         case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
4034           var buffer = object.buffer;
4035           return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
4036
4037         case numberTag:
4038         case stringTag:
4039           return new Ctor(object);
4040
4041         case regexpTag:
4042           var result = new Ctor(object.source, reFlags.exec(object));
4043           result.lastIndex = object.lastIndex;
4044       }
4045       return result;
4046     }
4047
4048     /**
4049      * Invokes the method at `path` on `object`.
4050      *
4051      * @private
4052      * @param {Object} object The object to query.
4053      * @param {Array|string} path The path of the method to invoke.
4054      * @param {Array} args The arguments to invoke the method with.
4055      * @returns {*} Returns the result of the invoked method.
4056      */
4057     function invokePath(object, path, args) {
4058       if (object != null && !isKey(path, object)) {
4059         path = toPath(path);
4060         object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
4061         path = last(path);
4062       }
4063       var func = object == null ? object : object[path];
4064       return func == null ? undefined : func.apply(object, args);
4065     }
4066
4067     /**
4068      * Checks if `value` is array-like.
4069      *
4070      * @private
4071      * @param {*} value The value to check.
4072      * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
4073      */
4074     function isArrayLike(value) {
4075       return value != null && isLength(getLength(value));
4076     }
4077
4078     /**
4079      * Checks if `value` is a valid array-like index.
4080      *
4081      * @private
4082      * @param {*} value The value to check.
4083      * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
4084      * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
4085      */
4086     function isIndex(value, length) {
4087       value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
4088       length = length == null ? MAX_SAFE_INTEGER : length;
4089       return value > -1 && value % 1 == 0 && value < length;
4090     }
4091
4092     /**
4093      * Checks if the provided arguments are from an iteratee call.
4094      *
4095      * @private
4096      * @param {*} value The potential iteratee value argument.
4097      * @param {*} index The potential iteratee index or key argument.
4098      * @param {*} object The potential iteratee object argument.
4099      * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
4100      */
4101     function isIterateeCall(value, index, object) {
4102       if (!isObject(object)) {
4103         return false;
4104       }
4105       var type = typeof index;
4106       if (type == 'number'
4107           ? (isArrayLike(object) && isIndex(index, object.length))
4108           : (type == 'string' && index in object)) {
4109         var other = object[index];
4110         return value === value ? (value === other) : (other !== other);
4111       }
4112       return false;
4113     }
4114
4115     /**
4116      * Checks if `value` is a property name and not a property path.
4117      *
4118      * @private
4119      * @param {*} value The value to check.
4120      * @param {Object} [object] The object to query keys on.
4121      * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
4122      */
4123     function isKey(value, object) {
4124       var type = typeof value;
4125       if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
4126         return true;
4127       }
4128       if (isArray(value)) {
4129         return false;
4130       }
4131       var result = !reIsDeepProp.test(value);
4132       return result || (object != null && value in toObject(object));
4133     }
4134
4135     /**
4136      * Checks if `func` has a lazy counterpart.
4137      *
4138      * @private
4139      * @param {Function} func The function to check.
4140      * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
4141      */
4142     function isLaziable(func) {
4143       var funcName = getFuncName(func);
4144       if (!(funcName in LazyWrapper.prototype)) {
4145         return false;
4146       }
4147       var other = lodash[funcName];
4148       if (func === other) {
4149         return true;
4150       }
4151       var data = getData(other);
4152       return !!data && func === data[0];
4153     }
4154
4155     /**
4156      * Checks if `value` is a valid array-like length.
4157      *
4158      * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
4159      *
4160      * @private
4161      * @param {*} value The value to check.
4162      * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
4163      */
4164     function isLength(value) {
4165       return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
4166     }
4167
4168     /**
4169      * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
4170      *
4171      * @private
4172      * @param {*} value The value to check.
4173      * @returns {boolean} Returns `true` if `value` if suitable for strict
4174      *  equality comparisons, else `false`.
4175      */
4176     function isStrictComparable(value) {
4177       return value === value && !isObject(value);
4178     }
4179
4180     /**
4181      * Merges the function metadata of `source` into `data`.
4182      *
4183      * Merging metadata reduces the number of wrappers required to invoke a function.
4184      * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
4185      * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
4186      * augment function arguments, making the order in which they are executed important,
4187      * preventing the merging of metadata. However, we make an exception for a safe
4188      * common case where curried functions have `_.ary` and or `_.rearg` applied.
4189      *
4190      * @private
4191      * @param {Array} data The destination metadata.
4192      * @param {Array} source The source metadata.
4193      * @returns {Array} Returns `data`.
4194      */
4195     function mergeData(data, source) {
4196       var bitmask = data[1],
4197           srcBitmask = source[1],
4198           newBitmask = bitmask | srcBitmask,
4199           isCommon = newBitmask < ARY_FLAG;
4200
4201       var isCombo =
4202         (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
4203         (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
4204         (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
4205
4206       // Exit early if metadata can't be merged.
4207       if (!(isCommon || isCombo)) {
4208         return data;
4209       }
4210       // Use source `thisArg` if available.
4211       if (srcBitmask & BIND_FLAG) {
4212         data[2] = source[2];
4213         // Set when currying a bound function.
4214         newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
4215       }
4216       // Compose partial arguments.
4217       var value = source[3];
4218       if (value) {
4219         var partials = data[3];
4220         data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
4221         data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
4222       }
4223       // Compose partial right arguments.
4224       value = source[5];
4225       if (value) {
4226         partials = data[5];
4227         data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
4228         data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
4229       }
4230       // Use source `argPos` if available.
4231       value = source[7];
4232       if (value) {
4233         data[7] = arrayCopy(value);
4234       }
4235       // Use source `ary` if it's smaller.
4236       if (srcBitmask & ARY_FLAG) {
4237         data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
4238       }
4239       // Use source `arity` if one is not provided.
4240       if (data[9] == null) {
4241         data[9] = source[9];
4242       }
4243       // Use source `func` and merge bitmasks.
4244       data[0] = source[0];
4245       data[1] = newBitmask;
4246
4247       return data;
4248     }
4249
4250     /**
4251      * Used by `_.defaultsDeep` to customize its `_.merge` use.
4252      *
4253      * @private
4254      * @param {*} objectValue The destination object property value.
4255      * @param {*} sourceValue The source object property value.
4256      * @returns {*} Returns the value to assign to the destination object.
4257      */
4258     function mergeDefaults(objectValue, sourceValue) {
4259       return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
4260     }
4261
4262     /**
4263      * A specialized version of `_.pick` which picks `object` properties specified
4264      * by `props`.
4265      *
4266      * @private
4267      * @param {Object} object The source object.
4268      * @param {string[]} props The property names to pick.
4269      * @returns {Object} Returns the new object.
4270      */
4271     function pickByArray(object, props) {
4272       object = toObject(object);
4273
4274       var index = -1,
4275           length = props.length,
4276           result = {};
4277
4278       while (++index < length) {
4279         var key = props[index];
4280         if (key in object) {
4281           result[key] = object[key];
4282         }
4283       }
4284       return result;
4285     }
4286
4287     /**
4288      * A specialized version of `_.pick` which picks `object` properties `predicate`
4289      * returns truthy for.
4290      *
4291      * @private
4292      * @param {Object} object The source object.
4293      * @param {Function} predicate The function invoked per iteration.
4294      * @returns {Object} Returns the new object.
4295      */
4296     function pickByCallback(object, predicate) {
4297       var result = {};
4298       baseForIn(object, function(value, key, object) {
4299         if (predicate(value, key, object)) {
4300           result[key] = value;
4301         }
4302       });
4303       return result;
4304     }
4305
4306     /**
4307      * Reorder `array` according to the specified indexes where the element at
4308      * the first index is assigned as the first element, the element at
4309      * the second index is assigned as the second element, and so on.
4310      *
4311      * @private
4312      * @param {Array} array The array to reorder.
4313      * @param {Array} indexes The arranged array indexes.
4314      * @returns {Array} Returns `array`.
4315      */
4316     function reorder(array, indexes) {
4317       var arrLength = array.length,
4318           length = nativeMin(indexes.length, arrLength),
4319           oldArray = arrayCopy(array);
4320
4321       while (length--) {
4322         var index = indexes[length];
4323         array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
4324       }
4325       return array;
4326     }
4327
4328     /**
4329      * Sets metadata for `func`.
4330      *
4331      * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
4332      * period of time, it will trip its breaker and transition to an identity function
4333      * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
4334      * for more details.
4335      *
4336      * @private
4337      * @param {Function} func The function to associate metadata with.
4338      * @param {*} data The metadata.
4339      * @returns {Function} Returns `func`.
4340      */
4341     var setData = (function() {
4342       var count = 0,
4343           lastCalled = 0;
4344
4345       return function(key, value) {
4346         var stamp = now(),
4347             remaining = HOT_SPAN - (stamp - lastCalled);
4348
4349         lastCalled = stamp;
4350         if (remaining > 0) {
4351           if (++count >= HOT_COUNT) {
4352             return key;
4353           }
4354         } else {
4355           count = 0;
4356         }
4357         return baseSetData(key, value);
4358       };
4359     }());
4360
4361     /**
4362      * A fallback implementation of `Object.keys` which creates an array of the
4363      * own enumerable property names of `object`.
4364      *
4365      * @private
4366      * @param {Object} object The object to query.
4367      * @returns {Array} Returns the array of property names.
4368      */
4369     function shimKeys(object) {
4370       var props = keysIn(object),
4371           propsLength = props.length,
4372           length = propsLength && object.length;
4373
4374       var allowIndexes = !!length && isLength(length) &&
4375         (isArray(object) || isArguments(object));
4376
4377       var index = -1,
4378           result = [];
4379
4380       while (++index < propsLength) {
4381         var key = props[index];
4382         if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
4383           result.push(key);
4384         }
4385       }
4386       return result;
4387     }
4388
4389     /**
4390      * Converts `value` to an array-like object if it's not one.
4391      *
4392      * @private
4393      * @param {*} value The value to process.
4394      * @returns {Array|Object} Returns the array-like object.
4395      */
4396     function toIterable(value) {
4397       if (value == null) {
4398         return [];
4399       }
4400       if (!isArrayLike(value)) {
4401         return values(value);
4402       }
4403       return isObject(value) ? value : Object(value);
4404     }
4405
4406     /**
4407      * Converts `value` to an object if it's not one.
4408      *
4409      * @private
4410      * @param {*} value The value to process.
4411      * @returns {Object} Returns the object.
4412      */
4413     function toObject(value) {
4414       return isObject(value) ? value : Object(value);
4415     }
4416
4417     /**
4418      * Converts `value` to property path array if it's not one.
4419      *
4420      * @private
4421      * @param {*} value The value to process.
4422      * @returns {Array} Returns the property path array.
4423      */
4424     function toPath(value) {
4425       if (isArray(value)) {
4426         return value;
4427       }
4428       var result = [];
4429       baseToString(value).replace(rePropName, function(match, number, quote, string) {
4430         result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
4431       });
4432       return result;
4433     }
4434
4435     /**
4436      * Creates a clone of `wrapper`.
4437      *
4438      * @private
4439      * @param {Object} wrapper The wrapper to clone.
4440      * @returns {Object} Returns the cloned wrapper.
4441      */
4442     function wrapperClone(wrapper) {
4443       return wrapper instanceof LazyWrapper
4444         ? wrapper.clone()
4445         : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
4446     }
4447
4448     /*------------------------------------------------------------------------*/
4449
4450     /**
4451      * Creates an array of elements split into groups the length of `size`.
4452      * If `collection` can't be split evenly, the final chunk will be the remaining
4453      * elements.
4454      *
4455      * @static
4456      * @memberOf _
4457      * @category Array
4458      * @param {Array} array The array to process.
4459      * @param {number} [size=1] The length of each chunk.
4460      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4461      * @returns {Array} Returns the new array containing chunks.
4462      * @example
4463      *
4464      * _.chunk(['a', 'b', 'c', 'd'], 2);
4465      * // => [['a', 'b'], ['c', 'd']]
4466      *
4467      * _.chunk(['a', 'b', 'c', 'd'], 3);
4468      * // => [['a', 'b', 'c'], ['d']]
4469      */
4470     function chunk(array, size, guard) {
4471       if (guard ? isIterateeCall(array, size, guard) : size == null) {
4472         size = 1;
4473       } else {
4474         size = nativeMax(nativeFloor(size) || 1, 1);
4475       }
4476       var index = 0,
4477           length = array ? array.length : 0,
4478           resIndex = -1,
4479           result = Array(nativeCeil(length / size));
4480
4481       while (index < length) {
4482         result[++resIndex] = baseSlice(array, index, (index += size));
4483       }
4484       return result;
4485     }
4486
4487     /**
4488      * Creates an array with all falsey values removed. The values `false`, `null`,
4489      * `0`, `""`, `undefined`, and `NaN` are falsey.
4490      *
4491      * @static
4492      * @memberOf _
4493      * @category Array
4494      * @param {Array} array The array to compact.
4495      * @returns {Array} Returns the new array of filtered values.
4496      * @example
4497      *
4498      * _.compact([0, 1, false, 2, '', 3]);
4499      * // => [1, 2, 3]
4500      */
4501     function compact(array) {
4502       var index = -1,
4503           length = array ? array.length : 0,
4504           resIndex = -1,
4505           result = [];
4506
4507       while (++index < length) {
4508         var value = array[index];
4509         if (value) {
4510           result[++resIndex] = value;
4511         }
4512       }
4513       return result;
4514     }
4515
4516     /**
4517      * Creates an array of unique `array` values not included in the other
4518      * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4519      * for equality comparisons.
4520      *
4521      * @static
4522      * @memberOf _
4523      * @category Array
4524      * @param {Array} array The array to inspect.
4525      * @param {...Array} [values] The arrays of values to exclude.
4526      * @returns {Array} Returns the new array of filtered values.
4527      * @example
4528      *
4529      * _.difference([1, 2, 3], [4, 2]);
4530      * // => [1, 3]
4531      */
4532     var difference = restParam(function(array, values) {
4533       return (isObjectLike(array) && isArrayLike(array))
4534         ? baseDifference(array, baseFlatten(values, false, true))
4535         : [];
4536     });
4537
4538     /**
4539      * Creates a slice of `array` with `n` elements dropped from the beginning.
4540      *
4541      * @static
4542      * @memberOf _
4543      * @category Array
4544      * @param {Array} array The array to query.
4545      * @param {number} [n=1] The number of elements to drop.
4546      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4547      * @returns {Array} Returns the slice of `array`.
4548      * @example
4549      *
4550      * _.drop([1, 2, 3]);
4551      * // => [2, 3]
4552      *
4553      * _.drop([1, 2, 3], 2);
4554      * // => [3]
4555      *
4556      * _.drop([1, 2, 3], 5);
4557      * // => []
4558      *
4559      * _.drop([1, 2, 3], 0);
4560      * // => [1, 2, 3]
4561      */
4562     function drop(array, n, guard) {
4563       var length = array ? array.length : 0;
4564       if (!length) {
4565         return [];
4566       }
4567       if (guard ? isIterateeCall(array, n, guard) : n == null) {
4568         n = 1;
4569       }
4570       return baseSlice(array, n < 0 ? 0 : n);
4571     }
4572
4573     /**
4574      * Creates a slice of `array` with `n` elements dropped from the end.
4575      *
4576      * @static
4577      * @memberOf _
4578      * @category Array
4579      * @param {Array} array The array to query.
4580      * @param {number} [n=1] The number of elements to drop.
4581      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4582      * @returns {Array} Returns the slice of `array`.
4583      * @example
4584      *
4585      * _.dropRight([1, 2, 3]);
4586      * // => [1, 2]
4587      *
4588      * _.dropRight([1, 2, 3], 2);
4589      * // => [1]
4590      *
4591      * _.dropRight([1, 2, 3], 5);
4592      * // => []
4593      *
4594      * _.dropRight([1, 2, 3], 0);
4595      * // => [1, 2, 3]
4596      */
4597     function dropRight(array, n, guard) {
4598       var length = array ? array.length : 0;
4599       if (!length) {
4600         return [];
4601       }
4602       if (guard ? isIterateeCall(array, n, guard) : n == null) {
4603         n = 1;
4604       }
4605       n = length - (+n || 0);
4606       return baseSlice(array, 0, n < 0 ? 0 : n);
4607     }
4608
4609     /**
4610      * Creates a slice of `array` excluding elements dropped from the end.
4611      * Elements are dropped until `predicate` returns falsey. The predicate is
4612      * bound to `thisArg` and invoked with three arguments: (value, index, array).
4613      *
4614      * If a property name is provided for `predicate` the created `_.property`
4615      * style callback returns the property value of the given element.
4616      *
4617      * If a value is also provided for `thisArg` the created `_.matchesProperty`
4618      * style callback returns `true` for elements that have a matching property
4619      * value, else `false`.
4620      *
4621      * If an object is provided for `predicate` the created `_.matches` style
4622      * callback returns `true` for elements that match the properties of the given
4623      * object, else `false`.
4624      *
4625      * @static
4626      * @memberOf _
4627      * @category Array
4628      * @param {Array} array The array to query.
4629      * @param {Function|Object|string} [predicate=_.identity] The function invoked
4630      *  per iteration.
4631      * @param {*} [thisArg] The `this` binding of `predicate`.
4632      * @returns {Array} Returns the slice of `array`.
4633      * @example
4634      *
4635      * _.dropRightWhile([1, 2, 3], function(n) {
4636      *   return n > 1;
4637      * });
4638      * // => [1]
4639      *
4640      * var users = [
4641      *   { 'user': 'barney',  'active': true },
4642      *   { 'user': 'fred',    'active': false },
4643      *   { 'user': 'pebbles', 'active': false }
4644      * ];
4645      *
4646      * // using the `_.matches` callback shorthand
4647      * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
4648      * // => ['barney', 'fred']
4649      *
4650      * // using the `_.matchesProperty` callback shorthand
4651      * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
4652      * // => ['barney']
4653      *
4654      * // using the `_.property` callback shorthand
4655      * _.pluck(_.dropRightWhile(users, 'active'), 'user');
4656      * // => ['barney', 'fred', 'pebbles']
4657      */
4658     function dropRightWhile(array, predicate, thisArg) {
4659       return (array && array.length)
4660         ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
4661         : [];
4662     }
4663
4664     /**
4665      * Creates a slice of `array` excluding elements dropped from the beginning.
4666      * Elements are dropped until `predicate` returns falsey. The predicate is
4667      * bound to `thisArg` and invoked with three arguments: (value, index, array).
4668      *
4669      * If a property name is provided for `predicate` the created `_.property`
4670      * style callback returns the property value of the given element.
4671      *
4672      * If a value is also provided for `thisArg` the created `_.matchesProperty`
4673      * style callback returns `true` for elements that have a matching property
4674      * value, else `false`.
4675      *
4676      * If an object is provided for `predicate` the created `_.matches` style
4677      * callback returns `true` for elements that have the properties of the given
4678      * object, else `false`.
4679      *
4680      * @static
4681      * @memberOf _
4682      * @category Array
4683      * @param {Array} array The array to query.
4684      * @param {Function|Object|string} [predicate=_.identity] The function invoked
4685      *  per iteration.
4686      * @param {*} [thisArg] The `this` binding of `predicate`.
4687      * @returns {Array} Returns the slice of `array`.
4688      * @example
4689      *
4690      * _.dropWhile([1, 2, 3], function(n) {
4691      *   return n < 3;
4692      * });
4693      * // => [3]
4694      *
4695      * var users = [
4696      *   { 'user': 'barney',  'active': false },
4697      *   { 'user': 'fred',    'active': false },
4698      *   { 'user': 'pebbles', 'active': true }
4699      * ];
4700      *
4701      * // using the `_.matches` callback shorthand
4702      * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
4703      * // => ['fred', 'pebbles']
4704      *
4705      * // using the `_.matchesProperty` callback shorthand
4706      * _.pluck(_.dropWhile(users, 'active', false), 'user');
4707      * // => ['pebbles']
4708      *
4709      * // using the `_.property` callback shorthand
4710      * _.pluck(_.dropWhile(users, 'active'), 'user');
4711      * // => ['barney', 'fred', 'pebbles']
4712      */
4713     function dropWhile(array, predicate, thisArg) {
4714       return (array && array.length)
4715         ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
4716         : [];
4717     }
4718
4719     /**
4720      * Fills elements of `array` with `value` from `start` up to, but not
4721      * including, `end`.
4722      *
4723      * **Note:** This method mutates `array`.
4724      *
4725      * @static
4726      * @memberOf _
4727      * @category Array
4728      * @param {Array} array The array to fill.
4729      * @param {*} value The value to fill `array` with.
4730      * @param {number} [start=0] The start position.
4731      * @param {number} [end=array.length] The end position.
4732      * @returns {Array} Returns `array`.
4733      * @example
4734      *
4735      * var array = [1, 2, 3];
4736      *
4737      * _.fill(array, 'a');
4738      * console.log(array);
4739      * // => ['a', 'a', 'a']
4740      *
4741      * _.fill(Array(3), 2);
4742      * // => [2, 2, 2]
4743      *
4744      * _.fill([4, 6, 8], '*', 1, 2);
4745      * // => [4, '*', 8]
4746      */
4747     function fill(array, value, start, end) {
4748       var length = array ? array.length : 0;
4749       if (!length) {
4750         return [];
4751       }
4752       if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
4753         start = 0;
4754         end = length;
4755       }
4756       return baseFill(array, value, start, end);
4757     }
4758
4759     /**
4760      * This method is like `_.find` except that it returns the index of the first
4761      * element `predicate` returns truthy for instead of the element itself.
4762      *
4763      * If a property name is provided for `predicate` the created `_.property`
4764      * style callback returns the property value of the given element.
4765      *
4766      * If a value is also provided for `thisArg` the created `_.matchesProperty`
4767      * style callback returns `true` for elements that have a matching property
4768      * value, else `false`.
4769      *
4770      * If an object is provided for `predicate` the created `_.matches` style
4771      * callback returns `true` for elements that have the properties of the given
4772      * object, else `false`.
4773      *
4774      * @static
4775      * @memberOf _
4776      * @category Array
4777      * @param {Array} array The array to search.
4778      * @param {Function|Object|string} [predicate=_.identity] The function invoked
4779      *  per iteration.
4780      * @param {*} [thisArg] The `this` binding of `predicate`.
4781      * @returns {number} Returns the index of the found element, else `-1`.
4782      * @example
4783      *
4784      * var users = [
4785      *   { 'user': 'barney',  'active': false },
4786      *   { 'user': 'fred',    'active': false },
4787      *   { 'user': 'pebbles', 'active': true }
4788      * ];
4789      *
4790      * _.findIndex(users, function(chr) {
4791      *   return chr.user == 'barney';
4792      * });
4793      * // => 0
4794      *
4795      * // using the `_.matches` callback shorthand
4796      * _.findIndex(users, { 'user': 'fred', 'active': false });
4797      * // => 1
4798      *
4799      * // using the `_.matchesProperty` callback shorthand
4800      * _.findIndex(users, 'active', false);
4801      * // => 0
4802      *
4803      * // using the `_.property` callback shorthand
4804      * _.findIndex(users, 'active');
4805      * // => 2
4806      */
4807     var findIndex = createFindIndex();
4808
4809     /**
4810      * This method is like `_.findIndex` except that it iterates over elements
4811      * of `collection` from right to left.
4812      *
4813      * If a property name is provided for `predicate` the created `_.property`
4814      * style callback returns the property value of the given element.
4815      *
4816      * If a value is also provided for `thisArg` the created `_.matchesProperty`
4817      * style callback returns `true` for elements that have a matching property
4818      * value, else `false`.
4819      *
4820      * If an object is provided for `predicate` the created `_.matches` style
4821      * callback returns `true` for elements that have the properties of the given
4822      * object, else `false`.
4823      *
4824      * @static
4825      * @memberOf _
4826      * @category Array
4827      * @param {Array} array The array to search.
4828      * @param {Function|Object|string} [predicate=_.identity] The function invoked
4829      *  per iteration.
4830      * @param {*} [thisArg] The `this` binding of `predicate`.
4831      * @returns {number} Returns the index of the found element, else `-1`.
4832      * @example
4833      *
4834      * var users = [
4835      *   { 'user': 'barney',  'active': true },
4836      *   { 'user': 'fred',    'active': false },
4837      *   { 'user': 'pebbles', 'active': false }
4838      * ];
4839      *
4840      * _.findLastIndex(users, function(chr) {
4841      *   return chr.user == 'pebbles';
4842      * });
4843      * // => 2
4844      *
4845      * // using the `_.matches` callback shorthand
4846      * _.findLastIndex(users, { 'user': 'barney', 'active': true });
4847      * // => 0
4848      *
4849      * // using the `_.matchesProperty` callback shorthand
4850      * _.findLastIndex(users, 'active', false);
4851      * // => 2
4852      *
4853      * // using the `_.property` callback shorthand
4854      * _.findLastIndex(users, 'active');
4855      * // => 0
4856      */
4857     var findLastIndex = createFindIndex(true);
4858
4859     /**
4860      * Gets the first element of `array`.
4861      *
4862      * @static
4863      * @memberOf _
4864      * @alias head
4865      * @category Array
4866      * @param {Array} array The array to query.
4867      * @returns {*} Returns the first element of `array`.
4868      * @example
4869      *
4870      * _.first([1, 2, 3]);
4871      * // => 1
4872      *
4873      * _.first([]);
4874      * // => undefined
4875      */
4876     function first(array) {
4877       return array ? array[0] : undefined;
4878     }
4879
4880     /**
4881      * Flattens a nested array. If `isDeep` is `true` the array is recursively
4882      * flattened, otherwise it is only flattened a single level.
4883      *
4884      * @static
4885      * @memberOf _
4886      * @category Array
4887      * @param {Array} array The array to flatten.
4888      * @param {boolean} [isDeep] Specify a deep flatten.
4889      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4890      * @returns {Array} Returns the new flattened array.
4891      * @example
4892      *
4893      * _.flatten([1, [2, 3, [4]]]);
4894      * // => [1, 2, 3, [4]]
4895      *
4896      * // using `isDeep`
4897      * _.flatten([1, [2, 3, [4]]], true);
4898      * // => [1, 2, 3, 4]
4899      */
4900     function flatten(array, isDeep, guard) {
4901       var length = array ? array.length : 0;
4902       if (guard && isIterateeCall(array, isDeep, guard)) {
4903         isDeep = false;
4904       }
4905       return length ? baseFlatten(array, isDeep) : [];
4906     }
4907
4908     /**
4909      * Recursively flattens a nested array.
4910      *
4911      * @static
4912      * @memberOf _
4913      * @category Array
4914      * @param {Array} array The array to recursively flatten.
4915      * @returns {Array} Returns the new flattened array.
4916      * @example
4917      *
4918      * _.flattenDeep([1, [2, 3, [4]]]);
4919      * // => [1, 2, 3, 4]
4920      */
4921     function flattenDeep(array) {
4922       var length = array ? array.length : 0;
4923       return length ? baseFlatten(array, true) : [];
4924     }
4925
4926     /**
4927      * Gets the index at which the first occurrence of `value` is found in `array`
4928      * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4929      * for equality comparisons. If `fromIndex` is negative, it is used as the offset
4930      * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
4931      * performs a faster binary search.
4932      *
4933      * @static
4934      * @memberOf _
4935      * @category Array
4936      * @param {Array} array The array to search.
4937      * @param {*} value The value to search for.
4938      * @param {boolean|number} [fromIndex=0] The index to search from or `true`
4939      *  to perform a binary search on a sorted array.
4940      * @returns {number} Returns the index of the matched value, else `-1`.
4941      * @example
4942      *
4943      * _.indexOf([1, 2, 1, 2], 2);
4944      * // => 1
4945      *
4946      * // using `fromIndex`
4947      * _.indexOf([1, 2, 1, 2], 2, 2);
4948      * // => 3
4949      *
4950      * // performing a binary search
4951      * _.indexOf([1, 1, 2, 2], 2, true);
4952      * // => 2
4953      */
4954     function indexOf(array, value, fromIndex) {
4955       var length = array ? array.length : 0;
4956       if (!length) {
4957         return -1;
4958       }
4959       if (typeof fromIndex == 'number') {
4960         fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
4961       } else if (fromIndex) {
4962         var index = binaryIndex(array, value);
4963         if (index < length &&
4964             (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
4965           return index;
4966         }
4967         return -1;
4968       }
4969       return baseIndexOf(array, value, fromIndex || 0);
4970     }
4971
4972     /**
4973      * Gets all but the last element of `array`.
4974      *
4975      * @static
4976      * @memberOf _
4977      * @category Array
4978      * @param {Array} array The array to query.
4979      * @returns {Array} Returns the slice of `array`.
4980      * @example
4981      *
4982      * _.initial([1, 2, 3]);
4983      * // => [1, 2]
4984      */
4985     function initial(array) {
4986       return dropRight(array, 1);
4987     }
4988
4989     /**
4990      * Creates an array of unique values that are included in all of the provided
4991      * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4992      * for equality comparisons.
4993      *
4994      * @static
4995      * @memberOf _
4996      * @category Array
4997      * @param {...Array} [arrays] The arrays to inspect.
4998      * @returns {Array} Returns the new array of shared values.
4999      * @example
5000      * _.intersection([1, 2], [4, 2], [2, 1]);
5001      * // => [2]
5002      */
5003     var intersection = restParam(function(arrays) {
5004       var othLength = arrays.length,
5005           othIndex = othLength,
5006           caches = Array(length),
5007           indexOf = getIndexOf(),
5008           isCommon = indexOf == baseIndexOf,
5009           result = [];
5010
5011       while (othIndex--) {
5012         var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
5013         caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
5014       }
5015       var array = arrays[0],
5016           index = -1,
5017           length = array ? array.length : 0,
5018           seen = caches[0];
5019
5020       outer:
5021       while (++index < length) {
5022         value = array[index];
5023         if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
5024           var othIndex = othLength;
5025           while (--othIndex) {
5026             var cache = caches[othIndex];
5027             if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
5028               continue outer;
5029             }
5030           }
5031           if (seen) {
5032             seen.push(value);
5033           }
5034           result.push(value);
5035         }
5036       }
5037       return result;
5038     });
5039
5040     /**
5041      * Gets the last element of `array`.
5042      *
5043      * @static
5044      * @memberOf _
5045      * @category Array
5046      * @param {Array} array The array to query.
5047      * @returns {*} Returns the last element of `array`.
5048      * @example
5049      *
5050      * _.last([1, 2, 3]);
5051      * // => 3
5052      */
5053     function last(array) {
5054       var length = array ? array.length : 0;
5055       return length ? array[length - 1] : undefined;
5056     }
5057
5058     /**
5059      * This method is like `_.indexOf` except that it iterates over elements of
5060      * `array` from right to left.
5061      *
5062      * @static
5063      * @memberOf _
5064      * @category Array
5065      * @param {Array} array The array to search.
5066      * @param {*} value The value to search for.
5067      * @param {boolean|number} [fromIndex=array.length-1] The index to search from
5068      *  or `true` to perform a binary search on a sorted array.
5069      * @returns {number} Returns the index of the matched value, else `-1`.
5070      * @example
5071      *
5072      * _.lastIndexOf([1, 2, 1, 2], 2);
5073      * // => 3
5074      *
5075      * // using `fromIndex`
5076      * _.lastIndexOf([1, 2, 1, 2], 2, 2);
5077      * // => 1
5078      *
5079      * // performing a binary search
5080      * _.lastIndexOf([1, 1, 2, 2], 2, true);
5081      * // => 3
5082      */
5083     function lastIndexOf(array, value, fromIndex) {
5084       var length = array ? array.length : 0;
5085       if (!length) {
5086         return -1;
5087       }
5088       var index = length;
5089       if (typeof fromIndex == 'number') {
5090         index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
5091       } else if (fromIndex) {
5092         index = binaryIndex(array, value, true) - 1;
5093         var other = array[index];
5094         if (value === value ? (value === other) : (other !== other)) {
5095           return index;
5096         }
5097         return -1;
5098       }
5099       if (value !== value) {
5100         return indexOfNaN(array, index, true);
5101       }
5102       while (index--) {
5103         if (array[index] === value) {
5104           return index;
5105         }
5106       }
5107       return -1;
5108     }
5109
5110     /**
5111      * Removes all provided values from `array` using
5112      * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5113      * for equality comparisons.
5114      *
5115      * **Note:** Unlike `_.without`, this method mutates `array`.
5116      *
5117      * @static
5118      * @memberOf _
5119      * @category Array
5120      * @param {Array} array The array to modify.
5121      * @param {...*} [values] The values to remove.
5122      * @returns {Array} Returns `array`.
5123      * @example
5124      *
5125      * var array = [1, 2, 3, 1, 2, 3];
5126      *
5127      * _.pull(array, 2, 3);
5128      * console.log(array);
5129      * // => [1, 1]
5130      */
5131     function pull() {
5132       var args = arguments,
5133           array = args[0];
5134
5135       if (!(array && array.length)) {
5136         return array;
5137       }
5138       var index = 0,
5139           indexOf = getIndexOf(),
5140           length = args.length;
5141
5142       while (++index < length) {
5143         var fromIndex = 0,
5144             value = args[index];
5145
5146         while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
5147           splice.call(array, fromIndex, 1);
5148         }
5149       }
5150       return array;
5151     }
5152
5153     /**
5154      * Removes elements from `array` corresponding to the given indexes and returns
5155      * an array of the removed elements. Indexes may be specified as an array of
5156      * indexes or as individual arguments.
5157      *
5158      * **Note:** Unlike `_.at`, this method mutates `array`.
5159      *
5160      * @static
5161      * @memberOf _
5162      * @category Array
5163      * @param {Array} array The array to modify.
5164      * @param {...(number|number[])} [indexes] The indexes of elements to remove,
5165      *  specified as individual indexes or arrays of indexes.
5166      * @returns {Array} Returns the new array of removed elements.
5167      * @example
5168      *
5169      * var array = [5, 10, 15, 20];
5170      * var evens = _.pullAt(array, 1, 3);
5171      *
5172      * console.log(array);
5173      * // => [5, 15]
5174      *
5175      * console.log(evens);
5176      * // => [10, 20]
5177      */
5178     var pullAt = restParam(function(array, indexes) {
5179       indexes = baseFlatten(indexes);
5180
5181       var result = baseAt(array, indexes);
5182       basePullAt(array, indexes.sort(baseCompareAscending));
5183       return result;
5184     });
5185
5186     /**
5187      * Removes all elements from `array` that `predicate` returns truthy for
5188      * and returns an array of the removed elements. The predicate is bound to
5189      * `thisArg` and invoked with three arguments: (value, index, array).
5190      *
5191      * If a property name is provided for `predicate` the created `_.property`
5192      * style callback returns the property value of the given element.
5193      *
5194      * If a value is also provided for `thisArg` the created `_.matchesProperty`
5195      * style callback returns `true` for elements that have a matching property
5196      * value, else `false`.
5197      *
5198      * If an object is provided for `predicate` the created `_.matches` style
5199      * callback returns `true` for elements that have the properties of the given
5200      * object, else `false`.
5201      *
5202      * **Note:** Unlike `_.filter`, this method mutates `array`.
5203      *
5204      * @static
5205      * @memberOf _
5206      * @category Array
5207      * @param {Array} array The array to modify.
5208      * @param {Function|Object|string} [predicate=_.identity] The function invoked
5209      *  per iteration.
5210      * @param {*} [thisArg] The `this` binding of `predicate`.
5211      * @returns {Array} Returns the new array of removed elements.
5212      * @example
5213      *
5214      * var array = [1, 2, 3, 4];
5215      * var evens = _.remove(array, function(n) {
5216      *   return n % 2 == 0;
5217      * });
5218      *
5219      * console.log(array);
5220      * // => [1, 3]
5221      *
5222      * console.log(evens);
5223      * // => [2, 4]
5224      */
5225     function remove(array, predicate, thisArg) {
5226       var result = [];
5227       if (!(array && array.length)) {
5228         return result;
5229       }
5230       var index = -1,
5231           indexes = [],
5232           length = array.length;
5233
5234       predicate = getCallback(predicate, thisArg, 3);
5235       while (++index < length) {
5236         var value = array[index];
5237         if (predicate(value, index, array)) {
5238           result.push(value);
5239           indexes.push(index);
5240         }
5241       }
5242       basePullAt(array, indexes);
5243       return result;
5244     }
5245
5246     /**
5247      * Gets all but the first element of `array`.
5248      *
5249      * @static
5250      * @memberOf _
5251      * @alias tail
5252      * @category Array
5253      * @param {Array} array The array to query.
5254      * @returns {Array} Returns the slice of `array`.
5255      * @example
5256      *
5257      * _.rest([1, 2, 3]);
5258      * // => [2, 3]
5259      */
5260     function rest(array) {
5261       return drop(array, 1);
5262     }
5263
5264     /**
5265      * Creates a slice of `array` from `start` up to, but not including, `end`.
5266      *
5267      * **Note:** This method is used instead of `Array#slice` to support node
5268      * lists in IE < 9 and to ensure dense arrays are returned.
5269      *
5270      * @static
5271      * @memberOf _
5272      * @category Array
5273      * @param {Array} array The array to slice.
5274      * @param {number} [start=0] The start position.
5275      * @param {number} [end=array.length] The end position.
5276      * @returns {Array} Returns the slice of `array`.
5277      */
5278     function slice(array, start, end) {
5279       var length = array ? array.length : 0;
5280       if (!length) {
5281         return [];
5282       }
5283       if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
5284         start = 0;
5285         end = length;
5286       }
5287       return baseSlice(array, start, end);
5288     }
5289
5290     /**
5291      * Uses a binary search to determine the lowest index at which `value` should
5292      * be inserted into `array` in order to maintain its sort order. If an iteratee
5293      * function is provided it is invoked for `value` and each element of `array`
5294      * to compute their sort ranking. The iteratee is bound to `thisArg` and
5295      * invoked with one argument; (value).
5296      *
5297      * If a property name is provided for `iteratee` the created `_.property`
5298      * style callback returns the property value of the given element.
5299      *
5300      * If a value is also provided for `thisArg` the created `_.matchesProperty`
5301      * style callback returns `true` for elements that have a matching property
5302      * value, else `false`.
5303      *
5304      * If an object is provided for `iteratee` the created `_.matches` style
5305      * callback returns `true` for elements that have the properties of the given
5306      * object, else `false`.
5307      *
5308      * @static
5309      * @memberOf _
5310      * @category Array
5311      * @param {Array} array The sorted array to inspect.
5312      * @param {*} value The value to evaluate.
5313      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5314      *  per iteration.
5315      * @param {*} [thisArg] The `this` binding of `iteratee`.
5316      * @returns {number} Returns the index at which `value` should be inserted
5317      *  into `array`.
5318      * @example
5319      *
5320      * _.sortedIndex([30, 50], 40);
5321      * // => 1
5322      *
5323      * _.sortedIndex([4, 4, 5, 5], 5);
5324      * // => 2
5325      *
5326      * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
5327      *
5328      * // using an iteratee function
5329      * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
5330      *   return this.data[word];
5331      * }, dict);
5332      * // => 1
5333      *
5334      * // using the `_.property` callback shorthand
5335      * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
5336      * // => 1
5337      */
5338     var sortedIndex = createSortedIndex();
5339
5340     /**
5341      * This method is like `_.sortedIndex` except that it returns the highest
5342      * index at which `value` should be inserted into `array` in order to
5343      * maintain its sort order.
5344      *
5345      * @static
5346      * @memberOf _
5347      * @category Array
5348      * @param {Array} array The sorted array to inspect.
5349      * @param {*} value The value to evaluate.
5350      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5351      *  per iteration.
5352      * @param {*} [thisArg] The `this` binding of `iteratee`.
5353      * @returns {number} Returns the index at which `value` should be inserted
5354      *  into `array`.
5355      * @example
5356      *
5357      * _.sortedLastIndex([4, 4, 5, 5], 5);
5358      * // => 4
5359      */
5360     var sortedLastIndex = createSortedIndex(true);
5361
5362     /**
5363      * Creates a slice of `array` with `n` elements taken from the beginning.
5364      *
5365      * @static
5366      * @memberOf _
5367      * @category Array
5368      * @param {Array} array The array to query.
5369      * @param {number} [n=1] The number of elements to take.
5370      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5371      * @returns {Array} Returns the slice of `array`.
5372      * @example
5373      *
5374      * _.take([1, 2, 3]);
5375      * // => [1]
5376      *
5377      * _.take([1, 2, 3], 2);
5378      * // => [1, 2]
5379      *
5380      * _.take([1, 2, 3], 5);
5381      * // => [1, 2, 3]
5382      *
5383      * _.take([1, 2, 3], 0);
5384      * // => []
5385      */
5386     function take(array, n, guard) {
5387       var length = array ? array.length : 0;
5388       if (!length) {
5389         return [];
5390       }
5391       if (guard ? isIterateeCall(array, n, guard) : n == null) {
5392         n = 1;
5393       }
5394       return baseSlice(array, 0, n < 0 ? 0 : n);
5395     }
5396
5397     /**
5398      * Creates a slice of `array` with `n` elements taken from the end.
5399      *
5400      * @static
5401      * @memberOf _
5402      * @category Array
5403      * @param {Array} array The array to query.
5404      * @param {number} [n=1] The number of elements to take.
5405      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5406      * @returns {Array} Returns the slice of `array`.
5407      * @example
5408      *
5409      * _.takeRight([1, 2, 3]);
5410      * // => [3]
5411      *
5412      * _.takeRight([1, 2, 3], 2);
5413      * // => [2, 3]
5414      *
5415      * _.takeRight([1, 2, 3], 5);
5416      * // => [1, 2, 3]
5417      *
5418      * _.takeRight([1, 2, 3], 0);
5419      * // => []
5420      */
5421     function takeRight(array, n, guard) {
5422       var length = array ? array.length : 0;
5423       if (!length) {
5424         return [];
5425       }
5426       if (guard ? isIterateeCall(array, n, guard) : n == null) {
5427         n = 1;
5428       }
5429       n = length - (+n || 0);
5430       return baseSlice(array, n < 0 ? 0 : n);
5431     }
5432
5433     /**
5434      * Creates a slice of `array` with elements taken from the end. Elements are
5435      * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
5436      * and invoked with three arguments: (value, index, array).
5437      *
5438      * If a property name is provided for `predicate` the created `_.property`
5439      * style callback returns the property value of the given element.
5440      *
5441      * If a value is also provided for `thisArg` the created `_.matchesProperty`
5442      * style callback returns `true` for elements that have a matching property
5443      * value, else `false`.
5444      *
5445      * If an object is provided for `predicate` the created `_.matches` style
5446      * callback returns `true` for elements that have the properties of the given
5447      * object, else `false`.
5448      *
5449      * @static
5450      * @memberOf _
5451      * @category Array
5452      * @param {Array} array The array to query.
5453      * @param {Function|Object|string} [predicate=_.identity] The function invoked
5454      *  per iteration.
5455      * @param {*} [thisArg] The `this` binding of `predicate`.
5456      * @returns {Array} Returns the slice of `array`.
5457      * @example
5458      *
5459      * _.takeRightWhile([1, 2, 3], function(n) {
5460      *   return n > 1;
5461      * });
5462      * // => [2, 3]
5463      *
5464      * var users = [
5465      *   { 'user': 'barney',  'active': true },
5466      *   { 'user': 'fred',    'active': false },
5467      *   { 'user': 'pebbles', 'active': false }
5468      * ];
5469      *
5470      * // using the `_.matches` callback shorthand
5471      * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
5472      * // => ['pebbles']
5473      *
5474      * // using the `_.matchesProperty` callback shorthand
5475      * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
5476      * // => ['fred', 'pebbles']
5477      *
5478      * // using the `_.property` callback shorthand
5479      * _.pluck(_.takeRightWhile(users, 'active'), 'user');
5480      * // => []
5481      */
5482     function takeRightWhile(array, predicate, thisArg) {
5483       return (array && array.length)
5484         ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
5485         : [];
5486     }
5487
5488     /**
5489      * Creates a slice of `array` with elements taken from the beginning. Elements
5490      * are taken until `predicate` returns falsey. The predicate is bound to
5491      * `thisArg` and invoked with three arguments: (value, index, array).
5492      *
5493      * If a property name is provided for `predicate` the created `_.property`
5494      * style callback returns the property value of the given element.
5495      *
5496      * If a value is also provided for `thisArg` the created `_.matchesProperty`
5497      * style callback returns `true` for elements that have a matching property
5498      * value, else `false`.
5499      *
5500      * If an object is provided for `predicate` the created `_.matches` style
5501      * callback returns `true` for elements that have the properties of the given
5502      * object, else `false`.
5503      *
5504      * @static
5505      * @memberOf _
5506      * @category Array
5507      * @param {Array} array The array to query.
5508      * @param {Function|Object|string} [predicate=_.identity] The function invoked
5509      *  per iteration.
5510      * @param {*} [thisArg] The `this` binding of `predicate`.
5511      * @returns {Array} Returns the slice of `array`.
5512      * @example
5513      *
5514      * _.takeWhile([1, 2, 3], function(n) {
5515      *   return n < 3;
5516      * });
5517      * // => [1, 2]
5518      *
5519      * var users = [
5520      *   { 'user': 'barney',  'active': false },
5521      *   { 'user': 'fred',    'active': false},
5522      *   { 'user': 'pebbles', 'active': true }
5523      * ];
5524      *
5525      * // using the `_.matches` callback shorthand
5526      * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
5527      * // => ['barney']
5528      *
5529      * // using the `_.matchesProperty` callback shorthand
5530      * _.pluck(_.takeWhile(users, 'active', false), 'user');
5531      * // => ['barney', 'fred']
5532      *
5533      * // using the `_.property` callback shorthand
5534      * _.pluck(_.takeWhile(users, 'active'), 'user');
5535      * // => []
5536      */
5537     function takeWhile(array, predicate, thisArg) {
5538       return (array && array.length)
5539         ? baseWhile(array, getCallback(predicate, thisArg, 3))
5540         : [];
5541     }
5542
5543     /**
5544      * Creates an array of unique values, in order, from all of the provided arrays
5545      * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5546      * for equality comparisons.
5547      *
5548      * @static
5549      * @memberOf _
5550      * @category Array
5551      * @param {...Array} [arrays] The arrays to inspect.
5552      * @returns {Array} Returns the new array of combined values.
5553      * @example
5554      *
5555      * _.union([1, 2], [4, 2], [2, 1]);
5556      * // => [1, 2, 4]
5557      */
5558     var union = restParam(function(arrays) {
5559       return baseUniq(baseFlatten(arrays, false, true));
5560     });
5561
5562     /**
5563      * Creates a duplicate-free version of an array, using
5564      * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5565      * for equality comparisons, in which only the first occurence of each element
5566      * is kept. Providing `true` for `isSorted` performs a faster search algorithm
5567      * for sorted arrays. If an iteratee function is provided it is invoked for
5568      * each element in the array to generate the criterion by which uniqueness
5569      * is computed. The `iteratee` is bound to `thisArg` and invoked with three
5570      * arguments: (value, index, array).
5571      *
5572      * If a property name is provided for `iteratee` the created `_.property`
5573      * style callback returns the property value of the given element.
5574      *
5575      * If a value is also provided for `thisArg` the created `_.matchesProperty`
5576      * style callback returns `true` for elements that have a matching property
5577      * value, else `false`.
5578      *
5579      * If an object is provided for `iteratee` the created `_.matches` style
5580      * callback returns `true` for elements that have the properties of the given
5581      * object, else `false`.
5582      *
5583      * @static
5584      * @memberOf _
5585      * @alias unique
5586      * @category Array
5587      * @param {Array} array The array to inspect.
5588      * @param {boolean} [isSorted] Specify the array is sorted.
5589      * @param {Function|Object|string} [iteratee] The function invoked per iteration.
5590      * @param {*} [thisArg] The `this` binding of `iteratee`.
5591      * @returns {Array} Returns the new duplicate-value-free array.
5592      * @example
5593      *
5594      * _.uniq([2, 1, 2]);
5595      * // => [2, 1]
5596      *
5597      * // using `isSorted`
5598      * _.uniq([1, 1, 2], true);
5599      * // => [1, 2]
5600      *
5601      * // using an iteratee function
5602      * _.uniq([1, 2.5, 1.5, 2], function(n) {
5603      *   return this.floor(n);
5604      * }, Math);
5605      * // => [1, 2.5]
5606      *
5607      * // using the `_.property` callback shorthand
5608      * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
5609      * // => [{ 'x': 1 }, { 'x': 2 }]
5610      */
5611     function uniq(array, isSorted, iteratee, thisArg) {
5612       var length = array ? array.length : 0;
5613       if (!length) {
5614         return [];
5615       }
5616       if (isSorted != null && typeof isSorted != 'boolean') {
5617         thisArg = iteratee;
5618         iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
5619         isSorted = false;
5620       }
5621       var callback = getCallback();
5622       if (!(iteratee == null && callback === baseCallback)) {
5623         iteratee = callback(iteratee, thisArg, 3);
5624       }
5625       return (isSorted && getIndexOf() == baseIndexOf)
5626         ? sortedUniq(array, iteratee)
5627         : baseUniq(array, iteratee);
5628     }
5629
5630     /**
5631      * This method is like `_.zip` except that it accepts an array of grouped
5632      * elements and creates an array regrouping the elements to their pre-zip
5633      * configuration.
5634      *
5635      * @static
5636      * @memberOf _
5637      * @category Array
5638      * @param {Array} array The array of grouped elements to process.
5639      * @returns {Array} Returns the new array of regrouped elements.
5640      * @example
5641      *
5642      * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
5643      * // => [['fred', 30, true], ['barney', 40, false]]
5644      *
5645      * _.unzip(zipped);
5646      * // => [['fred', 'barney'], [30, 40], [true, false]]
5647      */
5648     function unzip(array) {
5649       if (!(array && array.length)) {
5650         return [];
5651       }
5652       var index = -1,
5653           length = 0;
5654
5655       array = arrayFilter(array, function(group) {
5656         if (isArrayLike(group)) {
5657           length = nativeMax(group.length, length);
5658           return true;
5659         }
5660       });
5661       var result = Array(length);
5662       while (++index < length) {
5663         result[index] = arrayMap(array, baseProperty(index));
5664       }
5665       return result;
5666     }
5667
5668     /**
5669      * This method is like `_.unzip` except that it accepts an iteratee to specify
5670      * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
5671      * and invoked with four arguments: (accumulator, value, index, group).
5672      *
5673      * @static
5674      * @memberOf _
5675      * @category Array
5676      * @param {Array} array The array of grouped elements to process.
5677      * @param {Function} [iteratee] The function to combine regrouped values.
5678      * @param {*} [thisArg] The `this` binding of `iteratee`.
5679      * @returns {Array} Returns the new array of regrouped elements.
5680      * @example
5681      *
5682      * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
5683      * // => [[1, 10, 100], [2, 20, 200]]
5684      *
5685      * _.unzipWith(zipped, _.add);
5686      * // => [3, 30, 300]
5687      */
5688     function unzipWith(array, iteratee, thisArg) {
5689       var length = array ? array.length : 0;
5690       if (!length) {
5691         return [];
5692       }
5693       var result = unzip(array);
5694       if (iteratee == null) {
5695         return result;
5696       }
5697       iteratee = bindCallback(iteratee, thisArg, 4);
5698       return arrayMap(result, function(group) {
5699         return arrayReduce(group, iteratee, undefined, true);
5700       });
5701     }
5702
5703     /**
5704      * Creates an array excluding all provided values using
5705      * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5706      * for equality comparisons.
5707      *
5708      * @static
5709      * @memberOf _
5710      * @category Array
5711      * @param {Array} array The array to filter.
5712      * @param {...*} [values] The values to exclude.
5713      * @returns {Array} Returns the new array of filtered values.
5714      * @example
5715      *
5716      * _.without([1, 2, 1, 3], 1, 2);
5717      * // => [3]
5718      */
5719     var without = restParam(function(array, values) {
5720       return isArrayLike(array)
5721         ? baseDifference(array, values)
5722         : [];
5723     });
5724
5725     /**
5726      * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
5727      * of the provided arrays.
5728      *
5729      * @static
5730      * @memberOf _
5731      * @category Array
5732      * @param {...Array} [arrays] The arrays to inspect.
5733      * @returns {Array} Returns the new array of values.
5734      * @example
5735      *
5736      * _.xor([1, 2], [4, 2]);
5737      * // => [1, 4]
5738      */
5739     function xor() {
5740       var index = -1,
5741           length = arguments.length;
5742
5743       while (++index < length) {
5744         var array = arguments[index];
5745         if (isArrayLike(array)) {
5746           var result = result
5747             ? arrayPush(baseDifference(result, array), baseDifference(array, result))
5748             : array;
5749         }
5750       }
5751       return result ? baseUniq(result) : [];
5752     }
5753
5754     /**
5755      * Creates an array of grouped elements, the first of which contains the first
5756      * elements of the given arrays, the second of which contains the second elements
5757      * of the given arrays, and so on.
5758      *
5759      * @static
5760      * @memberOf _
5761      * @category Array
5762      * @param {...Array} [arrays] The arrays to process.
5763      * @returns {Array} Returns the new array of grouped elements.
5764      * @example
5765      *
5766      * _.zip(['fred', 'barney'], [30, 40], [true, false]);
5767      * // => [['fred', 30, true], ['barney', 40, false]]
5768      */
5769     var zip = restParam(unzip);
5770
5771     /**
5772      * The inverse of `_.pairs`; this method returns an object composed from arrays
5773      * of property names and values. Provide either a single two dimensional array,
5774      * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
5775      * and one of corresponding values.
5776      *
5777      * @static
5778      * @memberOf _
5779      * @alias object
5780      * @category Array
5781      * @param {Array} props The property names.
5782      * @param {Array} [values=[]] The property values.
5783      * @returns {Object} Returns the new object.
5784      * @example
5785      *
5786      * _.zipObject([['fred', 30], ['barney', 40]]);
5787      * // => { 'fred': 30, 'barney': 40 }
5788      *
5789      * _.zipObject(['fred', 'barney'], [30, 40]);
5790      * // => { 'fred': 30, 'barney': 40 }
5791      */
5792     function zipObject(props, values) {
5793       var index = -1,
5794           length = props ? props.length : 0,
5795           result = {};
5796
5797       if (length && !values && !isArray(props[0])) {
5798         values = [];
5799       }
5800       while (++index < length) {
5801         var key = props[index];
5802         if (values) {
5803           result[key] = values[index];
5804         } else if (key) {
5805           result[key[0]] = key[1];
5806         }
5807       }
5808       return result;
5809     }
5810
5811     /**
5812      * This method is like `_.zip` except that it accepts an iteratee to specify
5813      * how grouped values should be combined. The `iteratee` is bound to `thisArg`
5814      * and invoked with four arguments: (accumulator, value, index, group).
5815      *
5816      * @static
5817      * @memberOf _
5818      * @category Array
5819      * @param {...Array} [arrays] The arrays to process.
5820      * @param {Function} [iteratee] The function to combine grouped values.
5821      * @param {*} [thisArg] The `this` binding of `iteratee`.
5822      * @returns {Array} Returns the new array of grouped elements.
5823      * @example
5824      *
5825      * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
5826      * // => [111, 222]
5827      */
5828     var zipWith = restParam(function(arrays) {
5829       var length = arrays.length,
5830           iteratee = length > 2 ? arrays[length - 2] : undefined,
5831           thisArg = length > 1 ? arrays[length - 1] : undefined;
5832
5833       if (length > 2 && typeof iteratee == 'function') {
5834         length -= 2;
5835       } else {
5836         iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
5837         thisArg = undefined;
5838       }
5839       arrays.length = length;
5840       return unzipWith(arrays, iteratee, thisArg);
5841     });
5842
5843     /*------------------------------------------------------------------------*/
5844
5845     /**
5846      * Creates a `lodash` object that wraps `value` with explicit method
5847      * chaining enabled.
5848      *
5849      * @static
5850      * @memberOf _
5851      * @category Chain
5852      * @param {*} value The value to wrap.
5853      * @returns {Object} Returns the new `lodash` wrapper instance.
5854      * @example
5855      *
5856      * var users = [
5857      *   { 'user': 'barney',  'age': 36 },
5858      *   { 'user': 'fred',    'age': 40 },
5859      *   { 'user': 'pebbles', 'age': 1 }
5860      * ];
5861      *
5862      * var youngest = _.chain(users)
5863      *   .sortBy('age')
5864      *   .map(function(chr) {
5865      *     return chr.user + ' is ' + chr.age;
5866      *   })
5867      *   .first()
5868      *   .value();
5869      * // => 'pebbles is 1'
5870      */
5871     function chain(value) {
5872       var result = lodash(value);
5873       result.__chain__ = true;
5874       return result;
5875     }
5876
5877     /**
5878      * This method invokes `interceptor` and returns `value`. The interceptor is
5879      * bound to `thisArg` and invoked with one argument; (value). The purpose of
5880      * this method is to "tap into" a method chain in order to perform operations
5881      * on intermediate results within the chain.
5882      *
5883      * @static
5884      * @memberOf _
5885      * @category Chain
5886      * @param {*} value The value to provide to `interceptor`.
5887      * @param {Function} interceptor The function to invoke.
5888      * @param {*} [thisArg] The `this` binding of `interceptor`.
5889      * @returns {*} Returns `value`.
5890      * @example
5891      *
5892      * _([1, 2, 3])
5893      *  .tap(function(array) {
5894      *    array.pop();
5895      *  })
5896      *  .reverse()
5897      *  .value();
5898      * // => [2, 1]
5899      */
5900     function tap(value, interceptor, thisArg) {
5901       interceptor.call(thisArg, value);
5902       return value;
5903     }
5904
5905     /**
5906      * This method is like `_.tap` except that it returns the result of `interceptor`.
5907      *
5908      * @static
5909      * @memberOf _
5910      * @category Chain
5911      * @param {*} value The value to provide to `interceptor`.
5912      * @param {Function} interceptor The function to invoke.
5913      * @param {*} [thisArg] The `this` binding of `interceptor`.
5914      * @returns {*} Returns the result of `interceptor`.
5915      * @example
5916      *
5917      * _('  abc  ')
5918      *  .chain()
5919      *  .trim()
5920      *  .thru(function(value) {
5921      *    return [value];
5922      *  })
5923      *  .value();
5924      * // => ['abc']
5925      */
5926     function thru(value, interceptor, thisArg) {
5927       return interceptor.call(thisArg, value);
5928     }
5929
5930     /**
5931      * Enables explicit method chaining on the wrapper object.
5932      *
5933      * @name chain
5934      * @memberOf _
5935      * @category Chain
5936      * @returns {Object} Returns the new `lodash` wrapper instance.
5937      * @example
5938      *
5939      * var users = [
5940      *   { 'user': 'barney', 'age': 36 },
5941      *   { 'user': 'fred',   'age': 40 }
5942      * ];
5943      *
5944      * // without explicit chaining
5945      * _(users).first();
5946      * // => { 'user': 'barney', 'age': 36 }
5947      *
5948      * // with explicit chaining
5949      * _(users).chain()
5950      *   .first()
5951      *   .pick('user')
5952      *   .value();
5953      * // => { 'user': 'barney' }
5954      */
5955     function wrapperChain() {
5956       return chain(this);
5957     }
5958
5959     /**
5960      * Executes the chained sequence and returns the wrapped result.
5961      *
5962      * @name commit
5963      * @memberOf _
5964      * @category Chain
5965      * @returns {Object} Returns the new `lodash` wrapper instance.
5966      * @example
5967      *
5968      * var array = [1, 2];
5969      * var wrapped = _(array).push(3);
5970      *
5971      * console.log(array);
5972      * // => [1, 2]
5973      *
5974      * wrapped = wrapped.commit();
5975      * console.log(array);
5976      * // => [1, 2, 3]
5977      *
5978      * wrapped.last();
5979      * // => 3
5980      *
5981      * console.log(array);
5982      * // => [1, 2, 3]
5983      */
5984     function wrapperCommit() {
5985       return new LodashWrapper(this.value(), this.__chain__);
5986     }
5987
5988     /**
5989      * Creates a new array joining a wrapped array with any additional arrays
5990      * and/or values.
5991      *
5992      * @name concat
5993      * @memberOf _
5994      * @category Chain
5995      * @param {...*} [values] The values to concatenate.
5996      * @returns {Array} Returns the new concatenated array.
5997      * @example
5998      *
5999      * var array = [1];
6000      * var wrapped = _(array).concat(2, [3], [[4]]);
6001      *
6002      * console.log(wrapped.value());
6003      * // => [1, 2, 3, [4]]
6004      *
6005      * console.log(array);
6006      * // => [1]
6007      */
6008     var wrapperConcat = restParam(function(values) {
6009       values = baseFlatten(values);
6010       return this.thru(function(array) {
6011         return arrayConcat(isArray(array) ? array : [toObject(array)], values);
6012       });
6013     });
6014
6015     /**
6016      * Creates a clone of the chained sequence planting `value` as the wrapped value.
6017      *
6018      * @name plant
6019      * @memberOf _
6020      * @category Chain
6021      * @returns {Object} Returns the new `lodash` wrapper instance.
6022      * @example
6023      *
6024      * var array = [1, 2];
6025      * var wrapped = _(array).map(function(value) {
6026      *   return Math.pow(value, 2);
6027      * });
6028      *
6029      * var other = [3, 4];
6030      * var otherWrapped = wrapped.plant(other);
6031      *
6032      * otherWrapped.value();
6033      * // => [9, 16]
6034      *
6035      * wrapped.value();
6036      * // => [1, 4]
6037      */
6038     function wrapperPlant(value) {
6039       var result,
6040           parent = this;
6041
6042       while (parent instanceof baseLodash) {
6043         var clone = wrapperClone(parent);
6044         if (result) {
6045           previous.__wrapped__ = clone;
6046         } else {
6047           result = clone;
6048         }
6049         var previous = clone;
6050         parent = parent.__wrapped__;
6051       }
6052       previous.__wrapped__ = value;
6053       return result;
6054     }
6055
6056     /**
6057      * Reverses the wrapped array so the first element becomes the last, the
6058      * second element becomes the second to last, and so on.
6059      *
6060      * **Note:** This method mutates the wrapped array.
6061      *
6062      * @name reverse
6063      * @memberOf _
6064      * @category Chain
6065      * @returns {Object} Returns the new reversed `lodash` wrapper instance.
6066      * @example
6067      *
6068      * var array = [1, 2, 3];
6069      *
6070      * _(array).reverse().value()
6071      * // => [3, 2, 1]
6072      *
6073      * console.log(array);
6074      * // => [3, 2, 1]
6075      */
6076     function wrapperReverse() {
6077       var value = this.__wrapped__;
6078
6079       var interceptor = function(value) {
6080         return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
6081       };
6082       if (value instanceof LazyWrapper) {
6083         var wrapped = value;
6084         if (this.__actions__.length) {
6085           wrapped = new LazyWrapper(this);
6086         }
6087         wrapped = wrapped.reverse();
6088         wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
6089         return new LodashWrapper(wrapped, this.__chain__);
6090       }
6091       return this.thru(interceptor);
6092     }
6093
6094     /**
6095      * Produces the result of coercing the unwrapped value to a string.
6096      *
6097      * @name toString
6098      * @memberOf _
6099      * @category Chain
6100      * @returns {string} Returns the coerced string value.
6101      * @example
6102      *
6103      * _([1, 2, 3]).toString();
6104      * // => '1,2,3'
6105      */
6106     function wrapperToString() {
6107       return (this.value() + '');
6108     }
6109
6110     /**
6111      * Executes the chained sequence to extract the unwrapped value.
6112      *
6113      * @name value
6114      * @memberOf _
6115      * @alias run, toJSON, valueOf
6116      * @category Chain
6117      * @returns {*} Returns the resolved unwrapped value.
6118      * @example
6119      *
6120      * _([1, 2, 3]).value();
6121      * // => [1, 2, 3]
6122      */
6123     function wrapperValue() {
6124       return baseWrapperValue(this.__wrapped__, this.__actions__);
6125     }
6126
6127     /*------------------------------------------------------------------------*/
6128
6129     /**
6130      * Creates an array of elements corresponding to the given keys, or indexes,
6131      * of `collection`. Keys may be specified as individual arguments or as arrays
6132      * of keys.
6133      *
6134      * @static
6135      * @memberOf _
6136      * @category Collection
6137      * @param {Array|Object|string} collection The collection to iterate over.
6138      * @param {...(number|number[]|string|string[])} [props] The property names
6139      *  or indexes of elements to pick, specified individually or in arrays.
6140      * @returns {Array} Returns the new array of picked elements.
6141      * @example
6142      *
6143      * _.at(['a', 'b', 'c'], [0, 2]);
6144      * // => ['a', 'c']
6145      *
6146      * _.at(['barney', 'fred', 'pebbles'], 0, 2);
6147      * // => ['barney', 'pebbles']
6148      */
6149     var at = restParam(function(collection, props) {
6150       return baseAt(collection, baseFlatten(props));
6151     });
6152
6153     /**
6154      * Creates an object composed of keys generated from the results of running
6155      * each element of `collection` through `iteratee`. The corresponding value
6156      * of each key is the number of times the key was returned by `iteratee`.
6157      * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6158      * (value, index|key, collection).
6159      *
6160      * If a property name is provided for `iteratee` the created `_.property`
6161      * style callback returns the property value of the given element.
6162      *
6163      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6164      * style callback returns `true` for elements that have a matching property
6165      * value, else `false`.
6166      *
6167      * If an object is provided for `iteratee` the created `_.matches` style
6168      * callback returns `true` for elements that have the properties of the given
6169      * object, else `false`.
6170      *
6171      * @static
6172      * @memberOf _
6173      * @category Collection
6174      * @param {Array|Object|string} collection The collection to iterate over.
6175      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6176      *  per iteration.
6177      * @param {*} [thisArg] The `this` binding of `iteratee`.
6178      * @returns {Object} Returns the composed aggregate object.
6179      * @example
6180      *
6181      * _.countBy([4.3, 6.1, 6.4], function(n) {
6182      *   return Math.floor(n);
6183      * });
6184      * // => { '4': 1, '6': 2 }
6185      *
6186      * _.countBy([4.3, 6.1, 6.4], function(n) {
6187      *   return this.floor(n);
6188      * }, Math);
6189      * // => { '4': 1, '6': 2 }
6190      *
6191      * _.countBy(['one', 'two', 'three'], 'length');
6192      * // => { '3': 2, '5': 1 }
6193      */
6194     var countBy = createAggregator(function(result, value, key) {
6195       hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
6196     });
6197
6198     /**
6199      * Checks if `predicate` returns truthy for **all** elements of `collection`.
6200      * The predicate is bound to `thisArg` and invoked with three arguments:
6201      * (value, index|key, collection).
6202      *
6203      * If a property name is provided for `predicate` the created `_.property`
6204      * style callback returns the property value of the given element.
6205      *
6206      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6207      * style callback returns `true` for elements that have a matching property
6208      * value, else `false`.
6209      *
6210      * If an object is provided for `predicate` the created `_.matches` style
6211      * callback returns `true` for elements that have the properties of the given
6212      * object, else `false`.
6213      *
6214      * @static
6215      * @memberOf _
6216      * @alias all
6217      * @category Collection
6218      * @param {Array|Object|string} collection The collection to iterate over.
6219      * @param {Function|Object|string} [predicate=_.identity] The function invoked
6220      *  per iteration.
6221      * @param {*} [thisArg] The `this` binding of `predicate`.
6222      * @returns {boolean} Returns `true` if all elements pass the predicate check,
6223      *  else `false`.
6224      * @example
6225      *
6226      * _.every([true, 1, null, 'yes'], Boolean);
6227      * // => false
6228      *
6229      * var users = [
6230      *   { 'user': 'barney', 'active': false },
6231      *   { 'user': 'fred',   'active': false }
6232      * ];
6233      *
6234      * // using the `_.matches` callback shorthand
6235      * _.every(users, { 'user': 'barney', 'active': false });
6236      * // => false
6237      *
6238      * // using the `_.matchesProperty` callback shorthand
6239      * _.every(users, 'active', false);
6240      * // => true
6241      *
6242      * // using the `_.property` callback shorthand
6243      * _.every(users, 'active');
6244      * // => false
6245      */
6246     function every(collection, predicate, thisArg) {
6247       var func = isArray(collection) ? arrayEvery : baseEvery;
6248       if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
6249         predicate = undefined;
6250       }
6251       if (typeof predicate != 'function' || thisArg !== undefined) {
6252         predicate = getCallback(predicate, thisArg, 3);
6253       }
6254       return func(collection, predicate);
6255     }
6256
6257     /**
6258      * Iterates over elements of `collection`, returning an array of all elements
6259      * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6260      * invoked with three arguments: (value, index|key, collection).
6261      *
6262      * If a property name is provided for `predicate` the created `_.property`
6263      * style callback returns the property value of the given element.
6264      *
6265      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6266      * style callback returns `true` for elements that have a matching property
6267      * value, else `false`.
6268      *
6269      * If an object is provided for `predicate` the created `_.matches` style
6270      * callback returns `true` for elements that have the properties of the given
6271      * object, else `false`.
6272      *
6273      * @static
6274      * @memberOf _
6275      * @alias select
6276      * @category Collection
6277      * @param {Array|Object|string} collection The collection to iterate over.
6278      * @param {Function|Object|string} [predicate=_.identity] The function invoked
6279      *  per iteration.
6280      * @param {*} [thisArg] The `this` binding of `predicate`.
6281      * @returns {Array} Returns the new filtered array.
6282      * @example
6283      *
6284      * _.filter([4, 5, 6], function(n) {
6285      *   return n % 2 == 0;
6286      * });
6287      * // => [4, 6]
6288      *
6289      * var users = [
6290      *   { 'user': 'barney', 'age': 36, 'active': true },
6291      *   { 'user': 'fred',   'age': 40, 'active': false }
6292      * ];
6293      *
6294      * // using the `_.matches` callback shorthand
6295      * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
6296      * // => ['barney']
6297      *
6298      * // using the `_.matchesProperty` callback shorthand
6299      * _.pluck(_.filter(users, 'active', false), 'user');
6300      * // => ['fred']
6301      *
6302      * // using the `_.property` callback shorthand
6303      * _.pluck(_.filter(users, 'active'), 'user');
6304      * // => ['barney']
6305      */
6306     function filter(collection, predicate, thisArg) {
6307       var func = isArray(collection) ? arrayFilter : baseFilter;
6308       predicate = getCallback(predicate, thisArg, 3);
6309       return func(collection, predicate);
6310     }
6311
6312     /**
6313      * Iterates over elements of `collection`, returning the first element
6314      * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6315      * invoked with three arguments: (value, index|key, collection).
6316      *
6317      * If a property name is provided for `predicate` the created `_.property`
6318      * style callback returns the property value of the given element.
6319      *
6320      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6321      * style callback returns `true` for elements that have a matching property
6322      * value, else `false`.
6323      *
6324      * If an object is provided for `predicate` the created `_.matches` style
6325      * callback returns `true` for elements that have the properties of the given
6326      * object, else `false`.
6327      *
6328      * @static
6329      * @memberOf _
6330      * @alias detect
6331      * @category Collection
6332      * @param {Array|Object|string} collection The collection to search.
6333      * @param {Function|Object|string} [predicate=_.identity] The function invoked
6334      *  per iteration.
6335      * @param {*} [thisArg] The `this` binding of `predicate`.
6336      * @returns {*} Returns the matched element, else `undefined`.
6337      * @example
6338      *
6339      * var users = [
6340      *   { 'user': 'barney',  'age': 36, 'active': true },
6341      *   { 'user': 'fred',    'age': 40, 'active': false },
6342      *   { 'user': 'pebbles', 'age': 1,  'active': true }
6343      * ];
6344      *
6345      * _.result(_.find(users, function(chr) {
6346      *   return chr.age < 40;
6347      * }), 'user');
6348      * // => 'barney'
6349      *
6350      * // using the `_.matches` callback shorthand
6351      * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
6352      * // => 'pebbles'
6353      *
6354      * // using the `_.matchesProperty` callback shorthand
6355      * _.result(_.find(users, 'active', false), 'user');
6356      * // => 'fred'
6357      *
6358      * // using the `_.property` callback shorthand
6359      * _.result(_.find(users, 'active'), 'user');
6360      * // => 'barney'
6361      */
6362     var find = createFind(baseEach);
6363
6364     /**
6365      * This method is like `_.find` except that it iterates over elements of
6366      * `collection` from right to left.
6367      *
6368      * @static
6369      * @memberOf _
6370      * @category Collection
6371      * @param {Array|Object|string} collection The collection to search.
6372      * @param {Function|Object|string} [predicate=_.identity] The function invoked
6373      *  per iteration.
6374      * @param {*} [thisArg] The `this` binding of `predicate`.
6375      * @returns {*} Returns the matched element, else `undefined`.
6376      * @example
6377      *
6378      * _.findLast([1, 2, 3, 4], function(n) {
6379      *   return n % 2 == 1;
6380      * });
6381      * // => 3
6382      */
6383     var findLast = createFind(baseEachRight, true);
6384
6385     /**
6386      * Performs a deep comparison between each element in `collection` and the
6387      * source object, returning the first element that has equivalent property
6388      * values.
6389      *
6390      * **Note:** This method supports comparing arrays, booleans, `Date` objects,
6391      * numbers, `Object` objects, regexes, and strings. Objects are compared by
6392      * their own, not inherited, enumerable properties. For comparing a single
6393      * own or inherited property value see `_.matchesProperty`.
6394      *
6395      * @static
6396      * @memberOf _
6397      * @category Collection
6398      * @param {Array|Object|string} collection The collection to search.
6399      * @param {Object} source The object of property values to match.
6400      * @returns {*} Returns the matched element, else `undefined`.
6401      * @example
6402      *
6403      * var users = [
6404      *   { 'user': 'barney', 'age': 36, 'active': true },
6405      *   { 'user': 'fred',   'age': 40, 'active': false }
6406      * ];
6407      *
6408      * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
6409      * // => 'barney'
6410      *
6411      * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
6412      * // => 'fred'
6413      */
6414     function findWhere(collection, source) {
6415       return find(collection, baseMatches(source));
6416     }
6417
6418     /**
6419      * Iterates over elements of `collection` invoking `iteratee` for each element.
6420      * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6421      * (value, index|key, collection). Iteratee functions may exit iteration early
6422      * by explicitly returning `false`.
6423      *
6424      * **Note:** As with other "Collections" methods, objects with a "length" property
6425      * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
6426      * may be used for object iteration.
6427      *
6428      * @static
6429      * @memberOf _
6430      * @alias each
6431      * @category Collection
6432      * @param {Array|Object|string} collection The collection to iterate over.
6433      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6434      * @param {*} [thisArg] The `this` binding of `iteratee`.
6435      * @returns {Array|Object|string} Returns `collection`.
6436      * @example
6437      *
6438      * _([1, 2]).forEach(function(n) {
6439      *   console.log(n);
6440      * }).value();
6441      * // => logs each value from left to right and returns the array
6442      *
6443      * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
6444      *   console.log(n, key);
6445      * });
6446      * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
6447      */
6448     var forEach = createForEach(arrayEach, baseEach);
6449
6450     /**
6451      * This method is like `_.forEach` except that it iterates over elements of
6452      * `collection` from right to left.
6453      *
6454      * @static
6455      * @memberOf _
6456      * @alias eachRight
6457      * @category Collection
6458      * @param {Array|Object|string} collection The collection to iterate over.
6459      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6460      * @param {*} [thisArg] The `this` binding of `iteratee`.
6461      * @returns {Array|Object|string} Returns `collection`.
6462      * @example
6463      *
6464      * _([1, 2]).forEachRight(function(n) {
6465      *   console.log(n);
6466      * }).value();
6467      * // => logs each value from right to left and returns the array
6468      */
6469     var forEachRight = createForEach(arrayEachRight, baseEachRight);
6470
6471     /**
6472      * Creates an object composed of keys generated from the results of running
6473      * each element of `collection` through `iteratee`. The corresponding value
6474      * of each key is an array of the elements responsible for generating the key.
6475      * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6476      * (value, index|key, collection).
6477      *
6478      * If a property name is provided for `iteratee` the created `_.property`
6479      * style callback returns the property value of the given element.
6480      *
6481      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6482      * style callback returns `true` for elements that have a matching property
6483      * value, else `false`.
6484      *
6485      * If an object is provided for `iteratee` the created `_.matches` style
6486      * callback returns `true` for elements that have the properties of the given
6487      * object, else `false`.
6488      *
6489      * @static
6490      * @memberOf _
6491      * @category Collection
6492      * @param {Array|Object|string} collection The collection to iterate over.
6493      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6494      *  per iteration.
6495      * @param {*} [thisArg] The `this` binding of `iteratee`.
6496      * @returns {Object} Returns the composed aggregate object.
6497      * @example
6498      *
6499      * _.groupBy([4.2, 6.1, 6.4], function(n) {
6500      *   return Math.floor(n);
6501      * });
6502      * // => { '4': [4.2], '6': [6.1, 6.4] }
6503      *
6504      * _.groupBy([4.2, 6.1, 6.4], function(n) {
6505      *   return this.floor(n);
6506      * }, Math);
6507      * // => { '4': [4.2], '6': [6.1, 6.4] }
6508      *
6509      * // using the `_.property` callback shorthand
6510      * _.groupBy(['one', 'two', 'three'], 'length');
6511      * // => { '3': ['one', 'two'], '5': ['three'] }
6512      */
6513     var groupBy = createAggregator(function(result, value, key) {
6514       if (hasOwnProperty.call(result, key)) {
6515         result[key].push(value);
6516       } else {
6517         result[key] = [value];
6518       }
6519     });
6520
6521     /**
6522      * Checks if `value` is in `collection` using
6523      * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6524      * for equality comparisons. If `fromIndex` is negative, it is used as the offset
6525      * from the end of `collection`.
6526      *
6527      * @static
6528      * @memberOf _
6529      * @alias contains, include
6530      * @category Collection
6531      * @param {Array|Object|string} collection The collection to search.
6532      * @param {*} target The value to search for.
6533      * @param {number} [fromIndex=0] The index to search from.
6534      * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
6535      * @returns {boolean} Returns `true` if a matching element is found, else `false`.
6536      * @example
6537      *
6538      * _.includes([1, 2, 3], 1);
6539      * // => true
6540      *
6541      * _.includes([1, 2, 3], 1, 2);
6542      * // => false
6543      *
6544      * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
6545      * // => true
6546      *
6547      * _.includes('pebbles', 'eb');
6548      * // => true
6549      */
6550     function includes(collection, target, fromIndex, guard) {
6551       var length = collection ? getLength(collection) : 0;
6552       if (!isLength(length)) {
6553         collection = values(collection);
6554         length = collection.length;
6555       }
6556       if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
6557         fromIndex = 0;
6558       } else {
6559         fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
6560       }
6561       return (typeof collection == 'string' || !isArray(collection) && isString(collection))
6562         ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
6563         : (!!length && getIndexOf(collection, target, fromIndex) > -1);
6564     }
6565
6566     /**
6567      * Creates an object composed of keys generated from the results of running
6568      * each element of `collection` through `iteratee`. The corresponding value
6569      * of each key is the last element responsible for generating the key. The
6570      * iteratee function is bound to `thisArg` and invoked with three arguments:
6571      * (value, index|key, collection).
6572      *
6573      * If a property name is provided for `iteratee` the created `_.property`
6574      * style callback returns the property value of the given element.
6575      *
6576      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6577      * style callback returns `true` for elements that have a matching property
6578      * value, else `false`.
6579      *
6580      * If an object is provided for `iteratee` the created `_.matches` style
6581      * callback returns `true` for elements that have the properties of the given
6582      * object, else `false`.
6583      *
6584      * @static
6585      * @memberOf _
6586      * @category Collection
6587      * @param {Array|Object|string} collection The collection to iterate over.
6588      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6589      *  per iteration.
6590      * @param {*} [thisArg] The `this` binding of `iteratee`.
6591      * @returns {Object} Returns the composed aggregate object.
6592      * @example
6593      *
6594      * var keyData = [
6595      *   { 'dir': 'left', 'code': 97 },
6596      *   { 'dir': 'right', 'code': 100 }
6597      * ];
6598      *
6599      * _.indexBy(keyData, 'dir');
6600      * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
6601      *
6602      * _.indexBy(keyData, function(object) {
6603      *   return String.fromCharCode(object.code);
6604      * });
6605      * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6606      *
6607      * _.indexBy(keyData, function(object) {
6608      *   return this.fromCharCode(object.code);
6609      * }, String);
6610      * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6611      */
6612     var indexBy = createAggregator(function(result, value, key) {
6613       result[key] = value;
6614     });
6615
6616     /**
6617      * Invokes the method at `path` of each element in `collection`, returning
6618      * an array of the results of each invoked method. Any additional arguments
6619      * are provided to each invoked method. If `methodName` is a function it is
6620      * invoked for, and `this` bound to, each element in `collection`.
6621      *
6622      * @static
6623      * @memberOf _
6624      * @category Collection
6625      * @param {Array|Object|string} collection The collection to iterate over.
6626      * @param {Array|Function|string} path The path of the method to invoke or
6627      *  the function invoked per iteration.
6628      * @param {...*} [args] The arguments to invoke the method with.
6629      * @returns {Array} Returns the array of results.
6630      * @example
6631      *
6632      * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
6633      * // => [[1, 5, 7], [1, 2, 3]]
6634      *
6635      * _.invoke([123, 456], String.prototype.split, '');
6636      * // => [['1', '2', '3'], ['4', '5', '6']]
6637      */
6638     var invoke = restParam(function(collection, path, args) {
6639       var index = -1,
6640           isFunc = typeof path == 'function',
6641           isProp = isKey(path),
6642           result = isArrayLike(collection) ? Array(collection.length) : [];
6643
6644       baseEach(collection, function(value) {
6645         var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
6646         result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
6647       });
6648       return result;
6649     });
6650
6651     /**
6652      * Creates an array of values by running each element in `collection` through
6653      * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
6654      * arguments: (value, index|key, collection).
6655      *
6656      * If a property name is provided for `iteratee` the created `_.property`
6657      * style callback returns the property value of the given element.
6658      *
6659      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6660      * style callback returns `true` for elements that have a matching property
6661      * value, else `false`.
6662      *
6663      * If an object is provided for `iteratee` the created `_.matches` style
6664      * callback returns `true` for elements that have the properties of the given
6665      * object, else `false`.
6666      *
6667      * Many lodash methods are guarded to work as iteratees for methods like
6668      * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
6669      *
6670      * The guarded methods are:
6671      * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
6672      * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
6673      * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
6674      * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
6675      * `sum`, `uniq`, and `words`
6676      *
6677      * @static
6678      * @memberOf _
6679      * @alias collect
6680      * @category Collection
6681      * @param {Array|Object|string} collection The collection to iterate over.
6682      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6683      *  per iteration.
6684      * @param {*} [thisArg] The `this` binding of `iteratee`.
6685      * @returns {Array} Returns the new mapped array.
6686      * @example
6687      *
6688      * function timesThree(n) {
6689      *   return n * 3;
6690      * }
6691      *
6692      * _.map([1, 2], timesThree);
6693      * // => [3, 6]
6694      *
6695      * _.map({ 'a': 1, 'b': 2 }, timesThree);
6696      * // => [3, 6] (iteration order is not guaranteed)
6697      *
6698      * var users = [
6699      *   { 'user': 'barney' },
6700      *   { 'user': 'fred' }
6701      * ];
6702      *
6703      * // using the `_.property` callback shorthand
6704      * _.map(users, 'user');
6705      * // => ['barney', 'fred']
6706      */
6707     function map(collection, iteratee, thisArg) {
6708       var func = isArray(collection) ? arrayMap : baseMap;
6709       iteratee = getCallback(iteratee, thisArg, 3);
6710       return func(collection, iteratee);
6711     }
6712
6713     /**
6714      * Creates an array of elements split into two groups, the first of which
6715      * contains elements `predicate` returns truthy for, while the second of which
6716      * contains elements `predicate` returns falsey for. The predicate is bound
6717      * to `thisArg` and invoked with three arguments: (value, index|key, collection).
6718      *
6719      * If a property name is provided for `predicate` the created `_.property`
6720      * style callback returns the property value of the given element.
6721      *
6722      * If a value is also provided for `thisArg` the created `_.matchesProperty`
6723      * style callback returns `true` for elements that have a matching property
6724      * value, else `false`.
6725      *
6726      * If an object is provided for `predicate` the created `_.matches` style
6727      * callback returns `true` for elements that have the properties of the given
6728      * object, else `false`.
6729      *
6730      * @static
6731      * @memberOf _
6732      * @category Collection
6733      * @param {Array|Object|string} collection The collection to iterate over.
6734      * @param {Function|Object|string} [predicate=_.identity] The function invoked
6735      *  per iteration.
6736      * @param {*} [thisArg] The `this` binding of `predicate`.
6737      * @returns {Array} Returns the array of grouped elements.
6738      * @example
6739      *
6740      * _.partition([1, 2, 3], function(n) {
6741      *   return n % 2;
6742      * });
6743      * // => [[1, 3], [2]]
6744      *
6745      * _.partition([1.2, 2.3, 3.4], function(n) {
6746      *   return this.floor(n) % 2;
6747      * }, Math);
6748      * // => [[1.2, 3.4], [2.3]]
6749      *
6750      * var users = [
6751      *   { 'user': 'barney',  'age': 36, 'active': false },
6752      *   { 'user': 'fred',    'age': 40, 'active': true },
6753      *   { 'user': 'pebbles', 'age': 1,  'active': false }
6754      * ];
6755      *
6756      * var mapper = function(array) {
6757      *   return _.pluck(array, 'user');
6758      * };
6759      *
6760      * // using the `_.matches` callback shorthand
6761      * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
6762      * // => [['pebbles'], ['barney', 'fred']]
6763      *
6764      * // using the `_.matchesProperty` callback shorthand
6765      * _.map(_.partition(users, 'active', false), mapper);
6766      * // => [['barney', 'pebbles'], ['fred']]
6767      *
6768      * // using the `_.property` callback shorthand
6769      * _.map(_.partition(users, 'active'), mapper);
6770      * // => [['fred'], ['barney', 'pebbles']]
6771      */
6772     var partition = createAggregator(function(result, value, key) {
6773       result[key ? 0 : 1].push(value);
6774     }, function() { return [[], []]; });
6775
6776     /**
6777      * Gets the property value of `path` from all elements in `collection`.
6778      *
6779      * @static
6780      * @memberOf _
6781      * @category Collection
6782      * @param {Array|Object|string} collection The collection to iterate over.
6783      * @param {Array|string} path The path of the property to pluck.
6784      * @returns {Array} Returns the property values.
6785      * @example
6786      *
6787      * var users = [
6788      *   { 'user': 'barney', 'age': 36 },
6789      *   { 'user': 'fred',   'age': 40 }
6790      * ];
6791      *
6792      * _.pluck(users, 'user');
6793      * // => ['barney', 'fred']
6794      *
6795      * var userIndex = _.indexBy(users, 'user');
6796      * _.pluck(userIndex, 'age');
6797      * // => [36, 40] (iteration order is not guaranteed)
6798      */
6799     function pluck(collection, path) {
6800       return map(collection, property(path));
6801     }
6802
6803     /**
6804      * Reduces `collection` to a value which is the accumulated result of running
6805      * each element in `collection` through `iteratee`, where each successive
6806      * invocation is supplied the return value of the previous. If `accumulator`
6807      * is not provided the first element of `collection` is used as the initial
6808      * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
6809      * (accumulator, value, index|key, collection).
6810      *
6811      * Many lodash methods are guarded to work as iteratees for methods like
6812      * `_.reduce`, `_.reduceRight`, and `_.transform`.
6813      *
6814      * The guarded methods are:
6815      * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
6816      * and `sortByOrder`
6817      *
6818      * @static
6819      * @memberOf _
6820      * @alias foldl, inject
6821      * @category Collection
6822      * @param {Array|Object|string} collection The collection to iterate over.
6823      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6824      * @param {*} [accumulator] The initial value.
6825      * @param {*} [thisArg] The `this` binding of `iteratee`.
6826      * @returns {*} Returns the accumulated value.
6827      * @example
6828      *
6829      * _.reduce([1, 2], function(total, n) {
6830      *   return total + n;
6831      * });
6832      * // => 3
6833      *
6834      * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
6835      *   result[key] = n * 3;
6836      *   return result;
6837      * }, {});
6838      * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
6839      */
6840     var reduce = createReduce(arrayReduce, baseEach);
6841
6842     /**
6843      * This method is like `_.reduce` except that it iterates over elements of
6844      * `collection` from right to left.
6845      *
6846      * @static
6847      * @memberOf _
6848      * @alias foldr
6849      * @category Collection
6850      * @param {Array|Object|string} collection The collection to iterate over.
6851      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6852      * @param {*} [accumulator] The initial value.
6853      * @param {*} [thisArg] The `this` binding of `iteratee`.
6854      * @returns {*} Returns the accumulated value.
6855      * @example
6856      *
6857      * var array = [[0, 1], [2, 3], [4, 5]];
6858      *
6859      * _.reduceRight(array, function(flattened, other) {
6860      *   return flattened.concat(other);
6861      * }, []);
6862      * // => [4, 5, 2, 3, 0, 1]
6863      */
6864     var reduceRight = createReduce(arrayReduceRight, baseEachRight);
6865
6866     /**
6867      * The opposite of `_.filter`; this method returns the elements of `collection`
6868      * that `predicate` does **not** return truthy for.
6869      *
6870      * @static
6871      * @memberOf _
6872      * @category Collection
6873      * @param {Array|Object|string} collection The collection to iterate over.
6874      * @param {Function|Object|string} [predicate=_.identity] The function invoked
6875      *  per iteration.
6876      * @param {*} [thisArg] The `this` binding of `predicate`.
6877      * @returns {Array} Returns the new filtered array.
6878      * @example
6879      *
6880      * _.reject([1, 2, 3, 4], function(n) {
6881      *   return n % 2 == 0;
6882      * });
6883      * // => [1, 3]
6884      *
6885      * var users = [
6886      *   { 'user': 'barney', 'age': 36, 'active': false },
6887      *   { 'user': 'fred',   'age': 40, 'active': true }
6888      * ];
6889      *
6890      * // using the `_.matches` callback shorthand
6891      * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
6892      * // => ['barney']
6893      *
6894      * // using the `_.matchesProperty` callback shorthand
6895      * _.pluck(_.reject(users, 'active', false), 'user');
6896      * // => ['fred']
6897      *
6898      * // using the `_.property` callback shorthand
6899      * _.pluck(_.reject(users, 'active'), 'user');
6900      * // => ['barney']
6901      */
6902     function reject(collection, predicate, thisArg) {
6903       var func = isArray(collection) ? arrayFilter : baseFilter;
6904       predicate = getCallback(predicate, thisArg, 3);
6905       return func(collection, function(value, index, collection) {
6906         return !predicate(value, index, collection);
6907       });
6908     }
6909
6910     /**
6911      * Gets a random element or `n` random elements from a collection.
6912      *
6913      * @static
6914      * @memberOf _
6915      * @category Collection
6916      * @param {Array|Object|string} collection The collection to sample.
6917      * @param {number} [n] The number of elements to sample.
6918      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6919      * @returns {*} Returns the random sample(s).
6920      * @example
6921      *
6922      * _.sample([1, 2, 3, 4]);
6923      * // => 2
6924      *
6925      * _.sample([1, 2, 3, 4], 2);
6926      * // => [3, 1]
6927      */
6928     function sample(collection, n, guard) {
6929       if (guard ? isIterateeCall(collection, n, guard) : n == null) {
6930         collection = toIterable(collection);
6931         var length = collection.length;
6932         return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
6933       }
6934       var index = -1,
6935           result = toArray(collection),
6936           length = result.length,
6937           lastIndex = length - 1;
6938
6939       n = nativeMin(n < 0 ? 0 : (+n || 0), length);
6940       while (++index < n) {
6941         var rand = baseRandom(index, lastIndex),
6942             value = result[rand];
6943
6944         result[rand] = result[index];
6945         result[index] = value;
6946       }
6947       result.length = n;
6948       return result;
6949     }
6950
6951     /**
6952      * Creates an array of shuffled values, using a version of the
6953      * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
6954      *
6955      * @static
6956      * @memberOf _
6957      * @category Collection
6958      * @param {Array|Object|string} collection The collection to shuffle.
6959      * @returns {Array} Returns the new shuffled array.
6960      * @example
6961      *
6962      * _.shuffle([1, 2, 3, 4]);
6963      * // => [4, 1, 3, 2]
6964      */
6965     function shuffle(collection) {
6966       return sample(collection, POSITIVE_INFINITY);
6967     }
6968
6969     /**
6970      * Gets the size of `collection` by returning its length for array-like
6971      * values or the number of own enumerable properties for objects.
6972      *
6973      * @static
6974      * @memberOf _
6975      * @category Collection
6976      * @param {Array|Object|string} collection The collection to inspect.
6977      * @returns {number} Returns the size of `collection`.
6978      * @example
6979      *
6980      * _.size([1, 2, 3]);
6981      * // => 3
6982      *
6983      * _.size({ 'a': 1, 'b': 2 });
6984      * // => 2
6985      *
6986      * _.size('pebbles');
6987      * // => 7
6988      */
6989     function size(collection) {
6990       var length = collection ? getLength(collection) : 0;
6991       return isLength(length) ? length : keys(collection).length;
6992     }
6993
6994     /**
6995      * Checks if `predicate` returns truthy for **any** element of `collection`.
6996      * The function returns as soon as it finds a passing value and does not iterate
6997      * over the entire collection. The predicate is bound to `thisArg` and invoked
6998      * with three arguments: (value, index|key, collection).
6999      *
7000      * If a property name is provided for `predicate` the created `_.property`
7001      * style callback returns the property value of the given element.
7002      *
7003      * If a value is also provided for `thisArg` the created `_.matchesProperty`
7004      * style callback returns `true` for elements that have a matching property
7005      * value, else `false`.
7006      *
7007      * If an object is provided for `predicate` the created `_.matches` style
7008      * callback returns `true` for elements that have the properties of the given
7009      * object, else `false`.
7010      *
7011      * @static
7012      * @memberOf _
7013      * @alias any
7014      * @category Collection
7015      * @param {Array|Object|string} collection The collection to iterate over.
7016      * @param {Function|Object|string} [predicate=_.identity] The function invoked
7017      *  per iteration.
7018      * @param {*} [thisArg] The `this` binding of `predicate`.
7019      * @returns {boolean} Returns `true` if any element passes the predicate check,
7020      *  else `false`.
7021      * @example
7022      *
7023      * _.some([null, 0, 'yes', false], Boolean);
7024      * // => true
7025      *
7026      * var users = [
7027      *   { 'user': 'barney', 'active': true },
7028      *   { 'user': 'fred',   'active': false }
7029      * ];
7030      *
7031      * // using the `_.matches` callback shorthand
7032      * _.some(users, { 'user': 'barney', 'active': false });
7033      * // => false
7034      *
7035      * // using the `_.matchesProperty` callback shorthand
7036      * _.some(users, 'active', false);
7037      * // => true
7038      *
7039      * // using the `_.property` callback shorthand
7040      * _.some(users, 'active');
7041      * // => true
7042      */
7043     function some(collection, predicate, thisArg) {
7044       var func = isArray(collection) ? arraySome : baseSome;
7045       if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
7046         predicate = undefined;
7047       }
7048       if (typeof predicate != 'function' || thisArg !== undefined) {
7049         predicate = getCallback(predicate, thisArg, 3);
7050       }
7051       return func(collection, predicate);
7052     }
7053
7054     /**
7055      * Creates an array of elements, sorted in ascending order by the results of
7056      * running each element in a collection through `iteratee`. This method performs
7057      * a stable sort, that is, it preserves the original sort order of equal elements.
7058      * The `iteratee` is bound to `thisArg` and invoked with three arguments:
7059      * (value, index|key, collection).
7060      *
7061      * If a property name is provided for `iteratee` the created `_.property`
7062      * style callback returns the property value of the given element.
7063      *
7064      * If a value is also provided for `thisArg` the created `_.matchesProperty`
7065      * style callback returns `true` for elements that have a matching property
7066      * value, else `false`.
7067      *
7068      * If an object is provided for `iteratee` the created `_.matches` style
7069      * callback returns `true` for elements that have the properties of the given
7070      * object, else `false`.
7071      *
7072      * @static
7073      * @memberOf _
7074      * @category Collection
7075      * @param {Array|Object|string} collection The collection to iterate over.
7076      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
7077      *  per iteration.
7078      * @param {*} [thisArg] The `this` binding of `iteratee`.
7079      * @returns {Array} Returns the new sorted array.
7080      * @example
7081      *
7082      * _.sortBy([1, 2, 3], function(n) {
7083      *   return Math.sin(n);
7084      * });
7085      * // => [3, 1, 2]
7086      *
7087      * _.sortBy([1, 2, 3], function(n) {
7088      *   return this.sin(n);
7089      * }, Math);
7090      * // => [3, 1, 2]
7091      *
7092      * var users = [
7093      *   { 'user': 'fred' },
7094      *   { 'user': 'pebbles' },
7095      *   { 'user': 'barney' }
7096      * ];
7097      *
7098      * // using the `_.property` callback shorthand
7099      * _.pluck(_.sortBy(users, 'user'), 'user');
7100      * // => ['barney', 'fred', 'pebbles']
7101      */
7102     function sortBy(collection, iteratee, thisArg) {
7103       if (collection == null) {
7104         return [];
7105       }
7106       if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
7107         iteratee = undefined;
7108       }
7109       var index = -1;
7110       iteratee = getCallback(iteratee, thisArg, 3);
7111
7112       var result = baseMap(collection, function(value, key, collection) {
7113         return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
7114       });
7115       return baseSortBy(result, compareAscending);
7116     }
7117
7118     /**
7119      * This method is like `_.sortBy` except that it can sort by multiple iteratees
7120      * or property names.
7121      *
7122      * If a property name is provided for an iteratee the created `_.property`
7123      * style callback returns the property value of the given element.
7124      *
7125      * If an object is provided for an iteratee the created `_.matches` style
7126      * callback returns `true` for elements that have the properties of the given
7127      * object, else `false`.
7128      *
7129      * @static
7130      * @memberOf _
7131      * @category Collection
7132      * @param {Array|Object|string} collection The collection to iterate over.
7133      * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
7134      *  The iteratees to sort by, specified as individual values or arrays of values.
7135      * @returns {Array} Returns the new sorted array.
7136      * @example
7137      *
7138      * var users = [
7139      *   { 'user': 'fred',   'age': 48 },
7140      *   { 'user': 'barney', 'age': 36 },
7141      *   { 'user': 'fred',   'age': 42 },
7142      *   { 'user': 'barney', 'age': 34 }
7143      * ];
7144      *
7145      * _.map(_.sortByAll(users, ['user', 'age']), _.values);
7146      * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
7147      *
7148      * _.map(_.sortByAll(users, 'user', function(chr) {
7149      *   return Math.floor(chr.age / 10);
7150      * }), _.values);
7151      * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7152      */
7153     var sortByAll = restParam(function(collection, iteratees) {
7154       if (collection == null) {
7155         return [];
7156       }
7157       var guard = iteratees[2];
7158       if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
7159         iteratees.length = 1;
7160       }
7161       return baseSortByOrder(collection, baseFlatten(iteratees), []);
7162     });
7163
7164     /**
7165      * This method is like `_.sortByAll` except that it allows specifying the
7166      * sort orders of the iteratees to sort by. If `orders` is unspecified, all
7167      * values are sorted in ascending order. Otherwise, a value is sorted in
7168      * ascending order if its corresponding order is "asc", and descending if "desc".
7169      *
7170      * If a property name is provided for an iteratee the created `_.property`
7171      * style callback returns the property value of the given element.
7172      *
7173      * If an object is provided for an iteratee the created `_.matches` style
7174      * callback returns `true` for elements that have the properties of the given
7175      * object, else `false`.
7176      *
7177      * @static
7178      * @memberOf _
7179      * @category Collection
7180      * @param {Array|Object|string} collection The collection to iterate over.
7181      * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
7182      * @param {boolean[]} [orders] The sort orders of `iteratees`.
7183      * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
7184      * @returns {Array} Returns the new sorted array.
7185      * @example
7186      *
7187      * var users = [
7188      *   { 'user': 'fred',   'age': 48 },
7189      *   { 'user': 'barney', 'age': 34 },
7190      *   { 'user': 'fred',   'age': 42 },
7191      *   { 'user': 'barney', 'age': 36 }
7192      * ];
7193      *
7194      * // sort by `user` in ascending order and by `age` in descending order
7195      * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
7196      * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7197      */
7198     function sortByOrder(collection, iteratees, orders, guard) {
7199       if (collection == null) {
7200         return [];
7201       }
7202       if (guard && isIterateeCall(iteratees, orders, guard)) {
7203         orders = undefined;
7204       }
7205       if (!isArray(iteratees)) {
7206         iteratees = iteratees == null ? [] : [iteratees];
7207       }
7208       if (!isArray(orders)) {
7209         orders = orders == null ? [] : [orders];
7210       }
7211       return baseSortByOrder(collection, iteratees, orders);
7212     }
7213
7214     /**
7215      * Performs a deep comparison between each element in `collection` and the
7216      * source object, returning an array of all elements that have equivalent
7217      * property values.
7218      *
7219      * **Note:** This method supports comparing arrays, booleans, `Date` objects,
7220      * numbers, `Object` objects, regexes, and strings. Objects are compared by
7221      * their own, not inherited, enumerable properties. For comparing a single
7222      * own or inherited property value see `_.matchesProperty`.
7223      *
7224      * @static
7225      * @memberOf _
7226      * @category Collection
7227      * @param {Array|Object|string} collection The collection to search.
7228      * @param {Object} source The object of property values to match.
7229      * @returns {Array} Returns the new filtered array.
7230      * @example
7231      *
7232      * var users = [
7233      *   { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
7234      *   { 'user': 'fred',   'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
7235      * ];
7236      *
7237      * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
7238      * // => ['barney']
7239      *
7240      * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
7241      * // => ['fred']
7242      */
7243     function where(collection, source) {
7244       return filter(collection, baseMatches(source));
7245     }
7246
7247     /*------------------------------------------------------------------------*/
7248
7249     /**
7250      * Gets the number of milliseconds that have elapsed since the Unix epoch
7251      * (1 January 1970 00:00:00 UTC).
7252      *
7253      * @static
7254      * @memberOf _
7255      * @category Date
7256      * @example
7257      *
7258      * _.defer(function(stamp) {
7259      *   console.log(_.now() - stamp);
7260      * }, _.now());
7261      * // => logs the number of milliseconds it took for the deferred function to be invoked
7262      */
7263     var now = nativeNow || function() {
7264       return new Date().getTime();
7265     };
7266
7267     /*------------------------------------------------------------------------*/
7268
7269     /**
7270      * The opposite of `_.before`; this method creates a function that invokes
7271      * `func` once it is called `n` or more times.
7272      *
7273      * @static
7274      * @memberOf _
7275      * @category Function
7276      * @param {number} n The number of calls before `func` is invoked.
7277      * @param {Function} func The function to restrict.
7278      * @returns {Function} Returns the new restricted function.
7279      * @example
7280      *
7281      * var saves = ['profile', 'settings'];
7282      *
7283      * var done = _.after(saves.length, function() {
7284      *   console.log('done saving!');
7285      * });
7286      *
7287      * _.forEach(saves, function(type) {
7288      *   asyncSave({ 'type': type, 'complete': done });
7289      * });
7290      * // => logs 'done saving!' after the two async saves have completed
7291      */
7292     function after(n, func) {
7293       if (typeof func != 'function') {
7294         if (typeof n == 'function') {
7295           var temp = n;
7296           n = func;
7297           func = temp;
7298         } else {
7299           throw new TypeError(FUNC_ERROR_TEXT);
7300         }
7301       }
7302       n = nativeIsFinite(n = +n) ? n : 0;
7303       return function() {
7304         if (--n < 1) {
7305           return func.apply(this, arguments);
7306         }
7307       };
7308     }
7309
7310     /**
7311      * Creates a function that accepts up to `n` arguments ignoring any
7312      * additional arguments.
7313      *
7314      * @static
7315      * @memberOf _
7316      * @category Function
7317      * @param {Function} func The function to cap arguments for.
7318      * @param {number} [n=func.length] The arity cap.
7319      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7320      * @returns {Function} Returns the new function.
7321      * @example
7322      *
7323      * _.map(['6', '8', '10'], _.ary(parseInt, 1));
7324      * // => [6, 8, 10]
7325      */
7326     function ary(func, n, guard) {
7327       if (guard && isIterateeCall(func, n, guard)) {
7328         n = undefined;
7329       }
7330       n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
7331       return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
7332     }
7333
7334     /**
7335      * Creates a function that invokes `func`, with the `this` binding and arguments
7336      * of the created function, while it is called less than `n` times. Subsequent
7337      * calls to the created function return the result of the last `func` invocation.
7338      *
7339      * @static
7340      * @memberOf _
7341      * @category Function
7342      * @param {number} n The number of calls at which `func` is no longer invoked.
7343      * @param {Function} func The function to restrict.
7344      * @returns {Function} Returns the new restricted function.
7345      * @example
7346      *
7347      * jQuery('#add').on('click', _.before(5, addContactToList));
7348      * // => allows adding up to 4 contacts to the list
7349      */
7350     function before(n, func) {
7351       var result;
7352       if (typeof func != 'function') {
7353         if (typeof n == 'function') {
7354           var temp = n;
7355           n = func;
7356           func = temp;
7357         } else {
7358           throw new TypeError(FUNC_ERROR_TEXT);
7359         }
7360       }
7361       return function() {
7362         if (--n > 0) {
7363           result = func.apply(this, arguments);
7364         }
7365         if (n <= 1) {
7366           func = undefined;
7367         }
7368         return result;
7369       };
7370     }
7371
7372     /**
7373      * Creates a function that invokes `func` with the `this` binding of `thisArg`
7374      * and prepends any additional `_.bind` arguments to those provided to the
7375      * bound function.
7376      *
7377      * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
7378      * may be used as a placeholder for partially applied arguments.
7379      *
7380      * **Note:** Unlike native `Function#bind` this method does not set the "length"
7381      * property of bound functions.
7382      *
7383      * @static
7384      * @memberOf _
7385      * @category Function
7386      * @param {Function} func The function to bind.
7387      * @param {*} thisArg The `this` binding of `func`.
7388      * @param {...*} [partials] The arguments to be partially applied.
7389      * @returns {Function} Returns the new bound function.
7390      * @example
7391      *
7392      * var greet = function(greeting, punctuation) {
7393      *   return greeting + ' ' + this.user + punctuation;
7394      * };
7395      *
7396      * var object = { 'user': 'fred' };
7397      *
7398      * var bound = _.bind(greet, object, 'hi');
7399      * bound('!');
7400      * // => 'hi fred!'
7401      *
7402      * // using placeholders
7403      * var bound = _.bind(greet, object, _, '!');
7404      * bound('hi');
7405      * // => 'hi fred!'
7406      */
7407     var bind = restParam(function(func, thisArg, partials) {
7408       var bitmask = BIND_FLAG;
7409       if (partials.length) {
7410         var holders = replaceHolders(partials, bind.placeholder);
7411         bitmask |= PARTIAL_FLAG;
7412       }
7413       return createWrapper(func, bitmask, thisArg, partials, holders);
7414     });
7415
7416     /**
7417      * Binds methods of an object to the object itself, overwriting the existing
7418      * method. Method names may be specified as individual arguments or as arrays
7419      * of method names. If no method names are provided all enumerable function
7420      * properties, own and inherited, of `object` are bound.
7421      *
7422      * **Note:** This method does not set the "length" property of bound functions.
7423      *
7424      * @static
7425      * @memberOf _
7426      * @category Function
7427      * @param {Object} object The object to bind and assign the bound methods to.
7428      * @param {...(string|string[])} [methodNames] The object method names to bind,
7429      *  specified as individual method names or arrays of method names.
7430      * @returns {Object} Returns `object`.
7431      * @example
7432      *
7433      * var view = {
7434      *   'label': 'docs',
7435      *   'onClick': function() {
7436      *     console.log('clicked ' + this.label);
7437      *   }
7438      * };
7439      *
7440      * _.bindAll(view);
7441      * jQuery('#docs').on('click', view.onClick);
7442      * // => logs 'clicked docs' when the element is clicked
7443      */
7444     var bindAll = restParam(function(object, methodNames) {
7445       methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
7446
7447       var index = -1,
7448           length = methodNames.length;
7449
7450       while (++index < length) {
7451         var key = methodNames[index];
7452         object[key] = createWrapper(object[key], BIND_FLAG, object);
7453       }
7454       return object;
7455     });
7456
7457     /**
7458      * Creates a function that invokes the method at `object[key]` and prepends
7459      * any additional `_.bindKey` arguments to those provided to the bound function.
7460      *
7461      * This method differs from `_.bind` by allowing bound functions to reference
7462      * methods that may be redefined or don't yet exist.
7463      * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
7464      * for more details.
7465      *
7466      * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
7467      * builds, may be used as a placeholder for partially applied arguments.
7468      *
7469      * @static
7470      * @memberOf _
7471      * @category Function
7472      * @param {Object} object The object the method belongs to.
7473      * @param {string} key The key of the method.
7474      * @param {...*} [partials] The arguments to be partially applied.
7475      * @returns {Function} Returns the new bound function.
7476      * @example
7477      *
7478      * var object = {
7479      *   'user': 'fred',
7480      *   'greet': function(greeting, punctuation) {
7481      *     return greeting + ' ' + this.user + punctuation;
7482      *   }
7483      * };
7484      *
7485      * var bound = _.bindKey(object, 'greet', 'hi');
7486      * bound('!');
7487      * // => 'hi fred!'
7488      *
7489      * object.greet = function(greeting, punctuation) {
7490      *   return greeting + 'ya ' + this.user + punctuation;
7491      * };
7492      *
7493      * bound('!');
7494      * // => 'hiya fred!'
7495      *
7496      * // using placeholders
7497      * var bound = _.bindKey(object, 'greet', _, '!');
7498      * bound('hi');
7499      * // => 'hiya fred!'
7500      */
7501     var bindKey = restParam(function(object, key, partials) {
7502       var bitmask = BIND_FLAG | BIND_KEY_FLAG;
7503       if (partials.length) {
7504         var holders = replaceHolders(partials, bindKey.placeholder);
7505         bitmask |= PARTIAL_FLAG;
7506       }
7507       return createWrapper(key, bitmask, object, partials, holders);
7508     });
7509
7510     /**
7511      * Creates a function that accepts one or more arguments of `func` that when
7512      * called either invokes `func` returning its result, if all `func` arguments
7513      * have been provided, or returns a function that accepts one or more of the
7514      * remaining `func` arguments, and so on. The arity of `func` may be specified
7515      * if `func.length` is not sufficient.
7516      *
7517      * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
7518      * may be used as a placeholder for provided arguments.
7519      *
7520      * **Note:** This method does not set the "length" property of curried functions.
7521      *
7522      * @static
7523      * @memberOf _
7524      * @category Function
7525      * @param {Function} func The function to curry.
7526      * @param {number} [arity=func.length] The arity of `func`.
7527      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7528      * @returns {Function} Returns the new curried function.
7529      * @example
7530      *
7531      * var abc = function(a, b, c) {
7532      *   return [a, b, c];
7533      * };
7534      *
7535      * var curried = _.curry(abc);
7536      *
7537      * curried(1)(2)(3);
7538      * // => [1, 2, 3]
7539      *
7540      * curried(1, 2)(3);
7541      * // => [1, 2, 3]
7542      *
7543      * curried(1, 2, 3);
7544      * // => [1, 2, 3]
7545      *
7546      * // using placeholders
7547      * curried(1)(_, 3)(2);
7548      * // => [1, 2, 3]
7549      */
7550     var curry = createCurry(CURRY_FLAG);
7551
7552     /**
7553      * This method is like `_.curry` except that arguments are applied to `func`
7554      * in the manner of `_.partialRight` instead of `_.partial`.
7555      *
7556      * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
7557      * builds, may be used as a placeholder for provided arguments.
7558      *
7559      * **Note:** This method does not set the "length" property of curried functions.
7560      *
7561      * @static
7562      * @memberOf _
7563      * @category Function
7564      * @param {Function} func The function to curry.
7565      * @param {number} [arity=func.length] The arity of `func`.
7566      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7567      * @returns {Function} Returns the new curried function.
7568      * @example
7569      *
7570      * var abc = function(a, b, c) {
7571      *   return [a, b, c];
7572      * };
7573      *
7574      * var curried = _.curryRight(abc);
7575      *
7576      * curried(3)(2)(1);
7577      * // => [1, 2, 3]
7578      *
7579      * curried(2, 3)(1);
7580      * // => [1, 2, 3]
7581      *
7582      * curried(1, 2, 3);
7583      * // => [1, 2, 3]
7584      *
7585      * // using placeholders
7586      * curried(3)(1, _)(2);
7587      * // => [1, 2, 3]
7588      */
7589     var curryRight = createCurry(CURRY_RIGHT_FLAG);
7590
7591     /**
7592      * Creates a debounced function that delays invoking `func` until after `wait`
7593      * milliseconds have elapsed since the last time the debounced function was
7594      * invoked. The debounced function comes with a `cancel` method to cancel
7595      * delayed invocations. Provide an options object to indicate that `func`
7596      * should be invoked on the leading and/or trailing edge of the `wait` timeout.
7597      * Subsequent calls to the debounced function return the result of the last
7598      * `func` invocation.
7599      *
7600      * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
7601      * on the trailing edge of the timeout only if the the debounced function is
7602      * invoked more than once during the `wait` timeout.
7603      *
7604      * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
7605      * for details over the differences between `_.debounce` and `_.throttle`.
7606      *
7607      * @static
7608      * @memberOf _
7609      * @category Function
7610      * @param {Function} func The function to debounce.
7611      * @param {number} [wait=0] The number of milliseconds to delay.
7612      * @param {Object} [options] The options object.
7613      * @param {boolean} [options.leading=false] Specify invoking on the leading
7614      *  edge of the timeout.
7615      * @param {number} [options.maxWait] The maximum time `func` is allowed to be
7616      *  delayed before it is invoked.
7617      * @param {boolean} [options.trailing=true] Specify invoking on the trailing
7618      *  edge of the timeout.
7619      * @returns {Function} Returns the new debounced function.
7620      * @example
7621      *
7622      * // avoid costly calculations while the window size is in flux
7623      * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
7624      *
7625      * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
7626      * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
7627      *   'leading': true,
7628      *   'trailing': false
7629      * }));
7630      *
7631      * // ensure `batchLog` is invoked once after 1 second of debounced calls
7632      * var source = new EventSource('/stream');
7633      * jQuery(source).on('message', _.debounce(batchLog, 250, {
7634      *   'maxWait': 1000
7635      * }));
7636      *
7637      * // cancel a debounced call
7638      * var todoChanges = _.debounce(batchLog, 1000);
7639      * Object.observe(models.todo, todoChanges);
7640      *
7641      * Object.observe(models, function(changes) {
7642      *   if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
7643      *     todoChanges.cancel();
7644      *   }
7645      * }, ['delete']);
7646      *
7647      * // ...at some point `models.todo` is changed
7648      * models.todo.completed = true;
7649      *
7650      * // ...before 1 second has passed `models.todo` is deleted
7651      * // which cancels the debounced `todoChanges` call
7652      * delete models.todo;
7653      */
7654     function debounce(func, wait, options) {
7655       var args,
7656           maxTimeoutId,
7657           result,
7658           stamp,
7659           thisArg,
7660           timeoutId,
7661           trailingCall,
7662           lastCalled = 0,
7663           maxWait = false,
7664           trailing = true;
7665
7666       if (typeof func != 'function') {
7667         throw new TypeError(FUNC_ERROR_TEXT);
7668       }
7669       wait = wait < 0 ? 0 : (+wait || 0);
7670       if (options === true) {
7671         var leading = true;
7672         trailing = false;
7673       } else if (isObject(options)) {
7674         leading = !!options.leading;
7675         maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
7676         trailing = 'trailing' in options ? !!options.trailing : trailing;
7677       }
7678
7679       function cancel() {
7680         if (timeoutId) {
7681           clearTimeout(timeoutId);
7682         }
7683         if (maxTimeoutId) {
7684           clearTimeout(maxTimeoutId);
7685         }
7686         lastCalled = 0;
7687         maxTimeoutId = timeoutId = trailingCall = undefined;
7688       }
7689
7690       function complete(isCalled, id) {
7691         if (id) {
7692           clearTimeout(id);
7693         }
7694         maxTimeoutId = timeoutId = trailingCall = undefined;
7695         if (isCalled) {
7696           lastCalled = now();
7697           result = func.apply(thisArg, args);
7698           if (!timeoutId && !maxTimeoutId) {
7699             args = thisArg = undefined;
7700           }
7701         }
7702       }
7703
7704       function delayed() {
7705         var remaining = wait - (now() - stamp);
7706         if (remaining <= 0 || remaining > wait) {
7707           complete(trailingCall, maxTimeoutId);
7708         } else {
7709           timeoutId = setTimeout(delayed, remaining);
7710         }
7711       }
7712
7713       function maxDelayed() {
7714         complete(trailing, timeoutId);
7715       }
7716
7717       function debounced() {
7718         args = arguments;
7719         stamp = now();
7720         thisArg = this;
7721         trailingCall = trailing && (timeoutId || !leading);
7722
7723         if (maxWait === false) {
7724           var leadingCall = leading && !timeoutId;
7725         } else {
7726           if (!maxTimeoutId && !leading) {
7727             lastCalled = stamp;
7728           }
7729           var remaining = maxWait - (stamp - lastCalled),
7730               isCalled = remaining <= 0 || remaining > maxWait;
7731
7732           if (isCalled) {
7733             if (maxTimeoutId) {
7734               maxTimeoutId = clearTimeout(maxTimeoutId);
7735             }
7736             lastCalled = stamp;
7737             result = func.apply(thisArg, args);
7738           }
7739           else if (!maxTimeoutId) {
7740             maxTimeoutId = setTimeout(maxDelayed, remaining);
7741           }
7742         }
7743         if (isCalled && timeoutId) {
7744           timeoutId = clearTimeout(timeoutId);
7745         }
7746         else if (!timeoutId && wait !== maxWait) {
7747           timeoutId = setTimeout(delayed, wait);
7748         }
7749         if (leadingCall) {
7750           isCalled = true;
7751           result = func.apply(thisArg, args);
7752         }
7753         if (isCalled && !timeoutId && !maxTimeoutId) {
7754           args = thisArg = undefined;
7755         }
7756         return result;
7757       }
7758       debounced.cancel = cancel;
7759       return debounced;
7760     }
7761
7762     /**
7763      * Defers invoking the `func` until the current call stack has cleared. Any
7764      * additional arguments are provided to `func` when it is invoked.
7765      *
7766      * @static
7767      * @memberOf _
7768      * @category Function
7769      * @param {Function} func The function to defer.
7770      * @param {...*} [args] The arguments to invoke the function with.
7771      * @returns {number} Returns the timer id.
7772      * @example
7773      *
7774      * _.defer(function(text) {
7775      *   console.log(text);
7776      * }, 'deferred');
7777      * // logs 'deferred' after one or more milliseconds
7778      */
7779     var defer = restParam(function(func, args) {
7780       return baseDelay(func, 1, args);
7781     });
7782
7783     /**
7784      * Invokes `func` after `wait` milliseconds. Any additional arguments are
7785      * provided to `func` when it is invoked.
7786      *
7787      * @static
7788      * @memberOf _
7789      * @category Function
7790      * @param {Function} func The function to delay.
7791      * @param {number} wait The number of milliseconds to delay invocation.
7792      * @param {...*} [args] The arguments to invoke the function with.
7793      * @returns {number} Returns the timer id.
7794      * @example
7795      *
7796      * _.delay(function(text) {
7797      *   console.log(text);
7798      * }, 1000, 'later');
7799      * // => logs 'later' after one second
7800      */
7801     var delay = restParam(function(func, wait, args) {
7802       return baseDelay(func, wait, args);
7803     });
7804
7805     /**
7806      * Creates a function that returns the result of invoking the provided
7807      * functions with the `this` binding of the created function, where each
7808      * successive invocation is supplied the return value of the previous.
7809      *
7810      * @static
7811      * @memberOf _
7812      * @category Function
7813      * @param {...Function} [funcs] Functions to invoke.
7814      * @returns {Function} Returns the new function.
7815      * @example
7816      *
7817      * function square(n) {
7818      *   return n * n;
7819      * }
7820      *
7821      * var addSquare = _.flow(_.add, square);
7822      * addSquare(1, 2);
7823      * // => 9
7824      */
7825     var flow = createFlow();
7826
7827     /**
7828      * This method is like `_.flow` except that it creates a function that
7829      * invokes the provided functions from right to left.
7830      *
7831      * @static
7832      * @memberOf _
7833      * @alias backflow, compose
7834      * @category Function
7835      * @param {...Function} [funcs] Functions to invoke.
7836      * @returns {Function} Returns the new function.
7837      * @example
7838      *
7839      * function square(n) {
7840      *   return n * n;
7841      * }
7842      *
7843      * var addSquare = _.flowRight(square, _.add);
7844      * addSquare(1, 2);
7845      * // => 9
7846      */
7847     var flowRight = createFlow(true);
7848
7849     /**
7850      * Creates a function that memoizes the result of `func`. If `resolver` is
7851      * provided it determines the cache key for storing the result based on the
7852      * arguments provided to the memoized function. By default, the first argument
7853      * provided to the memoized function is coerced to a string and used as the
7854      * cache key. The `func` is invoked with the `this` binding of the memoized
7855      * function.
7856      *
7857      * **Note:** The cache is exposed as the `cache` property on the memoized
7858      * function. Its creation may be customized by replacing the `_.memoize.Cache`
7859      * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
7860      * method interface of `get`, `has`, and `set`.
7861      *
7862      * @static
7863      * @memberOf _
7864      * @category Function
7865      * @param {Function} func The function to have its output memoized.
7866      * @param {Function} [resolver] The function to resolve the cache key.
7867      * @returns {Function} Returns the new memoizing function.
7868      * @example
7869      *
7870      * var upperCase = _.memoize(function(string) {
7871      *   return string.toUpperCase();
7872      * });
7873      *
7874      * upperCase('fred');
7875      * // => 'FRED'
7876      *
7877      * // modifying the result cache
7878      * upperCase.cache.set('fred', 'BARNEY');
7879      * upperCase('fred');
7880      * // => 'BARNEY'
7881      *
7882      * // replacing `_.memoize.Cache`
7883      * var object = { 'user': 'fred' };
7884      * var other = { 'user': 'barney' };
7885      * var identity = _.memoize(_.identity);
7886      *
7887      * identity(object);
7888      * // => { 'user': 'fred' }
7889      * identity(other);
7890      * // => { 'user': 'fred' }
7891      *
7892      * _.memoize.Cache = WeakMap;
7893      * var identity = _.memoize(_.identity);
7894      *
7895      * identity(object);
7896      * // => { 'user': 'fred' }
7897      * identity(other);
7898      * // => { 'user': 'barney' }
7899      */
7900     function memoize(func, resolver) {
7901       if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
7902         throw new TypeError(FUNC_ERROR_TEXT);
7903       }
7904       var memoized = function() {
7905         var args = arguments,
7906             key = resolver ? resolver.apply(this, args) : args[0],
7907             cache = memoized.cache;
7908
7909         if (cache.has(key)) {
7910           return cache.get(key);
7911         }
7912         var result = func.apply(this, args);
7913         memoized.cache = cache.set(key, result);
7914         return result;
7915       };
7916       memoized.cache = new memoize.Cache;
7917       return memoized;
7918     }
7919
7920     /**
7921      * Creates a function that runs each argument through a corresponding
7922      * transform function.
7923      *
7924      * @static
7925      * @memberOf _
7926      * @category Function
7927      * @param {Function} func The function to wrap.
7928      * @param {...(Function|Function[])} [transforms] The functions to transform
7929      * arguments, specified as individual functions or arrays of functions.
7930      * @returns {Function} Returns the new function.
7931      * @example
7932      *
7933      * function doubled(n) {
7934      *   return n * 2;
7935      * }
7936      *
7937      * function square(n) {
7938      *   return n * n;
7939      * }
7940      *
7941      * var modded = _.modArgs(function(x, y) {
7942      *   return [x, y];
7943      * }, square, doubled);
7944      *
7945      * modded(1, 2);
7946      * // => [1, 4]
7947      *
7948      * modded(5, 10);
7949      * // => [25, 20]
7950      */
7951     var modArgs = restParam(function(func, transforms) {
7952       transforms = baseFlatten(transforms);
7953       if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
7954         throw new TypeError(FUNC_ERROR_TEXT);
7955       }
7956       var length = transforms.length;
7957       return restParam(function(args) {
7958         var index = nativeMin(args.length, length);
7959         while (index--) {
7960           args[index] = transforms[index](args[index]);
7961         }
7962         return func.apply(this, args);
7963       });
7964     });
7965
7966     /**
7967      * Creates a function that negates the result of the predicate `func`. The
7968      * `func` predicate is invoked with the `this` binding and arguments of the
7969      * created function.
7970      *
7971      * @static
7972      * @memberOf _
7973      * @category Function
7974      * @param {Function} predicate The predicate to negate.
7975      * @returns {Function} Returns the new function.
7976      * @example
7977      *
7978      * function isEven(n) {
7979      *   return n % 2 == 0;
7980      * }
7981      *
7982      * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
7983      * // => [1, 3, 5]
7984      */
7985     function negate(predicate) {
7986       if (typeof predicate != 'function') {
7987         throw new TypeError(FUNC_ERROR_TEXT);
7988       }
7989       return function() {
7990         return !predicate.apply(this, arguments);
7991       };
7992     }
7993
7994     /**
7995      * Creates a function that is restricted to invoking `func` once. Repeat calls
7996      * to the function return the value of the first call. The `func` is invoked
7997      * with the `this` binding and arguments of the created function.
7998      *
7999      * @static
8000      * @memberOf _
8001      * @category Function
8002      * @param {Function} func The function to restrict.
8003      * @returns {Function} Returns the new restricted function.
8004      * @example
8005      *
8006      * var initialize = _.once(createApplication);
8007      * initialize();
8008      * initialize();
8009      * // `initialize` invokes `createApplication` once
8010      */
8011     function once(func) {
8012       return before(2, func);
8013     }
8014
8015     /**
8016      * Creates a function that invokes `func` with `partial` arguments prepended
8017      * to those provided to the new function. This method is like `_.bind` except
8018      * it does **not** alter the `this` binding.
8019      *
8020      * The `_.partial.placeholder` value, which defaults to `_` in monolithic
8021      * builds, may be used as a placeholder for partially applied arguments.
8022      *
8023      * **Note:** This method does not set the "length" property of partially
8024      * applied functions.
8025      *
8026      * @static
8027      * @memberOf _
8028      * @category Function
8029      * @param {Function} func The function to partially apply arguments to.
8030      * @param {...*} [partials] The arguments to be partially applied.
8031      * @returns {Function} Returns the new partially applied function.
8032      * @example
8033      *
8034      * var greet = function(greeting, name) {
8035      *   return greeting + ' ' + name;
8036      * };
8037      *
8038      * var sayHelloTo = _.partial(greet, 'hello');
8039      * sayHelloTo('fred');
8040      * // => 'hello fred'
8041      *
8042      * // using placeholders
8043      * var greetFred = _.partial(greet, _, 'fred');
8044      * greetFred('hi');
8045      * // => 'hi fred'
8046      */
8047     var partial = createPartial(PARTIAL_FLAG);
8048
8049     /**
8050      * This method is like `_.partial` except that partially applied arguments
8051      * are appended to those provided to the new function.
8052      *
8053      * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
8054      * builds, may be used as a placeholder for partially applied arguments.
8055      *
8056      * **Note:** This method does not set the "length" property of partially
8057      * applied functions.
8058      *
8059      * @static
8060      * @memberOf _
8061      * @category Function
8062      * @param {Function} func The function to partially apply arguments to.
8063      * @param {...*} [partials] The arguments to be partially applied.
8064      * @returns {Function} Returns the new partially applied function.
8065      * @example
8066      *
8067      * var greet = function(greeting, name) {
8068      *   return greeting + ' ' + name;
8069      * };
8070      *
8071      * var greetFred = _.partialRight(greet, 'fred');
8072      * greetFred('hi');
8073      * // => 'hi fred'
8074      *
8075      * // using placeholders
8076      * var sayHelloTo = _.partialRight(greet, 'hello', _);
8077      * sayHelloTo('fred');
8078      * // => 'hello fred'
8079      */
8080     var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
8081
8082     /**
8083      * Creates a function that invokes `func` with arguments arranged according
8084      * to the specified indexes where the argument value at the first index is
8085      * provided as the first argument, the argument value at the second index is
8086      * provided as the second argument, and so on.
8087      *
8088      * @static
8089      * @memberOf _
8090      * @category Function
8091      * @param {Function} func The function to rearrange arguments for.
8092      * @param {...(number|number[])} indexes The arranged argument indexes,
8093      *  specified as individual indexes or arrays of indexes.
8094      * @returns {Function} Returns the new function.
8095      * @example
8096      *
8097      * var rearged = _.rearg(function(a, b, c) {
8098      *   return [a, b, c];
8099      * }, 2, 0, 1);
8100      *
8101      * rearged('b', 'c', 'a')
8102      * // => ['a', 'b', 'c']
8103      *
8104      * var map = _.rearg(_.map, [1, 0]);
8105      * map(function(n) {
8106      *   return n * 3;
8107      * }, [1, 2, 3]);
8108      * // => [3, 6, 9]
8109      */
8110     var rearg = restParam(function(func, indexes) {
8111       return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
8112     });
8113
8114     /**
8115      * Creates a function that invokes `func` with the `this` binding of the
8116      * created function and arguments from `start` and beyond provided as an array.
8117      *
8118      * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
8119      *
8120      * @static
8121      * @memberOf _
8122      * @category Function
8123      * @param {Function} func The function to apply a rest parameter to.
8124      * @param {number} [start=func.length-1] The start position of the rest parameter.
8125      * @returns {Function} Returns the new function.
8126      * @example
8127      *
8128      * var say = _.restParam(function(what, names) {
8129      *   return what + ' ' + _.initial(names).join(', ') +
8130      *     (_.size(names) > 1 ? ', & ' : '') + _.last(names);
8131      * });
8132      *
8133      * say('hello', 'fred', 'barney', 'pebbles');
8134      * // => 'hello fred, barney, & pebbles'
8135      */
8136     function restParam(func, start) {
8137       if (typeof func != 'function') {
8138         throw new TypeError(FUNC_ERROR_TEXT);
8139       }
8140       start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
8141       return function() {
8142         var args = arguments,
8143             index = -1,
8144             length = nativeMax(args.length - start, 0),
8145             rest = Array(length);
8146
8147         while (++index < length) {
8148           rest[index] = args[start + index];
8149         }
8150         switch (start) {
8151           case 0: return func.call(this, rest);
8152           case 1: return func.call(this, args[0], rest);
8153           case 2: return func.call(this, args[0], args[1], rest);
8154         }
8155         var otherArgs = Array(start + 1);
8156         index = -1;
8157         while (++index < start) {
8158           otherArgs[index] = args[index];
8159         }
8160         otherArgs[start] = rest;
8161         return func.apply(this, otherArgs);
8162       };
8163     }
8164
8165     /**
8166      * Creates a function that invokes `func` with the `this` binding of the created
8167      * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
8168      *
8169      * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
8170      *
8171      * @static
8172      * @memberOf _
8173      * @category Function
8174      * @param {Function} func The function to spread arguments over.
8175      * @returns {Function} Returns the new function.
8176      * @example
8177      *
8178      * var say = _.spread(function(who, what) {
8179      *   return who + ' says ' + what;
8180      * });
8181      *
8182      * say(['fred', 'hello']);
8183      * // => 'fred says hello'
8184      *
8185      * // with a Promise
8186      * var numbers = Promise.all([
8187      *   Promise.resolve(40),
8188      *   Promise.resolve(36)
8189      * ]);
8190      *
8191      * numbers.then(_.spread(function(x, y) {
8192      *   return x + y;
8193      * }));
8194      * // => a Promise of 76
8195      */
8196     function spread(func) {
8197       if (typeof func != 'function') {
8198         throw new TypeError(FUNC_ERROR_TEXT);
8199       }
8200       return function(array) {
8201         return func.apply(this, array);
8202       };
8203     }
8204
8205     /**
8206      * Creates a throttled function that only invokes `func` at most once per
8207      * every `wait` milliseconds. The throttled function comes with a `cancel`
8208      * method to cancel delayed invocations. Provide an options object to indicate
8209      * that `func` should be invoked on the leading and/or trailing edge of the
8210      * `wait` timeout. Subsequent calls to the throttled function return the
8211      * result of the last `func` call.
8212      *
8213      * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8214      * on the trailing edge of the timeout only if the the throttled function is
8215      * invoked more than once during the `wait` timeout.
8216      *
8217      * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8218      * for details over the differences between `_.throttle` and `_.debounce`.
8219      *
8220      * @static
8221      * @memberOf _
8222      * @category Function
8223      * @param {Function} func The function to throttle.
8224      * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
8225      * @param {Object} [options] The options object.
8226      * @param {boolean} [options.leading=true] Specify invoking on the leading
8227      *  edge of the timeout.
8228      * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8229      *  edge of the timeout.
8230      * @returns {Function} Returns the new throttled function.
8231      * @example
8232      *
8233      * // avoid excessively updating the position while scrolling
8234      * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
8235      *
8236      * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
8237      * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
8238      *   'trailing': false
8239      * }));
8240      *
8241      * // cancel a trailing throttled call
8242      * jQuery(window).on('popstate', throttled.cancel);
8243      */
8244     function throttle(func, wait, options) {
8245       var leading = true,
8246           trailing = true;
8247
8248       if (typeof func != 'function') {
8249         throw new TypeError(FUNC_ERROR_TEXT);
8250       }
8251       if (options === false) {
8252         leading = false;
8253       } else if (isObject(options)) {
8254         leading = 'leading' in options ? !!options.leading : leading;
8255         trailing = 'trailing' in options ? !!options.trailing : trailing;
8256       }
8257       return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
8258     }
8259
8260     /**
8261      * Creates a function that provides `value` to the wrapper function as its
8262      * first argument. Any additional arguments provided to the function are
8263      * appended to those provided to the wrapper function. The wrapper is invoked
8264      * with the `this` binding of the created function.
8265      *
8266      * @static
8267      * @memberOf _
8268      * @category Function
8269      * @param {*} value The value to wrap.
8270      * @param {Function} wrapper The wrapper function.
8271      * @returns {Function} Returns the new function.
8272      * @example
8273      *
8274      * var p = _.wrap(_.escape, function(func, text) {
8275      *   return '<p>' + func(text) + '</p>';
8276      * });
8277      *
8278      * p('fred, barney, & pebbles');
8279      * // => '<p>fred, barney, &amp; pebbles</p>'
8280      */
8281     function wrap(value, wrapper) {
8282       wrapper = wrapper == null ? identity : wrapper;
8283       return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
8284     }
8285
8286     /*------------------------------------------------------------------------*/
8287
8288     /**
8289      * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
8290      * otherwise they are assigned by reference. If `customizer` is provided it is
8291      * invoked to produce the cloned values. If `customizer` returns `undefined`
8292      * cloning is handled by the method instead. The `customizer` is bound to
8293      * `thisArg` and invoked with two argument; (value [, index|key, object]).
8294      *
8295      * **Note:** This method is loosely based on the
8296      * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8297      * The enumerable properties of `arguments` objects and objects created by
8298      * constructors other than `Object` are cloned to plain `Object` objects. An
8299      * empty object is returned for uncloneable values such as functions, DOM nodes,
8300      * Maps, Sets, and WeakMaps.
8301      *
8302      * @static
8303      * @memberOf _
8304      * @category Lang
8305      * @param {*} value The value to clone.
8306      * @param {boolean} [isDeep] Specify a deep clone.
8307      * @param {Function} [customizer] The function to customize cloning values.
8308      * @param {*} [thisArg] The `this` binding of `customizer`.
8309      * @returns {*} Returns the cloned value.
8310      * @example
8311      *
8312      * var users = [
8313      *   { 'user': 'barney' },
8314      *   { 'user': 'fred' }
8315      * ];
8316      *
8317      * var shallow = _.clone(users);
8318      * shallow[0] === users[0];
8319      * // => true
8320      *
8321      * var deep = _.clone(users, true);
8322      * deep[0] === users[0];
8323      * // => false
8324      *
8325      * // using a customizer callback
8326      * var el = _.clone(document.body, function(value) {
8327      *   if (_.isElement(value)) {
8328      *     return value.cloneNode(false);
8329      *   }
8330      * });
8331      *
8332      * el === document.body
8333      * // => false
8334      * el.nodeName
8335      * // => BODY
8336      * el.childNodes.length;
8337      * // => 0
8338      */
8339     function clone(value, isDeep, customizer, thisArg) {
8340       if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
8341         isDeep = false;
8342       }
8343       else if (typeof isDeep == 'function') {
8344         thisArg = customizer;
8345         customizer = isDeep;
8346         isDeep = false;
8347       }
8348       return typeof customizer == 'function'
8349         ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))
8350         : baseClone(value, isDeep);
8351     }
8352
8353     /**
8354      * Creates a deep clone of `value`. If `customizer` is provided it is invoked
8355      * to produce the cloned values. If `customizer` returns `undefined` cloning
8356      * is handled by the method instead. The `customizer` is bound to `thisArg`
8357      * and invoked with two argument; (value [, index|key, object]).
8358      *
8359      * **Note:** This method is loosely based on the
8360      * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8361      * The enumerable properties of `arguments` objects and objects created by
8362      * constructors other than `Object` are cloned to plain `Object` objects. An
8363      * empty object is returned for uncloneable values such as functions, DOM nodes,
8364      * Maps, Sets, and WeakMaps.
8365      *
8366      * @static
8367      * @memberOf _
8368      * @category Lang
8369      * @param {*} value The value to deep clone.
8370      * @param {Function} [customizer] The function to customize cloning values.
8371      * @param {*} [thisArg] The `this` binding of `customizer`.
8372      * @returns {*} Returns the deep cloned value.
8373      * @example
8374      *
8375      * var users = [
8376      *   { 'user': 'barney' },
8377      *   { 'user': 'fred' }
8378      * ];
8379      *
8380      * var deep = _.cloneDeep(users);
8381      * deep[0] === users[0];
8382      * // => false
8383      *
8384      * // using a customizer callback
8385      * var el = _.cloneDeep(document.body, function(value) {
8386      *   if (_.isElement(value)) {
8387      *     return value.cloneNode(true);
8388      *   }
8389      * });
8390      *
8391      * el === document.body
8392      * // => false
8393      * el.nodeName
8394      * // => BODY
8395      * el.childNodes.length;
8396      * // => 20
8397      */
8398     function cloneDeep(value, customizer, thisArg) {
8399       return typeof customizer == 'function'
8400         ? baseClone(value, true, bindCallback(customizer, thisArg, 1))
8401         : baseClone(value, true);
8402     }
8403
8404     /**
8405      * Checks if `value` is greater than `other`.
8406      *
8407      * @static
8408      * @memberOf _
8409      * @category Lang
8410      * @param {*} value The value to compare.
8411      * @param {*} other The other value to compare.
8412      * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
8413      * @example
8414      *
8415      * _.gt(3, 1);
8416      * // => true
8417      *
8418      * _.gt(3, 3);
8419      * // => false
8420      *
8421      * _.gt(1, 3);
8422      * // => false
8423      */
8424     function gt(value, other) {
8425       return value > other;
8426     }
8427
8428     /**
8429      * Checks if `value` is greater than or equal to `other`.
8430      *
8431      * @static
8432      * @memberOf _
8433      * @category Lang
8434      * @param {*} value The value to compare.
8435      * @param {*} other The other value to compare.
8436      * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
8437      * @example
8438      *
8439      * _.gte(3, 1);
8440      * // => true
8441      *
8442      * _.gte(3, 3);
8443      * // => true
8444      *
8445      * _.gte(1, 3);
8446      * // => false
8447      */
8448     function gte(value, other) {
8449       return value >= other;
8450     }
8451
8452     /**
8453      * Checks if `value` is classified as an `arguments` object.
8454      *
8455      * @static
8456      * @memberOf _
8457      * @category Lang
8458      * @param {*} value The value to check.
8459      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8460      * @example
8461      *
8462      * _.isArguments(function() { return arguments; }());
8463      * // => true
8464      *
8465      * _.isArguments([1, 2, 3]);
8466      * // => false
8467      */
8468     function isArguments(value) {
8469       return isObjectLike(value) && isArrayLike(value) &&
8470         hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
8471     }
8472
8473     /**
8474      * Checks if `value` is classified as an `Array` object.
8475      *
8476      * @static
8477      * @memberOf _
8478      * @category Lang
8479      * @param {*} value The value to check.
8480      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8481      * @example
8482      *
8483      * _.isArray([1, 2, 3]);
8484      * // => true
8485      *
8486      * _.isArray(function() { return arguments; }());
8487      * // => false
8488      */
8489     var isArray = nativeIsArray || function(value) {
8490       return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
8491     };
8492
8493     /**
8494      * Checks if `value` is classified as a boolean primitive or object.
8495      *
8496      * @static
8497      * @memberOf _
8498      * @category Lang
8499      * @param {*} value The value to check.
8500      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8501      * @example
8502      *
8503      * _.isBoolean(false);
8504      * // => true
8505      *
8506      * _.isBoolean(null);
8507      * // => false
8508      */
8509     function isBoolean(value) {
8510       return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
8511     }
8512
8513     /**
8514      * Checks if `value` is classified as a `Date` object.
8515      *
8516      * @static
8517      * @memberOf _
8518      * @category Lang
8519      * @param {*} value The value to check.
8520      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8521      * @example
8522      *
8523      * _.isDate(new Date);
8524      * // => true
8525      *
8526      * _.isDate('Mon April 23 2012');
8527      * // => false
8528      */
8529     function isDate(value) {
8530       return isObjectLike(value) && objToString.call(value) == dateTag;
8531     }
8532
8533     /**
8534      * Checks if `value` is a DOM element.
8535      *
8536      * @static
8537      * @memberOf _
8538      * @category Lang
8539      * @param {*} value The value to check.
8540      * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
8541      * @example
8542      *
8543      * _.isElement(document.body);
8544      * // => true
8545      *
8546      * _.isElement('<body>');
8547      * // => false
8548      */
8549     function isElement(value) {
8550       return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
8551     }
8552
8553     /**
8554      * Checks if `value` is empty. A value is considered empty unless it is an
8555      * `arguments` object, array, string, or jQuery-like collection with a length
8556      * greater than `0` or an object with own enumerable properties.
8557      *
8558      * @static
8559      * @memberOf _
8560      * @category Lang
8561      * @param {Array|Object|string} value The value to inspect.
8562      * @returns {boolean} Returns `true` if `value` is empty, else `false`.
8563      * @example
8564      *
8565      * _.isEmpty(null);
8566      * // => true
8567      *
8568      * _.isEmpty(true);
8569      * // => true
8570      *
8571      * _.isEmpty(1);
8572      * // => true
8573      *
8574      * _.isEmpty([1, 2, 3]);
8575      * // => false
8576      *
8577      * _.isEmpty({ 'a': 1 });
8578      * // => false
8579      */
8580     function isEmpty(value) {
8581       if (value == null) {
8582         return true;
8583       }
8584       if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
8585           (isObjectLike(value) && isFunction(value.splice)))) {
8586         return !value.length;
8587       }
8588       return !keys(value).length;
8589     }
8590
8591     /**
8592      * Performs a deep comparison between two values to determine if they are
8593      * equivalent. If `customizer` is provided it is invoked to compare values.
8594      * If `customizer` returns `undefined` comparisons are handled by the method
8595      * instead. The `customizer` is bound to `thisArg` and invoked with three
8596      * arguments: (value, other [, index|key]).
8597      *
8598      * **Note:** This method supports comparing arrays, booleans, `Date` objects,
8599      * numbers, `Object` objects, regexes, and strings. Objects are compared by
8600      * their own, not inherited, enumerable properties. Functions and DOM nodes
8601      * are **not** supported. Provide a customizer function to extend support
8602      * for comparing other values.
8603      *
8604      * @static
8605      * @memberOf _
8606      * @alias eq
8607      * @category Lang
8608      * @param {*} value The value to compare.
8609      * @param {*} other The other value to compare.
8610      * @param {Function} [customizer] The function to customize value comparisons.
8611      * @param {*} [thisArg] The `this` binding of `customizer`.
8612      * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
8613      * @example
8614      *
8615      * var object = { 'user': 'fred' };
8616      * var other = { 'user': 'fred' };
8617      *
8618      * object == other;
8619      * // => false
8620      *
8621      * _.isEqual(object, other);
8622      * // => true
8623      *
8624      * // using a customizer callback
8625      * var array = ['hello', 'goodbye'];
8626      * var other = ['hi', 'goodbye'];
8627      *
8628      * _.isEqual(array, other, function(value, other) {
8629      *   if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
8630      *     return true;
8631      *   }
8632      * });
8633      * // => true
8634      */
8635     function isEqual(value, other, customizer, thisArg) {
8636       customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
8637       var result = customizer ? customizer(value, other) : undefined;
8638       return  result === undefined ? baseIsEqual(value, other, customizer) : !!result;
8639     }
8640
8641     /**
8642      * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
8643      * `SyntaxError`, `TypeError`, or `URIError` object.
8644      *
8645      * @static
8646      * @memberOf _
8647      * @category Lang
8648      * @param {*} value The value to check.
8649      * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
8650      * @example
8651      *
8652      * _.isError(new Error);
8653      * // => true
8654      *
8655      * _.isError(Error);
8656      * // => false
8657      */
8658     function isError(value) {
8659       return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
8660     }
8661
8662     /**
8663      * Checks if `value` is a finite primitive number.
8664      *
8665      * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
8666      *
8667      * @static
8668      * @memberOf _
8669      * @category Lang
8670      * @param {*} value The value to check.
8671      * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
8672      * @example
8673      *
8674      * _.isFinite(10);
8675      * // => true
8676      *
8677      * _.isFinite('10');
8678      * // => false
8679      *
8680      * _.isFinite(true);
8681      * // => false
8682      *
8683      * _.isFinite(Object(10));
8684      * // => false
8685      *
8686      * _.isFinite(Infinity);
8687      * // => false
8688      */
8689     function isFinite(value) {
8690       return typeof value == 'number' && nativeIsFinite(value);
8691     }
8692
8693     /**
8694      * Checks if `value` is classified as a `Function` object.
8695      *
8696      * @static
8697      * @memberOf _
8698      * @category Lang
8699      * @param {*} value The value to check.
8700      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8701      * @example
8702      *
8703      * _.isFunction(_);
8704      * // => true
8705      *
8706      * _.isFunction(/abc/);
8707      * // => false
8708      */
8709     function isFunction(value) {
8710       // The use of `Object#toString` avoids issues with the `typeof` operator
8711       // in older versions of Chrome and Safari which return 'function' for regexes
8712       // and Safari 8 equivalents which return 'object' for typed array constructors.
8713       return isObject(value) && objToString.call(value) == funcTag;
8714     }
8715
8716     /**
8717      * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
8718      * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
8719      *
8720      * @static
8721      * @memberOf _
8722      * @category Lang
8723      * @param {*} value The value to check.
8724      * @returns {boolean} Returns `true` if `value` is an object, else `false`.
8725      * @example
8726      *
8727      * _.isObject({});
8728      * // => true
8729      *
8730      * _.isObject([1, 2, 3]);
8731      * // => true
8732      *
8733      * _.isObject(1);
8734      * // => false
8735      */
8736     function isObject(value) {
8737       // Avoid a V8 JIT bug in Chrome 19-20.
8738       // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
8739       var type = typeof value;
8740       return !!value && (type == 'object' || type == 'function');
8741     }
8742
8743     /**
8744      * Performs a deep comparison between `object` and `source` to determine if
8745      * `object` contains equivalent property values. If `customizer` is provided
8746      * it is invoked to compare values. If `customizer` returns `undefined`
8747      * comparisons are handled by the method instead. The `customizer` is bound
8748      * to `thisArg` and invoked with three arguments: (value, other, index|key).
8749      *
8750      * **Note:** This method supports comparing properties of arrays, booleans,
8751      * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
8752      * and DOM nodes are **not** supported. Provide a customizer function to extend
8753      * support for comparing other values.
8754      *
8755      * @static
8756      * @memberOf _
8757      * @category Lang
8758      * @param {Object} object The object to inspect.
8759      * @param {Object} source The object of property values to match.
8760      * @param {Function} [customizer] The function to customize value comparisons.
8761      * @param {*} [thisArg] The `this` binding of `customizer`.
8762      * @returns {boolean} Returns `true` if `object` is a match, else `false`.
8763      * @example
8764      *
8765      * var object = { 'user': 'fred', 'age': 40 };
8766      *
8767      * _.isMatch(object, { 'age': 40 });
8768      * // => true
8769      *
8770      * _.isMatch(object, { 'age': 36 });
8771      * // => false
8772      *
8773      * // using a customizer callback
8774      * var object = { 'greeting': 'hello' };
8775      * var source = { 'greeting': 'hi' };
8776      *
8777      * _.isMatch(object, source, function(value, other) {
8778      *   return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
8779      * });
8780      * // => true
8781      */
8782     function isMatch(object, source, customizer, thisArg) {
8783       customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
8784       return baseIsMatch(object, getMatchData(source), customizer);
8785     }
8786
8787     /**
8788      * Checks if `value` is `NaN`.
8789      *
8790      * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
8791      * which returns `true` for `undefined` and other non-numeric values.
8792      *
8793      * @static
8794      * @memberOf _
8795      * @category Lang
8796      * @param {*} value The value to check.
8797      * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
8798      * @example
8799      *
8800      * _.isNaN(NaN);
8801      * // => true
8802      *
8803      * _.isNaN(new Number(NaN));
8804      * // => true
8805      *
8806      * isNaN(undefined);
8807      * // => true
8808      *
8809      * _.isNaN(undefined);
8810      * // => false
8811      */
8812     function isNaN(value) {
8813       // An `NaN` primitive is the only value that is not equal to itself.
8814       // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
8815       return isNumber(value) && value != +value;
8816     }
8817
8818     /**
8819      * Checks if `value` is a native function.
8820      *
8821      * @static
8822      * @memberOf _
8823      * @category Lang
8824      * @param {*} value The value to check.
8825      * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
8826      * @example
8827      *
8828      * _.isNative(Array.prototype.push);
8829      * // => true
8830      *
8831      * _.isNative(_);
8832      * // => false
8833      */
8834     function isNative(value) {
8835       if (value == null) {
8836         return false;
8837       }
8838       if (isFunction(value)) {
8839         return reIsNative.test(fnToString.call(value));
8840       }
8841       return isObjectLike(value) && reIsHostCtor.test(value);
8842     }
8843
8844     /**
8845      * Checks if `value` is `null`.
8846      *
8847      * @static
8848      * @memberOf _
8849      * @category Lang
8850      * @param {*} value The value to check.
8851      * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
8852      * @example
8853      *
8854      * _.isNull(null);
8855      * // => true
8856      *
8857      * _.isNull(void 0);
8858      * // => false
8859      */
8860     function isNull(value) {
8861       return value === null;
8862     }
8863
8864     /**
8865      * Checks if `value` is classified as a `Number` primitive or object.
8866      *
8867      * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
8868      * as numbers, use the `_.isFinite` method.
8869      *
8870      * @static
8871      * @memberOf _
8872      * @category Lang
8873      * @param {*} value The value to check.
8874      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8875      * @example
8876      *
8877      * _.isNumber(8.4);
8878      * // => true
8879      *
8880      * _.isNumber(NaN);
8881      * // => true
8882      *
8883      * _.isNumber('8.4');
8884      * // => false
8885      */
8886     function isNumber(value) {
8887       return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
8888     }
8889
8890     /**
8891      * Checks if `value` is a plain object, that is, an object created by the
8892      * `Object` constructor or one with a `[[Prototype]]` of `null`.
8893      *
8894      * **Note:** This method assumes objects created by the `Object` constructor
8895      * have no inherited enumerable properties.
8896      *
8897      * @static
8898      * @memberOf _
8899      * @category Lang
8900      * @param {*} value The value to check.
8901      * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
8902      * @example
8903      *
8904      * function Foo() {
8905      *   this.a = 1;
8906      * }
8907      *
8908      * _.isPlainObject(new Foo);
8909      * // => false
8910      *
8911      * _.isPlainObject([1, 2, 3]);
8912      * // => false
8913      *
8914      * _.isPlainObject({ 'x': 0, 'y': 0 });
8915      * // => true
8916      *
8917      * _.isPlainObject(Object.create(null));
8918      * // => true
8919      */
8920     function isPlainObject(value) {
8921       var Ctor;
8922
8923       // Exit early for non `Object` objects.
8924       if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
8925           (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
8926         return false;
8927       }
8928       // IE < 9 iterates inherited properties before own properties. If the first
8929       // iterated property is an object's own property then there are no inherited
8930       // enumerable properties.
8931       var result;
8932       // In most environments an object's own properties are iterated before
8933       // its inherited properties. If the last iterated property is an object's
8934       // own property then there are no inherited enumerable properties.
8935       baseForIn(value, function(subValue, key) {
8936         result = key;
8937       });
8938       return result === undefined || hasOwnProperty.call(value, result);
8939     }
8940
8941     /**
8942      * Checks if `value` is classified as a `RegExp` object.
8943      *
8944      * @static
8945      * @memberOf _
8946      * @category Lang
8947      * @param {*} value The value to check.
8948      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8949      * @example
8950      *
8951      * _.isRegExp(/abc/);
8952      * // => true
8953      *
8954      * _.isRegExp('/abc/');
8955      * // => false
8956      */
8957     function isRegExp(value) {
8958       return isObject(value) && objToString.call(value) == regexpTag;
8959     }
8960
8961     /**
8962      * Checks if `value` is classified as a `String` primitive or object.
8963      *
8964      * @static
8965      * @memberOf _
8966      * @category Lang
8967      * @param {*} value The value to check.
8968      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8969      * @example
8970      *
8971      * _.isString('abc');
8972      * // => true
8973      *
8974      * _.isString(1);
8975      * // => false
8976      */
8977     function isString(value) {
8978       return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
8979     }
8980
8981     /**
8982      * Checks if `value` is classified as a typed array.
8983      *
8984      * @static
8985      * @memberOf _
8986      * @category Lang
8987      * @param {*} value The value to check.
8988      * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8989      * @example
8990      *
8991      * _.isTypedArray(new Uint8Array);
8992      * // => true
8993      *
8994      * _.isTypedArray([]);
8995      * // => false
8996      */
8997     function isTypedArray(value) {
8998       return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
8999     }
9000
9001     /**
9002      * Checks if `value` is `undefined`.
9003      *
9004      * @static
9005      * @memberOf _
9006      * @category Lang
9007      * @param {*} value The value to check.
9008      * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
9009      * @example
9010      *
9011      * _.isUndefined(void 0);
9012      * // => true
9013      *
9014      * _.isUndefined(null);
9015      * // => false
9016      */
9017     function isUndefined(value) {
9018       return value === undefined;
9019     }
9020
9021     /**
9022      * Checks if `value` is less than `other`.
9023      *
9024      * @static
9025      * @memberOf _
9026      * @category Lang
9027      * @param {*} value The value to compare.
9028      * @param {*} other The other value to compare.
9029      * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
9030      * @example
9031      *
9032      * _.lt(1, 3);
9033      * // => true
9034      *
9035      * _.lt(3, 3);
9036      * // => false
9037      *
9038      * _.lt(3, 1);
9039      * // => false
9040      */
9041     function lt(value, other) {
9042       return value < other;
9043     }
9044
9045     /**
9046      * Checks if `value` is less than or equal to `other`.
9047      *
9048      * @static
9049      * @memberOf _
9050      * @category Lang
9051      * @param {*} value The value to compare.
9052      * @param {*} other The other value to compare.
9053      * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
9054      * @example
9055      *
9056      * _.lte(1, 3);
9057      * // => true
9058      *
9059      * _.lte(3, 3);
9060      * // => true
9061      *
9062      * _.lte(3, 1);
9063      * // => false
9064      */
9065     function lte(value, other) {
9066       return value <= other;
9067     }
9068
9069     /**
9070      * Converts `value` to an array.
9071      *
9072      * @static
9073      * @memberOf _
9074      * @category Lang
9075      * @param {*} value The value to convert.
9076      * @returns {Array} Returns the converted array.
9077      * @example
9078      *
9079      * (function() {
9080      *   return _.toArray(arguments).slice(1);
9081      * }(1, 2, 3));
9082      * // => [2, 3]
9083      */
9084     function toArray(value) {
9085       var length = value ? getLength(value) : 0;
9086       if (!isLength(length)) {
9087         return values(value);
9088       }
9089       if (!length) {
9090         return [];
9091       }
9092       return arrayCopy(value);
9093     }
9094
9095     /**
9096      * Converts `value` to a plain object flattening inherited enumerable
9097      * properties of `value` to own properties of the plain object.
9098      *
9099      * @static
9100      * @memberOf _
9101      * @category Lang
9102      * @param {*} value The value to convert.
9103      * @returns {Object} Returns the converted plain object.
9104      * @example
9105      *
9106      * function Foo() {
9107      *   this.b = 2;
9108      * }
9109      *
9110      * Foo.prototype.c = 3;
9111      *
9112      * _.assign({ 'a': 1 }, new Foo);
9113      * // => { 'a': 1, 'b': 2 }
9114      *
9115      * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
9116      * // => { 'a': 1, 'b': 2, 'c': 3 }
9117      */
9118     function toPlainObject(value) {
9119       return baseCopy(value, keysIn(value));
9120     }
9121
9122     /*------------------------------------------------------------------------*/
9123
9124     /**
9125      * Recursively merges own enumerable properties of the source object(s), that
9126      * don't resolve to `undefined` into the destination object. Subsequent sources
9127      * overwrite property assignments of previous sources. If `customizer` is
9128      * provided it is invoked to produce the merged values of the destination and
9129      * source properties. If `customizer` returns `undefined` merging is handled
9130      * by the method instead. The `customizer` is bound to `thisArg` and invoked
9131      * with five arguments: (objectValue, sourceValue, key, object, source).
9132      *
9133      * @static
9134      * @memberOf _
9135      * @category Object
9136      * @param {Object} object The destination object.
9137      * @param {...Object} [sources] The source objects.
9138      * @param {Function} [customizer] The function to customize assigned values.
9139      * @param {*} [thisArg] The `this` binding of `customizer`.
9140      * @returns {Object} Returns `object`.
9141      * @example
9142      *
9143      * var users = {
9144      *   'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
9145      * };
9146      *
9147      * var ages = {
9148      *   'data': [{ 'age': 36 }, { 'age': 40 }]
9149      * };
9150      *
9151      * _.merge(users, ages);
9152      * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
9153      *
9154      * // using a customizer callback
9155      * var object = {
9156      *   'fruits': ['apple'],
9157      *   'vegetables': ['beet']
9158      * };
9159      *
9160      * var other = {
9161      *   'fruits': ['banana'],
9162      *   'vegetables': ['carrot']
9163      * };
9164      *
9165      * _.merge(object, other, function(a, b) {
9166      *   if (_.isArray(a)) {
9167      *     return a.concat(b);
9168      *   }
9169      * });
9170      * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
9171      */
9172     var merge = createAssigner(baseMerge);
9173
9174     /**
9175      * Assigns own enumerable properties of source object(s) to the destination
9176      * object. Subsequent sources overwrite property assignments of previous sources.
9177      * If `customizer` is provided it is invoked to produce the assigned values.
9178      * The `customizer` is bound to `thisArg` and invoked with five arguments:
9179      * (objectValue, sourceValue, key, object, source).
9180      *
9181      * **Note:** This method mutates `object` and is based on
9182      * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
9183      *
9184      * @static
9185      * @memberOf _
9186      * @alias extend
9187      * @category Object
9188      * @param {Object} object The destination object.
9189      * @param {...Object} [sources] The source objects.
9190      * @param {Function} [customizer] The function to customize assigned values.
9191      * @param {*} [thisArg] The `this` binding of `customizer`.
9192      * @returns {Object} Returns `object`.
9193      * @example
9194      *
9195      * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
9196      * // => { 'user': 'fred', 'age': 40 }
9197      *
9198      * // using a customizer callback
9199      * var defaults = _.partialRight(_.assign, function(value, other) {
9200      *   return _.isUndefined(value) ? other : value;
9201      * });
9202      *
9203      * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9204      * // => { 'user': 'barney', 'age': 36 }
9205      */
9206     var assign = createAssigner(function(object, source, customizer) {
9207       return customizer
9208         ? assignWith(object, source, customizer)
9209         : baseAssign(object, source);
9210     });
9211
9212     /**
9213      * Creates an object that inherits from the given `prototype` object. If a
9214      * `properties` object is provided its own enumerable properties are assigned
9215      * to the created object.
9216      *
9217      * @static
9218      * @memberOf _
9219      * @category Object
9220      * @param {Object} prototype The object to inherit from.
9221      * @param {Object} [properties] The properties to assign to the object.
9222      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9223      * @returns {Object} Returns the new object.
9224      * @example
9225      *
9226      * function Shape() {
9227      *   this.x = 0;
9228      *   this.y = 0;
9229      * }
9230      *
9231      * function Circle() {
9232      *   Shape.call(this);
9233      * }
9234      *
9235      * Circle.prototype = _.create(Shape.prototype, {
9236      *   'constructor': Circle
9237      * });
9238      *
9239      * var circle = new Circle;
9240      * circle instanceof Circle;
9241      * // => true
9242      *
9243      * circle instanceof Shape;
9244      * // => true
9245      */
9246     function create(prototype, properties, guard) {
9247       var result = baseCreate(prototype);
9248       if (guard && isIterateeCall(prototype, properties, guard)) {
9249         properties = undefined;
9250       }
9251       return properties ? baseAssign(result, properties) : result;
9252     }
9253
9254     /**
9255      * Assigns own enumerable properties of source object(s) to the destination
9256      * object for all destination properties that resolve to `undefined`. Once a
9257      * property is set, additional values of the same property are ignored.
9258      *
9259      * **Note:** This method mutates `object`.
9260      *
9261      * @static
9262      * @memberOf _
9263      * @category Object
9264      * @param {Object} object The destination object.
9265      * @param {...Object} [sources] The source objects.
9266      * @returns {Object} Returns `object`.
9267      * @example
9268      *
9269      * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9270      * // => { 'user': 'barney', 'age': 36 }
9271      */
9272     var defaults = createDefaults(assign, assignDefaults);
9273
9274     /**
9275      * This method is like `_.defaults` except that it recursively assigns
9276      * default properties.
9277      *
9278      * **Note:** This method mutates `object`.
9279      *
9280      * @static
9281      * @memberOf _
9282      * @category Object
9283      * @param {Object} object The destination object.
9284      * @param {...Object} [sources] The source objects.
9285      * @returns {Object} Returns `object`.
9286      * @example
9287      *
9288      * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
9289      * // => { 'user': { 'name': 'barney', 'age': 36 } }
9290      *
9291      */
9292     var defaultsDeep = createDefaults(merge, mergeDefaults);
9293
9294     /**
9295      * This method is like `_.find` except that it returns the key of the first
9296      * element `predicate` returns truthy for instead of the element itself.
9297      *
9298      * If a property name is provided for `predicate` the created `_.property`
9299      * style callback returns the property value of the given element.
9300      *
9301      * If a value is also provided for `thisArg` the created `_.matchesProperty`
9302      * style callback returns `true` for elements that have a matching property
9303      * value, else `false`.
9304      *
9305      * If an object is provided for `predicate` the created `_.matches` style
9306      * callback returns `true` for elements that have the properties of the given
9307      * object, else `false`.
9308      *
9309      * @static
9310      * @memberOf _
9311      * @category Object
9312      * @param {Object} object The object to search.
9313      * @param {Function|Object|string} [predicate=_.identity] The function invoked
9314      *  per iteration.
9315      * @param {*} [thisArg] The `this` binding of `predicate`.
9316      * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9317      * @example
9318      *
9319      * var users = {
9320      *   'barney':  { 'age': 36, 'active': true },
9321      *   'fred':    { 'age': 40, 'active': false },
9322      *   'pebbles': { 'age': 1,  'active': true }
9323      * };
9324      *
9325      * _.findKey(users, function(chr) {
9326      *   return chr.age < 40;
9327      * });
9328      * // => 'barney' (iteration order is not guaranteed)
9329      *
9330      * // using the `_.matches` callback shorthand
9331      * _.findKey(users, { 'age': 1, 'active': true });
9332      * // => 'pebbles'
9333      *
9334      * // using the `_.matchesProperty` callback shorthand
9335      * _.findKey(users, 'active', false);
9336      * // => 'fred'
9337      *
9338      * // using the `_.property` callback shorthand
9339      * _.findKey(users, 'active');
9340      * // => 'barney'
9341      */
9342     var findKey = createFindKey(baseForOwn);
9343
9344     /**
9345      * This method is like `_.findKey` except that it iterates over elements of
9346      * a collection in the opposite order.
9347      *
9348      * If a property name is provided for `predicate` the created `_.property`
9349      * style callback returns the property value of the given element.
9350      *
9351      * If a value is also provided for `thisArg` the created `_.matchesProperty`
9352      * style callback returns `true` for elements that have a matching property
9353      * value, else `false`.
9354      *
9355      * If an object is provided for `predicate` the created `_.matches` style
9356      * callback returns `true` for elements that have the properties of the given
9357      * object, else `false`.
9358      *
9359      * @static
9360      * @memberOf _
9361      * @category Object
9362      * @param {Object} object The object to search.
9363      * @param {Function|Object|string} [predicate=_.identity] The function invoked
9364      *  per iteration.
9365      * @param {*} [thisArg] The `this` binding of `predicate`.
9366      * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9367      * @example
9368      *
9369      * var users = {
9370      *   'barney':  { 'age': 36, 'active': true },
9371      *   'fred':    { 'age': 40, 'active': false },
9372      *   'pebbles': { 'age': 1,  'active': true }
9373      * };
9374      *
9375      * _.findLastKey(users, function(chr) {
9376      *   return chr.age < 40;
9377      * });
9378      * // => returns `pebbles` assuming `_.findKey` returns `barney`
9379      *
9380      * // using the `_.matches` callback shorthand
9381      * _.findLastKey(users, { 'age': 36, 'active': true });
9382      * // => 'barney'
9383      *
9384      * // using the `_.matchesProperty` callback shorthand
9385      * _.findLastKey(users, 'active', false);
9386      * // => 'fred'
9387      *
9388      * // using the `_.property` callback shorthand
9389      * _.findLastKey(users, 'active');
9390      * // => 'pebbles'
9391      */
9392     var findLastKey = createFindKey(baseForOwnRight);
9393
9394     /**
9395      * Iterates over own and inherited enumerable properties of an object invoking
9396      * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
9397      * with three arguments: (value, key, object). Iteratee functions may exit
9398      * iteration early by explicitly returning `false`.
9399      *
9400      * @static
9401      * @memberOf _
9402      * @category Object
9403      * @param {Object} object The object to iterate over.
9404      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9405      * @param {*} [thisArg] The `this` binding of `iteratee`.
9406      * @returns {Object} Returns `object`.
9407      * @example
9408      *
9409      * function Foo() {
9410      *   this.a = 1;
9411      *   this.b = 2;
9412      * }
9413      *
9414      * Foo.prototype.c = 3;
9415      *
9416      * _.forIn(new Foo, function(value, key) {
9417      *   console.log(key);
9418      * });
9419      * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
9420      */
9421     var forIn = createForIn(baseFor);
9422
9423     /**
9424      * This method is like `_.forIn` except that it iterates over properties of
9425      * `object` in the opposite order.
9426      *
9427      * @static
9428      * @memberOf _
9429      * @category Object
9430      * @param {Object} object The object to iterate over.
9431      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9432      * @param {*} [thisArg] The `this` binding of `iteratee`.
9433      * @returns {Object} Returns `object`.
9434      * @example
9435      *
9436      * function Foo() {
9437      *   this.a = 1;
9438      *   this.b = 2;
9439      * }
9440      *
9441      * Foo.prototype.c = 3;
9442      *
9443      * _.forInRight(new Foo, function(value, key) {
9444      *   console.log(key);
9445      * });
9446      * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
9447      */
9448     var forInRight = createForIn(baseForRight);
9449
9450     /**
9451      * Iterates over own enumerable properties of an object invoking `iteratee`
9452      * for each property. The `iteratee` is bound to `thisArg` and invoked with
9453      * three arguments: (value, key, object). Iteratee functions may exit iteration
9454      * early by explicitly returning `false`.
9455      *
9456      * @static
9457      * @memberOf _
9458      * @category Object
9459      * @param {Object} object The object to iterate over.
9460      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9461      * @param {*} [thisArg] The `this` binding of `iteratee`.
9462      * @returns {Object} Returns `object`.
9463      * @example
9464      *
9465      * function Foo() {
9466      *   this.a = 1;
9467      *   this.b = 2;
9468      * }
9469      *
9470      * Foo.prototype.c = 3;
9471      *
9472      * _.forOwn(new Foo, function(value, key) {
9473      *   console.log(key);
9474      * });
9475      * // => logs 'a' and 'b' (iteration order is not guaranteed)
9476      */
9477     var forOwn = createForOwn(baseForOwn);
9478
9479     /**
9480      * This method is like `_.forOwn` except that it iterates over properties of
9481      * `object` in the opposite order.
9482      *
9483      * @static
9484      * @memberOf _
9485      * @category Object
9486      * @param {Object} object The object to iterate over.
9487      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9488      * @param {*} [thisArg] The `this` binding of `iteratee`.
9489      * @returns {Object} Returns `object`.
9490      * @example
9491      *
9492      * function Foo() {
9493      *   this.a = 1;
9494      *   this.b = 2;
9495      * }
9496      *
9497      * Foo.prototype.c = 3;
9498      *
9499      * _.forOwnRight(new Foo, function(value, key) {
9500      *   console.log(key);
9501      * });
9502      * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
9503      */
9504     var forOwnRight = createForOwn(baseForOwnRight);
9505
9506     /**
9507      * Creates an array of function property names from all enumerable properties,
9508      * own and inherited, of `object`.
9509      *
9510      * @static
9511      * @memberOf _
9512      * @alias methods
9513      * @category Object
9514      * @param {Object} object The object to inspect.
9515      * @returns {Array} Returns the new array of property names.
9516      * @example
9517      *
9518      * _.functions(_);
9519      * // => ['after', 'ary', 'assign', ...]
9520      */
9521     function functions(object) {
9522       return baseFunctions(object, keysIn(object));
9523     }
9524
9525     /**
9526      * Gets the property value at `path` of `object`. If the resolved value is
9527      * `undefined` the `defaultValue` is used in its place.
9528      *
9529      * @static
9530      * @memberOf _
9531      * @category Object
9532      * @param {Object} object The object to query.
9533      * @param {Array|string} path The path of the property to get.
9534      * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9535      * @returns {*} Returns the resolved value.
9536      * @example
9537      *
9538      * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9539      *
9540      * _.get(object, 'a[0].b.c');
9541      * // => 3
9542      *
9543      * _.get(object, ['a', '0', 'b', 'c']);
9544      * // => 3
9545      *
9546      * _.get(object, 'a.b.c', 'default');
9547      * // => 'default'
9548      */
9549     function get(object, path, defaultValue) {
9550       var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
9551       return result === undefined ? defaultValue : result;
9552     }
9553
9554     /**
9555      * Checks if `path` is a direct property.
9556      *
9557      * @static
9558      * @memberOf _
9559      * @category Object
9560      * @param {Object} object The object to query.
9561      * @param {Array|string} path The path to check.
9562      * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
9563      * @example
9564      *
9565      * var object = { 'a': { 'b': { 'c': 3 } } };
9566      *
9567      * _.has(object, 'a');
9568      * // => true
9569      *
9570      * _.has(object, 'a.b.c');
9571      * // => true
9572      *
9573      * _.has(object, ['a', 'b', 'c']);
9574      * // => true
9575      */
9576     function has(object, path) {
9577       if (object == null) {
9578         return false;
9579       }
9580       var result = hasOwnProperty.call(object, path);
9581       if (!result && !isKey(path)) {
9582         path = toPath(path);
9583         object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9584         if (object == null) {
9585           return false;
9586         }
9587         path = last(path);
9588         result = hasOwnProperty.call(object, path);
9589       }
9590       return result || (isLength(object.length) && isIndex(path, object.length) &&
9591         (isArray(object) || isArguments(object)));
9592     }
9593
9594     /**
9595      * Creates an object composed of the inverted keys and values of `object`.
9596      * If `object` contains duplicate values, subsequent values overwrite property
9597      * assignments of previous values unless `multiValue` is `true`.
9598      *
9599      * @static
9600      * @memberOf _
9601      * @category Object
9602      * @param {Object} object The object to invert.
9603      * @param {boolean} [multiValue] Allow multiple values per key.
9604      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9605      * @returns {Object} Returns the new inverted object.
9606      * @example
9607      *
9608      * var object = { 'a': 1, 'b': 2, 'c': 1 };
9609      *
9610      * _.invert(object);
9611      * // => { '1': 'c', '2': 'b' }
9612      *
9613      * // with `multiValue`
9614      * _.invert(object, true);
9615      * // => { '1': ['a', 'c'], '2': ['b'] }
9616      */
9617     function invert(object, multiValue, guard) {
9618       if (guard && isIterateeCall(object, multiValue, guard)) {
9619         multiValue = undefined;
9620       }
9621       var index = -1,
9622           props = keys(object),
9623           length = props.length,
9624           result = {};
9625
9626       while (++index < length) {
9627         var key = props[index],
9628             value = object[key];
9629
9630         if (multiValue) {
9631           if (hasOwnProperty.call(result, value)) {
9632             result[value].push(key);
9633           } else {
9634             result[value] = [key];
9635           }
9636         }
9637         else {
9638           result[value] = key;
9639         }
9640       }
9641       return result;
9642     }
9643
9644     /**
9645      * Creates an array of the own enumerable property names of `object`.
9646      *
9647      * **Note:** Non-object values are coerced to objects. See the
9648      * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
9649      * for more details.
9650      *
9651      * @static
9652      * @memberOf _
9653      * @category Object
9654      * @param {Object} object The object to query.
9655      * @returns {Array} Returns the array of property names.
9656      * @example
9657      *
9658      * function Foo() {
9659      *   this.a = 1;
9660      *   this.b = 2;
9661      * }
9662      *
9663      * Foo.prototype.c = 3;
9664      *
9665      * _.keys(new Foo);
9666      * // => ['a', 'b'] (iteration order is not guaranteed)
9667      *
9668      * _.keys('hi');
9669      * // => ['0', '1']
9670      */
9671     var keys = !nativeKeys ? shimKeys : function(object) {
9672       var Ctor = object == null ? undefined : object.constructor;
9673       if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
9674           (typeof object != 'function' && isArrayLike(object))) {
9675         return shimKeys(object);
9676       }
9677       return isObject(object) ? nativeKeys(object) : [];
9678     };
9679
9680     /**
9681      * Creates an array of the own and inherited enumerable property names of `object`.
9682      *
9683      * **Note:** Non-object values are coerced to objects.
9684      *
9685      * @static
9686      * @memberOf _
9687      * @category Object
9688      * @param {Object} object The object to query.
9689      * @returns {Array} Returns the array of property names.
9690      * @example
9691      *
9692      * function Foo() {
9693      *   this.a = 1;
9694      *   this.b = 2;
9695      * }
9696      *
9697      * Foo.prototype.c = 3;
9698      *
9699      * _.keysIn(new Foo);
9700      * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
9701      */
9702     function keysIn(object) {
9703       if (object == null) {
9704         return [];
9705       }
9706       if (!isObject(object)) {
9707         object = Object(object);
9708       }
9709       var length = object.length;
9710       length = (length && isLength(length) &&
9711         (isArray(object) || isArguments(object)) && length) || 0;
9712
9713       var Ctor = object.constructor,
9714           index = -1,
9715           isProto = typeof Ctor == 'function' && Ctor.prototype === object,
9716           result = Array(length),
9717           skipIndexes = length > 0;
9718
9719       while (++index < length) {
9720         result[index] = (index + '');
9721       }
9722       for (var key in object) {
9723         if (!(skipIndexes && isIndex(key, length)) &&
9724             !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
9725           result.push(key);
9726         }
9727       }
9728       return result;
9729     }
9730
9731     /**
9732      * The opposite of `_.mapValues`; this method creates an object with the
9733      * same values as `object` and keys generated by running each own enumerable
9734      * property of `object` through `iteratee`.
9735      *
9736      * @static
9737      * @memberOf _
9738      * @category Object
9739      * @param {Object} object The object to iterate over.
9740      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9741      *  per iteration.
9742      * @param {*} [thisArg] The `this` binding of `iteratee`.
9743      * @returns {Object} Returns the new mapped object.
9744      * @example
9745      *
9746      * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
9747      *   return key + value;
9748      * });
9749      * // => { 'a1': 1, 'b2': 2 }
9750      */
9751     var mapKeys = createObjectMapper(true);
9752
9753     /**
9754      * Creates an object with the same keys as `object` and values generated by
9755      * running each own enumerable property of `object` through `iteratee`. The
9756      * iteratee function is bound to `thisArg` and invoked with three arguments:
9757      * (value, key, object).
9758      *
9759      * If a property name is provided for `iteratee` the created `_.property`
9760      * style callback returns the property value of the given element.
9761      *
9762      * If a value is also provided for `thisArg` the created `_.matchesProperty`
9763      * style callback returns `true` for elements that have a matching property
9764      * value, else `false`.
9765      *
9766      * If an object is provided for `iteratee` the created `_.matches` style
9767      * callback returns `true` for elements that have the properties of the given
9768      * object, else `false`.
9769      *
9770      * @static
9771      * @memberOf _
9772      * @category Object
9773      * @param {Object} object The object to iterate over.
9774      * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9775      *  per iteration.
9776      * @param {*} [thisArg] The `this` binding of `iteratee`.
9777      * @returns {Object} Returns the new mapped object.
9778      * @example
9779      *
9780      * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
9781      *   return n * 3;
9782      * });
9783      * // => { 'a': 3, 'b': 6 }
9784      *
9785      * var users = {
9786      *   'fred':    { 'user': 'fred',    'age': 40 },
9787      *   'pebbles': { 'user': 'pebbles', 'age': 1 }
9788      * };
9789      *
9790      * // using the `_.property` callback shorthand
9791      * _.mapValues(users, 'age');
9792      * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
9793      */
9794     var mapValues = createObjectMapper();
9795
9796     /**
9797      * The opposite of `_.pick`; this method creates an object composed of the
9798      * own and inherited enumerable properties of `object` that are not omitted.
9799      *
9800      * @static
9801      * @memberOf _
9802      * @category Object
9803      * @param {Object} object The source object.
9804      * @param {Function|...(string|string[])} [predicate] The function invoked per
9805      *  iteration or property names to omit, specified as individual property
9806      *  names or arrays of property names.
9807      * @param {*} [thisArg] The `this` binding of `predicate`.
9808      * @returns {Object} Returns the new object.
9809      * @example
9810      *
9811      * var object = { 'user': 'fred', 'age': 40 };
9812      *
9813      * _.omit(object, 'age');
9814      * // => { 'user': 'fred' }
9815      *
9816      * _.omit(object, _.isNumber);
9817      * // => { 'user': 'fred' }
9818      */
9819     var omit = restParam(function(object, props) {
9820       if (object == null) {
9821         return {};
9822       }
9823       if (typeof props[0] != 'function') {
9824         var props = arrayMap(baseFlatten(props), String);
9825         return pickByArray(object, baseDifference(keysIn(object), props));
9826       }
9827       var predicate = bindCallback(props[0], props[1], 3);
9828       return pickByCallback(object, function(value, key, object) {
9829         return !predicate(value, key, object);
9830       });
9831     });
9832
9833     /**
9834      * Creates a two dimensional array of the key-value pairs for `object`,
9835      * e.g. `[[key1, value1], [key2, value2]]`.
9836      *
9837      * @static
9838      * @memberOf _
9839      * @category Object
9840      * @param {Object} object The object to query.
9841      * @returns {Array} Returns the new array of key-value pairs.
9842      * @example
9843      *
9844      * _.pairs({ 'barney': 36, 'fred': 40 });
9845      * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
9846      */
9847     function pairs(object) {
9848       object = toObject(object);
9849
9850       var index = -1,
9851           props = keys(object),
9852           length = props.length,
9853           result = Array(length);
9854
9855       while (++index < length) {
9856         var key = props[index];
9857         result[index] = [key, object[key]];
9858       }
9859       return result;
9860     }
9861
9862     /**
9863      * Creates an object composed of the picked `object` properties. Property
9864      * names may be specified as individual arguments or as arrays of property
9865      * names. If `predicate` is provided it is invoked for each property of `object`
9866      * picking the properties `predicate` returns truthy for. The predicate is
9867      * bound to `thisArg` and invoked with three arguments: (value, key, object).
9868      *
9869      * @static
9870      * @memberOf _
9871      * @category Object
9872      * @param {Object} object The source object.
9873      * @param {Function|...(string|string[])} [predicate] The function invoked per
9874      *  iteration or property names to pick, specified as individual property
9875      *  names or arrays of property names.
9876      * @param {*} [thisArg] The `this` binding of `predicate`.
9877      * @returns {Object} Returns the new object.
9878      * @example
9879      *
9880      * var object = { 'user': 'fred', 'age': 40 };
9881      *
9882      * _.pick(object, 'user');
9883      * // => { 'user': 'fred' }
9884      *
9885      * _.pick(object, _.isString);
9886      * // => { 'user': 'fred' }
9887      */
9888     var pick = restParam(function(object, props) {
9889       if (object == null) {
9890         return {};
9891       }
9892       return typeof props[0] == 'function'
9893         ? pickByCallback(object, bindCallback(props[0], props[1], 3))
9894         : pickByArray(object, baseFlatten(props));
9895     });
9896
9897     /**
9898      * This method is like `_.get` except that if the resolved value is a function
9899      * it is invoked with the `this` binding of its parent object and its result
9900      * is returned.
9901      *
9902      * @static
9903      * @memberOf _
9904      * @category Object
9905      * @param {Object} object The object to query.
9906      * @param {Array|string} path The path of the property to resolve.
9907      * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9908      * @returns {*} Returns the resolved value.
9909      * @example
9910      *
9911      * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
9912      *
9913      * _.result(object, 'a[0].b.c1');
9914      * // => 3
9915      *
9916      * _.result(object, 'a[0].b.c2');
9917      * // => 4
9918      *
9919      * _.result(object, 'a.b.c', 'default');
9920      * // => 'default'
9921      *
9922      * _.result(object, 'a.b.c', _.constant('default'));
9923      * // => 'default'
9924      */
9925     function result(object, path, defaultValue) {
9926       var result = object == null ? undefined : object[path];
9927       if (result === undefined) {
9928         if (object != null && !isKey(path, object)) {
9929           path = toPath(path);
9930           object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9931           result = object == null ? undefined : object[last(path)];
9932         }
9933         result = result === undefined ? defaultValue : result;
9934       }
9935       return isFunction(result) ? result.call(object) : result;
9936     }
9937
9938     /**
9939      * Sets the property value of `path` on `object`. If a portion of `path`
9940      * does not exist it is created.
9941      *
9942      * @static
9943      * @memberOf _
9944      * @category Object
9945      * @param {Object} object The object to augment.
9946      * @param {Array|string} path The path of the property to set.
9947      * @param {*} value The value to set.
9948      * @returns {Object} Returns `object`.
9949      * @example
9950      *
9951      * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9952      *
9953      * _.set(object, 'a[0].b.c', 4);
9954      * console.log(object.a[0].b.c);
9955      * // => 4
9956      *
9957      * _.set(object, 'x[0].y.z', 5);
9958      * console.log(object.x[0].y.z);
9959      * // => 5
9960      */
9961     function set(object, path, value) {
9962       if (object == null) {
9963         return object;
9964       }
9965       var pathKey = (path + '');
9966       path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
9967
9968       var index = -1,
9969           length = path.length,
9970           lastIndex = length - 1,
9971           nested = object;
9972
9973       while (nested != null && ++index < length) {
9974         var key = path[index];
9975         if (isObject(nested)) {
9976           if (index == lastIndex) {
9977             nested[key] = value;
9978           } else if (nested[key] == null) {
9979             nested[key] = isIndex(path[index + 1]) ? [] : {};
9980           }
9981         }
9982         nested = nested[key];
9983       }
9984       return object;
9985     }
9986
9987     /**
9988      * An alternative to `_.reduce`; this method transforms `object` to a new
9989      * `accumulator` object which is the result of running each of its own enumerable
9990      * properties through `iteratee`, with each invocation potentially mutating
9991      * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
9992      * with four arguments: (accumulator, value, key, object). Iteratee functions
9993      * may exit iteration early by explicitly returning `false`.
9994      *
9995      * @static
9996      * @memberOf _
9997      * @category Object
9998      * @param {Array|Object} object The object to iterate over.
9999      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10000      * @param {*} [accumulator] The custom accumulator value.
10001      * @param {*} [thisArg] The `this` binding of `iteratee`.
10002      * @returns {*} Returns the accumulated value.
10003      * @example
10004      *
10005      * _.transform([2, 3, 4], function(result, n) {
10006      *   result.push(n *= n);
10007      *   return n % 2 == 0;
10008      * });
10009      * // => [4, 9]
10010      *
10011      * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
10012      *   result[key] = n * 3;
10013      * });
10014      * // => { 'a': 3, 'b': 6 }
10015      */
10016     function transform(object, iteratee, accumulator, thisArg) {
10017       var isArr = isArray(object) || isTypedArray(object);
10018       iteratee = getCallback(iteratee, thisArg, 4);
10019
10020       if (accumulator == null) {
10021         if (isArr || isObject(object)) {
10022           var Ctor = object.constructor;
10023           if (isArr) {
10024             accumulator = isArray(object) ? new Ctor : [];
10025           } else {
10026             accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
10027           }
10028         } else {
10029           accumulator = {};
10030         }
10031       }
10032       (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
10033         return iteratee(accumulator, value, index, object);
10034       });
10035       return accumulator;
10036     }
10037
10038     /**
10039      * Creates an array of the own enumerable property values of `object`.
10040      *
10041      * **Note:** Non-object values are coerced to objects.
10042      *
10043      * @static
10044      * @memberOf _
10045      * @category Object
10046      * @param {Object} object The object to query.
10047      * @returns {Array} Returns the array of property values.
10048      * @example
10049      *
10050      * function Foo() {
10051      *   this.a = 1;
10052      *   this.b = 2;
10053      * }
10054      *
10055      * Foo.prototype.c = 3;
10056      *
10057      * _.values(new Foo);
10058      * // => [1, 2] (iteration order is not guaranteed)
10059      *
10060      * _.values('hi');
10061      * // => ['h', 'i']
10062      */
10063     function values(object) {
10064       return baseValues(object, keys(object));
10065     }
10066
10067     /**
10068      * Creates an array of the own and inherited enumerable property values
10069      * of `object`.
10070      *
10071      * **Note:** Non-object values are coerced to objects.
10072      *
10073      * @static
10074      * @memberOf _
10075      * @category Object
10076      * @param {Object} object The object to query.
10077      * @returns {Array} Returns the array of property values.
10078      * @example
10079      *
10080      * function Foo() {
10081      *   this.a = 1;
10082      *   this.b = 2;
10083      * }
10084      *
10085      * Foo.prototype.c = 3;
10086      *
10087      * _.valuesIn(new Foo);
10088      * // => [1, 2, 3] (iteration order is not guaranteed)
10089      */
10090     function valuesIn(object) {
10091       return baseValues(object, keysIn(object));
10092     }
10093
10094     /*------------------------------------------------------------------------*/
10095
10096     /**
10097      * Checks if `n` is between `start` and up to but not including, `end`. If
10098      * `end` is not specified it is set to `start` with `start` then set to `0`.
10099      *
10100      * @static
10101      * @memberOf _
10102      * @category Number
10103      * @param {number} n The number to check.
10104      * @param {number} [start=0] The start of the range.
10105      * @param {number} end The end of the range.
10106      * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
10107      * @example
10108      *
10109      * _.inRange(3, 2, 4);
10110      * // => true
10111      *
10112      * _.inRange(4, 8);
10113      * // => true
10114      *
10115      * _.inRange(4, 2);
10116      * // => false
10117      *
10118      * _.inRange(2, 2);
10119      * // => false
10120      *
10121      * _.inRange(1.2, 2);
10122      * // => true
10123      *
10124      * _.inRange(5.2, 4);
10125      * // => false
10126      */
10127     function inRange(value, start, end) {
10128       start = +start || 0;
10129       if (end === undefined) {
10130         end = start;
10131         start = 0;
10132       } else {
10133         end = +end || 0;
10134       }
10135       return value >= nativeMin(start, end) && value < nativeMax(start, end);
10136     }
10137
10138     /**
10139      * Produces a random number between `min` and `max` (inclusive). If only one
10140      * argument is provided a number between `0` and the given number is returned.
10141      * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
10142      * number is returned instead of an integer.
10143      *
10144      * @static
10145      * @memberOf _
10146      * @category Number
10147      * @param {number} [min=0] The minimum possible value.
10148      * @param {number} [max=1] The maximum possible value.
10149      * @param {boolean} [floating] Specify returning a floating-point number.
10150      * @returns {number} Returns the random number.
10151      * @example
10152      *
10153      * _.random(0, 5);
10154      * // => an integer between 0 and 5
10155      *
10156      * _.random(5);
10157      * // => also an integer between 0 and 5
10158      *
10159      * _.random(5, true);
10160      * // => a floating-point number between 0 and 5
10161      *
10162      * _.random(1.2, 5.2);
10163      * // => a floating-point number between 1.2 and 5.2
10164      */
10165     function random(min, max, floating) {
10166       if (floating && isIterateeCall(min, max, floating)) {
10167         max = floating = undefined;
10168       }
10169       var noMin = min == null,
10170           noMax = max == null;
10171
10172       if (floating == null) {
10173         if (noMax && typeof min == 'boolean') {
10174           floating = min;
10175           min = 1;
10176         }
10177         else if (typeof max == 'boolean') {
10178           floating = max;
10179           noMax = true;
10180         }
10181       }
10182       if (noMin && noMax) {
10183         max = 1;
10184         noMax = false;
10185       }
10186       min = +min || 0;
10187       if (noMax) {
10188         max = min;
10189         min = 0;
10190       } else {
10191         max = +max || 0;
10192       }
10193       if (floating || min % 1 || max % 1) {
10194         var rand = nativeRandom();
10195         return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
10196       }
10197       return baseRandom(min, max);
10198     }
10199
10200     /*------------------------------------------------------------------------*/
10201
10202     /**
10203      * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
10204      *
10205      * @static
10206      * @memberOf _
10207      * @category String
10208      * @param {string} [string=''] The string to convert.
10209      * @returns {string} Returns the camel cased string.
10210      * @example
10211      *
10212      * _.camelCase('Foo Bar');
10213      * // => 'fooBar'
10214      *
10215      * _.camelCase('--foo-bar');
10216      * // => 'fooBar'
10217      *
10218      * _.camelCase('__foo_bar__');
10219      * // => 'fooBar'
10220      */
10221     var camelCase = createCompounder(function(result, word, index) {
10222       word = word.toLowerCase();
10223       return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
10224     });
10225
10226     /**
10227      * Capitalizes the first character of `string`.
10228      *
10229      * @static
10230      * @memberOf _
10231      * @category String
10232      * @param {string} [string=''] The string to capitalize.
10233      * @returns {string} Returns the capitalized string.
10234      * @example
10235      *
10236      * _.capitalize('fred');
10237      * // => 'Fred'
10238      */
10239     function capitalize(string) {
10240       string = baseToString(string);
10241       return string && (string.charAt(0).toUpperCase() + string.slice(1));
10242     }
10243
10244     /**
10245      * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
10246      * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
10247      *
10248      * @static
10249      * @memberOf _
10250      * @category String
10251      * @param {string} [string=''] The string to deburr.
10252      * @returns {string} Returns the deburred string.
10253      * @example
10254      *
10255      * _.deburr('déjà vu');
10256      * // => 'deja vu'
10257      */
10258     function deburr(string) {
10259       string = baseToString(string);
10260       return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
10261     }
10262
10263     /**
10264      * Checks if `string` ends with the given target string.
10265      *
10266      * @static
10267      * @memberOf _
10268      * @category String
10269      * @param {string} [string=''] The string to search.
10270      * @param {string} [target] The string to search for.
10271      * @param {number} [position=string.length] The position to search from.
10272      * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
10273      * @example
10274      *
10275      * _.endsWith('abc', 'c');
10276      * // => true
10277      *
10278      * _.endsWith('abc', 'b');
10279      * // => false
10280      *
10281      * _.endsWith('abc', 'b', 2);
10282      * // => true
10283      */
10284     function endsWith(string, target, position) {
10285       string = baseToString(string);
10286       target = (target + '');
10287
10288       var length = string.length;
10289       position = position === undefined
10290         ? length
10291         : nativeMin(position < 0 ? 0 : (+position || 0), length);
10292
10293       position -= target.length;
10294       return position >= 0 && string.indexOf(target, position) == position;
10295     }
10296
10297     /**
10298      * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
10299      * their corresponding HTML entities.
10300      *
10301      * **Note:** No other characters are escaped. To escape additional characters
10302      * use a third-party library like [_he_](https://mths.be/he).
10303      *
10304      * Though the ">" character is escaped for symmetry, characters like
10305      * ">" and "/" don't need escaping in HTML and have no special meaning
10306      * unless they're part of a tag or unquoted attribute value.
10307      * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
10308      * (under "semi-related fun fact") for more details.
10309      *
10310      * Backticks are escaped because in Internet Explorer < 9, they can break out
10311      * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
10312      * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
10313      * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
10314      * for more details.
10315      *
10316      * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
10317      * to reduce XSS vectors.
10318      *
10319      * @static
10320      * @memberOf _
10321      * @category String
10322      * @param {string} [string=''] The string to escape.
10323      * @returns {string} Returns the escaped string.
10324      * @example
10325      *
10326      * _.escape('fred, barney, & pebbles');
10327      * // => 'fred, barney, &amp; pebbles'
10328      */
10329     function escape(string) {
10330       // Reset `lastIndex` because in IE < 9 `String#replace` does not.
10331       string = baseToString(string);
10332       return (string && reHasUnescapedHtml.test(string))
10333         ? string.replace(reUnescapedHtml, escapeHtmlChar)
10334         : string;
10335     }
10336
10337     /**
10338      * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
10339      * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
10340      *
10341      * @static
10342      * @memberOf _
10343      * @category String
10344      * @param {string} [string=''] The string to escape.
10345      * @returns {string} Returns the escaped string.
10346      * @example
10347      *
10348      * _.escapeRegExp('[lodash](https://lodash.com/)');
10349      * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
10350      */
10351     function escapeRegExp(string) {
10352       string = baseToString(string);
10353       return (string && reHasRegExpChars.test(string))
10354         ? string.replace(reRegExpChars, escapeRegExpChar)
10355         : (string || '(?:)');
10356     }
10357
10358     /**
10359      * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
10360      *
10361      * @static
10362      * @memberOf _
10363      * @category String
10364      * @param {string} [string=''] The string to convert.
10365      * @returns {string} Returns the kebab cased string.
10366      * @example
10367      *
10368      * _.kebabCase('Foo Bar');
10369      * // => 'foo-bar'
10370      *
10371      * _.kebabCase('fooBar');
10372      * // => 'foo-bar'
10373      *
10374      * _.kebabCase('__foo_bar__');
10375      * // => 'foo-bar'
10376      */
10377     var kebabCase = createCompounder(function(result, word, index) {
10378       return result + (index ? '-' : '') + word.toLowerCase();
10379     });
10380
10381     /**
10382      * Pads `string` on the left and right sides if it's shorter than `length`.
10383      * Padding characters are truncated if they can't be evenly divided by `length`.
10384      *
10385      * @static
10386      * @memberOf _
10387      * @category String
10388      * @param {string} [string=''] The string to pad.
10389      * @param {number} [length=0] The padding length.
10390      * @param {string} [chars=' '] The string used as padding.
10391      * @returns {string} Returns the padded string.
10392      * @example
10393      *
10394      * _.pad('abc', 8);
10395      * // => '  abc   '
10396      *
10397      * _.pad('abc', 8, '_-');
10398      * // => '_-abc_-_'
10399      *
10400      * _.pad('abc', 3);
10401      * // => 'abc'
10402      */
10403     function pad(string, length, chars) {
10404       string = baseToString(string);
10405       length = +length;
10406
10407       var strLength = string.length;
10408       if (strLength >= length || !nativeIsFinite(length)) {
10409         return string;
10410       }
10411       var mid = (length - strLength) / 2,
10412           leftLength = nativeFloor(mid),
10413           rightLength = nativeCeil(mid);
10414
10415       chars = createPadding('', rightLength, chars);
10416       return chars.slice(0, leftLength) + string + chars;
10417     }
10418
10419     /**
10420      * Pads `string` on the left side if it's shorter than `length`. Padding
10421      * characters are truncated if they exceed `length`.
10422      *
10423      * @static
10424      * @memberOf _
10425      * @category String
10426      * @param {string} [string=''] The string to pad.
10427      * @param {number} [length=0] The padding length.
10428      * @param {string} [chars=' '] The string used as padding.
10429      * @returns {string} Returns the padded string.
10430      * @example
10431      *
10432      * _.padLeft('abc', 6);
10433      * // => '   abc'
10434      *
10435      * _.padLeft('abc', 6, '_-');
10436      * // => '_-_abc'
10437      *
10438      * _.padLeft('abc', 3);
10439      * // => 'abc'
10440      */
10441     var padLeft = createPadDir();
10442
10443     /**
10444      * Pads `string` on the right side if it's shorter than `length`. Padding
10445      * characters are truncated if they exceed `length`.
10446      *
10447      * @static
10448      * @memberOf _
10449      * @category String
10450      * @param {string} [string=''] The string to pad.
10451      * @param {number} [length=0] The padding length.
10452      * @param {string} [chars=' '] The string used as padding.
10453      * @returns {string} Returns the padded string.
10454      * @example
10455      *
10456      * _.padRight('abc', 6);
10457      * // => 'abc   '
10458      *
10459      * _.padRight('abc', 6, '_-');
10460      * // => 'abc_-_'
10461      *
10462      * _.padRight('abc', 3);
10463      * // => 'abc'
10464      */
10465     var padRight = createPadDir(true);
10466
10467     /**
10468      * Converts `string` to an integer of the specified radix. If `radix` is
10469      * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
10470      * in which case a `radix` of `16` is used.
10471      *
10472      * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
10473      * of `parseInt`.
10474      *
10475      * @static
10476      * @memberOf _
10477      * @category String
10478      * @param {string} string The string to convert.
10479      * @param {number} [radix] The radix to interpret `value` by.
10480      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10481      * @returns {number} Returns the converted integer.
10482      * @example
10483      *
10484      * _.parseInt('08');
10485      * // => 8
10486      *
10487      * _.map(['6', '08', '10'], _.parseInt);
10488      * // => [6, 8, 10]
10489      */
10490     function parseInt(string, radix, guard) {
10491       // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
10492       // Chrome fails to trim leading <BOM> whitespace characters.
10493       // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
10494       if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
10495         radix = 0;
10496       } else if (radix) {
10497         radix = +radix;
10498       }
10499       string = trim(string);
10500       return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
10501     }
10502
10503     /**
10504      * Repeats the given string `n` times.
10505      *
10506      * @static
10507      * @memberOf _
10508      * @category String
10509      * @param {string} [string=''] The string to repeat.
10510      * @param {number} [n=0] The number of times to repeat the string.
10511      * @returns {string} Returns the repeated string.
10512      * @example
10513      *
10514      * _.repeat('*', 3);
10515      * // => '***'
10516      *
10517      * _.repeat('abc', 2);
10518      * // => 'abcabc'
10519      *
10520      * _.repeat('abc', 0);
10521      * // => ''
10522      */
10523     function repeat(string, n) {
10524       var result = '';
10525       string = baseToString(string);
10526       n = +n;
10527       if (n < 1 || !string || !nativeIsFinite(n)) {
10528         return result;
10529       }
10530       // Leverage the exponentiation by squaring algorithm for a faster repeat.
10531       // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
10532       do {
10533         if (n % 2) {
10534           result += string;
10535         }
10536         n = nativeFloor(n / 2);
10537         string += string;
10538       } while (n);
10539
10540       return result;
10541     }
10542
10543     /**
10544      * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
10545      *
10546      * @static
10547      * @memberOf _
10548      * @category String
10549      * @param {string} [string=''] The string to convert.
10550      * @returns {string} Returns the snake cased string.
10551      * @example
10552      *
10553      * _.snakeCase('Foo Bar');
10554      * // => 'foo_bar'
10555      *
10556      * _.snakeCase('fooBar');
10557      * // => 'foo_bar'
10558      *
10559      * _.snakeCase('--foo-bar');
10560      * // => 'foo_bar'
10561      */
10562     var snakeCase = createCompounder(function(result, word, index) {
10563       return result + (index ? '_' : '') + word.toLowerCase();
10564     });
10565
10566     /**
10567      * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
10568      *
10569      * @static
10570      * @memberOf _
10571      * @category String
10572      * @param {string} [string=''] The string to convert.
10573      * @returns {string} Returns the start cased string.
10574      * @example
10575      *
10576      * _.startCase('--foo-bar');
10577      * // => 'Foo Bar'
10578      *
10579      * _.startCase('fooBar');
10580      * // => 'Foo Bar'
10581      *
10582      * _.startCase('__foo_bar__');
10583      * // => 'Foo Bar'
10584      */
10585     var startCase = createCompounder(function(result, word, index) {
10586       return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
10587     });
10588
10589     /**
10590      * Checks if `string` starts with the given target string.
10591      *
10592      * @static
10593      * @memberOf _
10594      * @category String
10595      * @param {string} [string=''] The string to search.
10596      * @param {string} [target] The string to search for.
10597      * @param {number} [position=0] The position to search from.
10598      * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
10599      * @example
10600      *
10601      * _.startsWith('abc', 'a');
10602      * // => true
10603      *
10604      * _.startsWith('abc', 'b');
10605      * // => false
10606      *
10607      * _.startsWith('abc', 'b', 1);
10608      * // => true
10609      */
10610     function startsWith(string, target, position) {
10611       string = baseToString(string);
10612       position = position == null
10613         ? 0
10614         : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
10615
10616       return string.lastIndexOf(target, position) == position;
10617     }
10618
10619     /**
10620      * Creates a compiled template function that can interpolate data properties
10621      * in "interpolate" delimiters, HTML-escape interpolated data properties in
10622      * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
10623      * properties may be accessed as free variables in the template. If a setting
10624      * object is provided it takes precedence over `_.templateSettings` values.
10625      *
10626      * **Note:** In the development build `_.template` utilizes
10627      * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
10628      * for easier debugging.
10629      *
10630      * For more information on precompiling templates see
10631      * [lodash's custom builds documentation](https://lodash.com/custom-builds).
10632      *
10633      * For more information on Chrome extension sandboxes see
10634      * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
10635      *
10636      * @static
10637      * @memberOf _
10638      * @category String
10639      * @param {string} [string=''] The template string.
10640      * @param {Object} [options] The options object.
10641      * @param {RegExp} [options.escape] The HTML "escape" delimiter.
10642      * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
10643      * @param {Object} [options.imports] An object to import into the template as free variables.
10644      * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
10645      * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
10646      * @param {string} [options.variable] The data object variable name.
10647      * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
10648      * @returns {Function} Returns the compiled template function.
10649      * @example
10650      *
10651      * // using the "interpolate" delimiter to create a compiled template
10652      * var compiled = _.template('hello <%= user %>!');
10653      * compiled({ 'user': 'fred' });
10654      * // => 'hello fred!'
10655      *
10656      * // using the HTML "escape" delimiter to escape data property values
10657      * var compiled = _.template('<b><%- value %></b>');
10658      * compiled({ 'value': '<script>' });
10659      * // => '<b>&lt;script&gt;</b>'
10660      *
10661      * // using the "evaluate" delimiter to execute JavaScript and generate HTML
10662      * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
10663      * compiled({ 'users': ['fred', 'barney'] });
10664      * // => '<li>fred</li><li>barney</li>'
10665      *
10666      * // using the internal `print` function in "evaluate" delimiters
10667      * var compiled = _.template('<% print("hello " + user); %>!');
10668      * compiled({ 'user': 'barney' });
10669      * // => 'hello barney!'
10670      *
10671      * // using the ES delimiter as an alternative to the default "interpolate" delimiter
10672      * var compiled = _.template('hello ${ user }!');
10673      * compiled({ 'user': 'pebbles' });
10674      * // => 'hello pebbles!'
10675      *
10676      * // using custom template delimiters
10677      * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
10678      * var compiled = _.template('hello {{ user }}!');
10679      * compiled({ 'user': 'mustache' });
10680      * // => 'hello mustache!'
10681      *
10682      * // using backslashes to treat delimiters as plain text
10683      * var compiled = _.template('<%= "\\<%- value %\\>" %>');
10684      * compiled({ 'value': 'ignored' });
10685      * // => '<%- value %>'
10686      *
10687      * // using the `imports` option to import `jQuery` as `jq`
10688      * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
10689      * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
10690      * compiled({ 'users': ['fred', 'barney'] });
10691      * // => '<li>fred</li><li>barney</li>'
10692      *
10693      * // using the `sourceURL` option to specify a custom sourceURL for the template
10694      * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
10695      * compiled(data);
10696      * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
10697      *
10698      * // using the `variable` option to ensure a with-statement isn't used in the compiled template
10699      * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
10700      * compiled.source;
10701      * // => function(data) {
10702      * //   var __t, __p = '';
10703      * //   __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
10704      * //   return __p;
10705      * // }
10706      *
10707      * // using the `source` property to inline compiled templates for meaningful
10708      * // line numbers in error messages and a stack trace
10709      * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
10710      *   var JST = {\
10711      *     "main": ' + _.template(mainText).source + '\
10712      *   };\
10713      * ');
10714      */
10715     function template(string, options, otherOptions) {
10716       // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
10717       // and Laura Doktorova's doT.js (https://github.com/olado/doT).
10718       var settings = lodash.templateSettings;
10719
10720       if (otherOptions && isIterateeCall(string, options, otherOptions)) {
10721         options = otherOptions = undefined;
10722       }
10723       string = baseToString(string);
10724       options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
10725
10726       var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
10727           importsKeys = keys(imports),
10728           importsValues = baseValues(imports, importsKeys);
10729
10730       var isEscaping,
10731           isEvaluating,
10732           index = 0,
10733           interpolate = options.interpolate || reNoMatch,
10734           source = "__p += '";
10735
10736       // Compile the regexp to match each delimiter.
10737       var reDelimiters = RegExp(
10738         (options.escape || reNoMatch).source + '|' +
10739         interpolate.source + '|' +
10740         (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
10741         (options.evaluate || reNoMatch).source + '|$'
10742       , 'g');
10743
10744       // Use a sourceURL for easier debugging.
10745       var sourceURL = '//# sourceURL=' +
10746         ('sourceURL' in options
10747           ? options.sourceURL
10748           : ('lodash.templateSources[' + (++templateCounter) + ']')
10749         ) + '\n';
10750
10751       string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
10752         interpolateValue || (interpolateValue = esTemplateValue);
10753
10754         // Escape characters that can't be included in string literals.
10755         source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
10756
10757         // Replace delimiters with snippets.
10758         if (escapeValue) {
10759           isEscaping = true;
10760           source += "' +\n__e(" + escapeValue + ") +\n'";
10761         }
10762         if (evaluateValue) {
10763           isEvaluating = true;
10764           source += "';\n" + evaluateValue + ";\n__p += '";
10765         }
10766         if (interpolateValue) {
10767           source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
10768         }
10769         index = offset + match.length;
10770
10771         // The JS engine embedded in Adobe products requires returning the `match`
10772         // string in order to produce the correct `offset` value.
10773         return match;
10774       });
10775
10776       source += "';\n";
10777
10778       // If `variable` is not specified wrap a with-statement around the generated
10779       // code to add the data object to the top of the scope chain.
10780       var variable = options.variable;
10781       if (!variable) {
10782         source = 'with (obj) {\n' + source + '\n}\n';
10783       }
10784       // Cleanup code by stripping empty strings.
10785       source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
10786         .replace(reEmptyStringMiddle, '$1')
10787         .replace(reEmptyStringTrailing, '$1;');
10788
10789       // Frame code as the function body.
10790       source = 'function(' + (variable || 'obj') + ') {\n' +
10791         (variable
10792           ? ''
10793           : 'obj || (obj = {});\n'
10794         ) +
10795         "var __t, __p = ''" +
10796         (isEscaping
10797            ? ', __e = _.escape'
10798            : ''
10799         ) +
10800         (isEvaluating
10801           ? ', __j = Array.prototype.join;\n' +
10802             "function print() { __p += __j.call(arguments, '') }\n"
10803           : ';\n'
10804         ) +
10805         source +
10806         'return __p\n}';
10807
10808       var result = attempt(function() {
10809         return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
10810       });
10811
10812       // Provide the compiled function's source by its `toString` method or
10813       // the `source` property as a convenience for inlining compiled templates.
10814       result.source = source;
10815       if (isError(result)) {
10816         throw result;
10817       }
10818       return result;
10819     }
10820
10821     /**
10822      * Removes leading and trailing whitespace or specified characters from `string`.
10823      *
10824      * @static
10825      * @memberOf _
10826      * @category String
10827      * @param {string} [string=''] The string to trim.
10828      * @param {string} [chars=whitespace] The characters to trim.
10829      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10830      * @returns {string} Returns the trimmed string.
10831      * @example
10832      *
10833      * _.trim('  abc  ');
10834      * // => 'abc'
10835      *
10836      * _.trim('-_-abc-_-', '_-');
10837      * // => 'abc'
10838      *
10839      * _.map(['  foo  ', '  bar  '], _.trim);
10840      * // => ['foo', 'bar']
10841      */
10842     function trim(string, chars, guard) {
10843       var value = string;
10844       string = baseToString(string);
10845       if (!string) {
10846         return string;
10847       }
10848       if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10849         return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
10850       }
10851       chars = (chars + '');
10852       return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
10853     }
10854
10855     /**
10856      * Removes leading whitespace or specified characters from `string`.
10857      *
10858      * @static
10859      * @memberOf _
10860      * @category String
10861      * @param {string} [string=''] The string to trim.
10862      * @param {string} [chars=whitespace] The characters to trim.
10863      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10864      * @returns {string} Returns the trimmed string.
10865      * @example
10866      *
10867      * _.trimLeft('  abc  ');
10868      * // => 'abc  '
10869      *
10870      * _.trimLeft('-_-abc-_-', '_-');
10871      * // => 'abc-_-'
10872      */
10873     function trimLeft(string, chars, guard) {
10874       var value = string;
10875       string = baseToString(string);
10876       if (!string) {
10877         return string;
10878       }
10879       if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10880         return string.slice(trimmedLeftIndex(string));
10881       }
10882       return string.slice(charsLeftIndex(string, (chars + '')));
10883     }
10884
10885     /**
10886      * Removes trailing whitespace or specified characters from `string`.
10887      *
10888      * @static
10889      * @memberOf _
10890      * @category String
10891      * @param {string} [string=''] The string to trim.
10892      * @param {string} [chars=whitespace] The characters to trim.
10893      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10894      * @returns {string} Returns the trimmed string.
10895      * @example
10896      *
10897      * _.trimRight('  abc  ');
10898      * // => '  abc'
10899      *
10900      * _.trimRight('-_-abc-_-', '_-');
10901      * // => '-_-abc'
10902      */
10903     function trimRight(string, chars, guard) {
10904       var value = string;
10905       string = baseToString(string);
10906       if (!string) {
10907         return string;
10908       }
10909       if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10910         return string.slice(0, trimmedRightIndex(string) + 1);
10911       }
10912       return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
10913     }
10914
10915     /**
10916      * Truncates `string` if it's longer than the given maximum string length.
10917      * The last characters of the truncated string are replaced with the omission
10918      * string which defaults to "...".
10919      *
10920      * @static
10921      * @memberOf _
10922      * @category String
10923      * @param {string} [string=''] The string to truncate.
10924      * @param {Object|number} [options] The options object or maximum string length.
10925      * @param {number} [options.length=30] The maximum string length.
10926      * @param {string} [options.omission='...'] The string to indicate text is omitted.
10927      * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
10928      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10929      * @returns {string} Returns the truncated string.
10930      * @example
10931      *
10932      * _.trunc('hi-diddly-ho there, neighborino');
10933      * // => 'hi-diddly-ho there, neighbo...'
10934      *
10935      * _.trunc('hi-diddly-ho there, neighborino', 24);
10936      * // => 'hi-diddly-ho there, n...'
10937      *
10938      * _.trunc('hi-diddly-ho there, neighborino', {
10939      *   'length': 24,
10940      *   'separator': ' '
10941      * });
10942      * // => 'hi-diddly-ho there,...'
10943      *
10944      * _.trunc('hi-diddly-ho there, neighborino', {
10945      *   'length': 24,
10946      *   'separator': /,? +/
10947      * });
10948      * // => 'hi-diddly-ho there...'
10949      *
10950      * _.trunc('hi-diddly-ho there, neighborino', {
10951      *   'omission': ' [...]'
10952      * });
10953      * // => 'hi-diddly-ho there, neig [...]'
10954      */
10955     function trunc(string, options, guard) {
10956       if (guard && isIterateeCall(string, options, guard)) {
10957         options = undefined;
10958       }
10959       var length = DEFAULT_TRUNC_LENGTH,
10960           omission = DEFAULT_TRUNC_OMISSION;
10961
10962       if (options != null) {
10963         if (isObject(options)) {
10964           var separator = 'separator' in options ? options.separator : separator;
10965           length = 'length' in options ? (+options.length || 0) : length;
10966           omission = 'omission' in options ? baseToString(options.omission) : omission;
10967         } else {
10968           length = +options || 0;
10969         }
10970       }
10971       string = baseToString(string);
10972       if (length >= string.length) {
10973         return string;
10974       }
10975       var end = length - omission.length;
10976       if (end < 1) {
10977         return omission;
10978       }
10979       var result = string.slice(0, end);
10980       if (separator == null) {
10981         return result + omission;
10982       }
10983       if (isRegExp(separator)) {
10984         if (string.slice(end).search(separator)) {
10985           var match,
10986               newEnd,
10987               substring = string.slice(0, end);
10988
10989           if (!separator.global) {
10990             separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
10991           }
10992           separator.lastIndex = 0;
10993           while ((match = separator.exec(substring))) {
10994             newEnd = match.index;
10995           }
10996           result = result.slice(0, newEnd == null ? end : newEnd);
10997         }
10998       } else if (string.indexOf(separator, end) != end) {
10999         var index = result.lastIndexOf(separator);
11000         if (index > -1) {
11001           result = result.slice(0, index);
11002         }
11003       }
11004       return result + omission;
11005     }
11006
11007     /**
11008      * The inverse of `_.escape`; this method converts the HTML entities
11009      * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
11010      * corresponding characters.
11011      *
11012      * **Note:** No other HTML entities are unescaped. To unescape additional HTML
11013      * entities use a third-party library like [_he_](https://mths.be/he).
11014      *
11015      * @static
11016      * @memberOf _
11017      * @category String
11018      * @param {string} [string=''] The string to unescape.
11019      * @returns {string} Returns the unescaped string.
11020      * @example
11021      *
11022      * _.unescape('fred, barney, &amp; pebbles');
11023      * // => 'fred, barney, & pebbles'
11024      */
11025     function unescape(string) {
11026       string = baseToString(string);
11027       return (string && reHasEscapedHtml.test(string))
11028         ? string.replace(reEscapedHtml, unescapeHtmlChar)
11029         : string;
11030     }
11031
11032     /**
11033      * Splits `string` into an array of its words.
11034      *
11035      * @static
11036      * @memberOf _
11037      * @category String
11038      * @param {string} [string=''] The string to inspect.
11039      * @param {RegExp|string} [pattern] The pattern to match words.
11040      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11041      * @returns {Array} Returns the words of `string`.
11042      * @example
11043      *
11044      * _.words('fred, barney, & pebbles');
11045      * // => ['fred', 'barney', 'pebbles']
11046      *
11047      * _.words('fred, barney, & pebbles', /[^, ]+/g);
11048      * // => ['fred', 'barney', '&', 'pebbles']
11049      */
11050     function words(string, pattern, guard) {
11051       if (guard && isIterateeCall(string, pattern, guard)) {
11052         pattern = undefined;
11053       }
11054       string = baseToString(string);
11055       return string.match(pattern || reWords) || [];
11056     }
11057
11058     /*------------------------------------------------------------------------*/
11059
11060     /**
11061      * Attempts to invoke `func`, returning either the result or the caught error
11062      * object. Any additional arguments are provided to `func` when it is invoked.
11063      *
11064      * @static
11065      * @memberOf _
11066      * @category Utility
11067      * @param {Function} func The function to attempt.
11068      * @returns {*} Returns the `func` result or error object.
11069      * @example
11070      *
11071      * // avoid throwing errors for invalid selectors
11072      * var elements = _.attempt(function(selector) {
11073      *   return document.querySelectorAll(selector);
11074      * }, '>_>');
11075      *
11076      * if (_.isError(elements)) {
11077      *   elements = [];
11078      * }
11079      */
11080     var attempt = restParam(function(func, args) {
11081       try {
11082         return func.apply(undefined, args);
11083       } catch(e) {
11084         return isError(e) ? e : new Error(e);
11085       }
11086     });
11087
11088     /**
11089      * Creates a function that invokes `func` with the `this` binding of `thisArg`
11090      * and arguments of the created function. If `func` is a property name the
11091      * created callback returns the property value for a given element. If `func`
11092      * is an object the created callback returns `true` for elements that contain
11093      * the equivalent object properties, otherwise it returns `false`.
11094      *
11095      * @static
11096      * @memberOf _
11097      * @alias iteratee
11098      * @category Utility
11099      * @param {*} [func=_.identity] The value to convert to a callback.
11100      * @param {*} [thisArg] The `this` binding of `func`.
11101      * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11102      * @returns {Function} Returns the callback.
11103      * @example
11104      *
11105      * var users = [
11106      *   { 'user': 'barney', 'age': 36 },
11107      *   { 'user': 'fred',   'age': 40 }
11108      * ];
11109      *
11110      * // wrap to create custom callback shorthands
11111      * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
11112      *   var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
11113      *   if (!match) {
11114      *     return callback(func, thisArg);
11115      *   }
11116      *   return function(object) {
11117      *     return match[2] == 'gt'
11118      *       ? object[match[1]] > match[3]
11119      *       : object[match[1]] < match[3];
11120      *   };
11121      * });
11122      *
11123      * _.filter(users, 'age__gt36');
11124      * // => [{ 'user': 'fred', 'age': 40 }]
11125      */
11126     function callback(func, thisArg, guard) {
11127       if (guard && isIterateeCall(func, thisArg, guard)) {
11128         thisArg = undefined;
11129       }
11130       return isObjectLike(func)
11131         ? matches(func)
11132         : baseCallback(func, thisArg);
11133     }
11134
11135     /**
11136      * Creates a function that returns `value`.
11137      *
11138      * @static
11139      * @memberOf _
11140      * @category Utility
11141      * @param {*} value The value to return from the new function.
11142      * @returns {Function} Returns the new function.
11143      * @example
11144      *
11145      * var object = { 'user': 'fred' };
11146      * var getter = _.constant(object);
11147      *
11148      * getter() === object;
11149      * // => true
11150      */
11151     function constant(value) {
11152       return function() {
11153         return value;
11154       };
11155     }
11156
11157     /**
11158      * This method returns the first argument provided to it.
11159      *
11160      * @static
11161      * @memberOf _
11162      * @category Utility
11163      * @param {*} value Any value.
11164      * @returns {*} Returns `value`.
11165      * @example
11166      *
11167      * var object = { 'user': 'fred' };
11168      *
11169      * _.identity(object) === object;
11170      * // => true
11171      */
11172     function identity(value) {
11173       return value;
11174     }
11175
11176     /**
11177      * Creates a function that performs a deep comparison between a given object
11178      * and `source`, returning `true` if the given object has equivalent property
11179      * values, else `false`.
11180      *
11181      * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11182      * numbers, `Object` objects, regexes, and strings. Objects are compared by
11183      * their own, not inherited, enumerable properties. For comparing a single
11184      * own or inherited property value see `_.matchesProperty`.
11185      *
11186      * @static
11187      * @memberOf _
11188      * @category Utility
11189      * @param {Object} source The object of property values to match.
11190      * @returns {Function} Returns the new function.
11191      * @example
11192      *
11193      * var users = [
11194      *   { 'user': 'barney', 'age': 36, 'active': true },
11195      *   { 'user': 'fred',   'age': 40, 'active': false }
11196      * ];
11197      *
11198      * _.filter(users, _.matches({ 'age': 40, 'active': false }));
11199      * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
11200      */
11201     function matches(source) {
11202       return baseMatches(baseClone(source, true));
11203     }
11204
11205     /**
11206      * Creates a function that compares the property value of `path` on a given
11207      * object to `value`.
11208      *
11209      * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11210      * numbers, `Object` objects, regexes, and strings. Objects are compared by
11211      * their own, not inherited, enumerable properties.
11212      *
11213      * @static
11214      * @memberOf _
11215      * @category Utility
11216      * @param {Array|string} path The path of the property to get.
11217      * @param {*} srcValue The value to match.
11218      * @returns {Function} Returns the new function.
11219      * @example
11220      *
11221      * var users = [
11222      *   { 'user': 'barney' },
11223      *   { 'user': 'fred' }
11224      * ];
11225      *
11226      * _.find(users, _.matchesProperty('user', 'fred'));
11227      * // => { 'user': 'fred' }
11228      */
11229     function matchesProperty(path, srcValue) {
11230       return baseMatchesProperty(path, baseClone(srcValue, true));
11231     }
11232
11233     /**
11234      * Creates a function that invokes the method at `path` on a given object.
11235      * Any additional arguments are provided to the invoked method.
11236      *
11237      * @static
11238      * @memberOf _
11239      * @category Utility
11240      * @param {Array|string} path The path of the method to invoke.
11241      * @param {...*} [args] The arguments to invoke the method with.
11242      * @returns {Function} Returns the new function.
11243      * @example
11244      *
11245      * var objects = [
11246      *   { 'a': { 'b': { 'c': _.constant(2) } } },
11247      *   { 'a': { 'b': { 'c': _.constant(1) } } }
11248      * ];
11249      *
11250      * _.map(objects, _.method('a.b.c'));
11251      * // => [2, 1]
11252      *
11253      * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
11254      * // => [1, 2]
11255      */
11256     var method = restParam(function(path, args) {
11257       return function(object) {
11258         return invokePath(object, path, args);
11259       };
11260     });
11261
11262     /**
11263      * The opposite of `_.method`; this method creates a function that invokes
11264      * the method at a given path on `object`. Any additional arguments are
11265      * provided to the invoked method.
11266      *
11267      * @static
11268      * @memberOf _
11269      * @category Utility
11270      * @param {Object} object The object to query.
11271      * @param {...*} [args] The arguments to invoke the method with.
11272      * @returns {Function} Returns the new function.
11273      * @example
11274      *
11275      * var array = _.times(3, _.constant),
11276      *     object = { 'a': array, 'b': array, 'c': array };
11277      *
11278      * _.map(['a[2]', 'c[0]'], _.methodOf(object));
11279      * // => [2, 0]
11280      *
11281      * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
11282      * // => [2, 0]
11283      */
11284     var methodOf = restParam(function(object, args) {
11285       return function(path) {
11286         return invokePath(object, path, args);
11287       };
11288     });
11289
11290     /**
11291      * Adds all own enumerable function properties of a source object to the
11292      * destination object. If `object` is a function then methods are added to
11293      * its prototype as well.
11294      *
11295      * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
11296      * avoid conflicts caused by modifying the original.
11297      *
11298      * @static
11299      * @memberOf _
11300      * @category Utility
11301      * @param {Function|Object} [object=lodash] The destination object.
11302      * @param {Object} source The object of functions to add.
11303      * @param {Object} [options] The options object.
11304      * @param {boolean} [options.chain=true] Specify whether the functions added
11305      *  are chainable.
11306      * @returns {Function|Object} Returns `object`.
11307      * @example
11308      *
11309      * function vowels(string) {
11310      *   return _.filter(string, function(v) {
11311      *     return /[aeiou]/i.test(v);
11312      *   });
11313      * }
11314      *
11315      * _.mixin({ 'vowels': vowels });
11316      * _.vowels('fred');
11317      * // => ['e']
11318      *
11319      * _('fred').vowels().value();
11320      * // => ['e']
11321      *
11322      * _.mixin({ 'vowels': vowels }, { 'chain': false });
11323      * _('fred').vowels();
11324      * // => ['e']
11325      */
11326     function mixin(object, source, options) {
11327       if (options == null) {
11328         var isObj = isObject(source),
11329             props = isObj ? keys(source) : undefined,
11330             methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
11331
11332         if (!(methodNames ? methodNames.length : isObj)) {
11333           methodNames = false;
11334           options = source;
11335           source = object;
11336           object = this;
11337         }
11338       }
11339       if (!methodNames) {
11340         methodNames = baseFunctions(source, keys(source));
11341       }
11342       var chain = true,
11343           index = -1,
11344           isFunc = isFunction(object),
11345           length = methodNames.length;
11346
11347       if (options === false) {
11348         chain = false;
11349       } else if (isObject(options) && 'chain' in options) {
11350         chain = options.chain;
11351       }
11352       while (++index < length) {
11353         var methodName = methodNames[index],
11354             func = source[methodName];
11355
11356         object[methodName] = func;
11357         if (isFunc) {
11358           object.prototype[methodName] = (function(func) {
11359             return function() {
11360               var chainAll = this.__chain__;
11361               if (chain || chainAll) {
11362                 var result = object(this.__wrapped__),
11363                     actions = result.__actions__ = arrayCopy(this.__actions__);
11364
11365                 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
11366                 result.__chain__ = chainAll;
11367                 return result;
11368               }
11369               return func.apply(object, arrayPush([this.value()], arguments));
11370             };
11371           }(func));
11372         }
11373       }
11374       return object;
11375     }
11376
11377     /**
11378      * Reverts the `_` variable to its previous value and returns a reference to
11379      * the `lodash` function.
11380      *
11381      * @static
11382      * @memberOf _
11383      * @category Utility
11384      * @returns {Function} Returns the `lodash` function.
11385      * @example
11386      *
11387      * var lodash = _.noConflict();
11388      */
11389     function noConflict() {
11390       root._ = oldDash;
11391       return this;
11392     }
11393
11394     /**
11395      * A no-operation function that returns `undefined` regardless of the
11396      * arguments it receives.
11397      *
11398      * @static
11399      * @memberOf _
11400      * @category Utility
11401      * @example
11402      *
11403      * var object = { 'user': 'fred' };
11404      *
11405      * _.noop(object) === undefined;
11406      * // => true
11407      */
11408     function noop() {
11409       // No operation performed.
11410     }
11411
11412     /**
11413      * Creates a function that returns the property value at `path` on a
11414      * given object.
11415      *
11416      * @static
11417      * @memberOf _
11418      * @category Utility
11419      * @param {Array|string} path The path of the property to get.
11420      * @returns {Function} Returns the new function.
11421      * @example
11422      *
11423      * var objects = [
11424      *   { 'a': { 'b': { 'c': 2 } } },
11425      *   { 'a': { 'b': { 'c': 1 } } }
11426      * ];
11427      *
11428      * _.map(objects, _.property('a.b.c'));
11429      * // => [2, 1]
11430      *
11431      * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
11432      * // => [1, 2]
11433      */
11434     function property(path) {
11435       return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
11436     }
11437
11438     /**
11439      * The opposite of `_.property`; this method creates a function that returns
11440      * the property value at a given path on `object`.
11441      *
11442      * @static
11443      * @memberOf _
11444      * @category Utility
11445      * @param {Object} object The object to query.
11446      * @returns {Function} Returns the new function.
11447      * @example
11448      *
11449      * var array = [0, 1, 2],
11450      *     object = { 'a': array, 'b': array, 'c': array };
11451      *
11452      * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
11453      * // => [2, 0]
11454      *
11455      * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
11456      * // => [2, 0]
11457      */
11458     function propertyOf(object) {
11459       return function(path) {
11460         return baseGet(object, toPath(path), path + '');
11461       };
11462     }
11463
11464     /**
11465      * Creates an array of numbers (positive and/or negative) progressing from
11466      * `start` up to, but not including, `end`. If `end` is not specified it is
11467      * set to `start` with `start` then set to `0`. If `end` is less than `start`
11468      * a zero-length range is created unless a negative `step` is specified.
11469      *
11470      * @static
11471      * @memberOf _
11472      * @category Utility
11473      * @param {number} [start=0] The start of the range.
11474      * @param {number} end The end of the range.
11475      * @param {number} [step=1] The value to increment or decrement by.
11476      * @returns {Array} Returns the new array of numbers.
11477      * @example
11478      *
11479      * _.range(4);
11480      * // => [0, 1, 2, 3]
11481      *
11482      * _.range(1, 5);
11483      * // => [1, 2, 3, 4]
11484      *
11485      * _.range(0, 20, 5);
11486      * // => [0, 5, 10, 15]
11487      *
11488      * _.range(0, -4, -1);
11489      * // => [0, -1, -2, -3]
11490      *
11491      * _.range(1, 4, 0);
11492      * // => [1, 1, 1]
11493      *
11494      * _.range(0);
11495      * // => []
11496      */
11497     function range(start, end, step) {
11498       if (step && isIterateeCall(start, end, step)) {
11499         end = step = undefined;
11500       }
11501       start = +start || 0;
11502       step = step == null ? 1 : (+step || 0);
11503
11504       if (end == null) {
11505         end = start;
11506         start = 0;
11507       } else {
11508         end = +end || 0;
11509       }
11510       // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
11511       // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
11512       var index = -1,
11513           length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
11514           result = Array(length);
11515
11516       while (++index < length) {
11517         result[index] = start;
11518         start += step;
11519       }
11520       return result;
11521     }
11522
11523     /**
11524      * Invokes the iteratee function `n` times, returning an array of the results
11525      * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
11526      * one argument; (index).
11527      *
11528      * @static
11529      * @memberOf _
11530      * @category Utility
11531      * @param {number} n The number of times to invoke `iteratee`.
11532      * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11533      * @param {*} [thisArg] The `this` binding of `iteratee`.
11534      * @returns {Array} Returns the array of results.
11535      * @example
11536      *
11537      * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
11538      * // => [3, 6, 4]
11539      *
11540      * _.times(3, function(n) {
11541      *   mage.castSpell(n);
11542      * });
11543      * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
11544      *
11545      * _.times(3, function(n) {
11546      *   this.cast(n);
11547      * }, mage);
11548      * // => also invokes `mage.castSpell(n)` three times
11549      */
11550     function times(n, iteratee, thisArg) {
11551       n = nativeFloor(n);
11552
11553       // Exit early to avoid a JSC JIT bug in Safari 8
11554       // where `Array(0)` is treated as `Array(1)`.
11555       if (n < 1 || !nativeIsFinite(n)) {
11556         return [];
11557       }
11558       var index = -1,
11559           result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
11560
11561       iteratee = bindCallback(iteratee, thisArg, 1);
11562       while (++index < n) {
11563         if (index < MAX_ARRAY_LENGTH) {
11564           result[index] = iteratee(index);
11565         } else {
11566           iteratee(index);
11567         }
11568       }
11569       return result;
11570     }
11571
11572     /**
11573      * Generates a unique ID. If `prefix` is provided the ID is appended to it.
11574      *
11575      * @static
11576      * @memberOf _
11577      * @category Utility
11578      * @param {string} [prefix] The value to prefix the ID with.
11579      * @returns {string} Returns the unique ID.
11580      * @example
11581      *
11582      * _.uniqueId('contact_');
11583      * // => 'contact_104'
11584      *
11585      * _.uniqueId();
11586      * // => '105'
11587      */
11588     function uniqueId(prefix) {
11589       var id = ++idCounter;
11590       return baseToString(prefix) + id;
11591     }
11592
11593     /*------------------------------------------------------------------------*/
11594
11595     /**
11596      * Adds two numbers.
11597      *
11598      * @static
11599      * @memberOf _
11600      * @category Math
11601      * @param {number} augend The first number to add.
11602      * @param {number} addend The second number to add.
11603      * @returns {number} Returns the sum.
11604      * @example
11605      *
11606      * _.add(6, 4);
11607      * // => 10
11608      */
11609     function add(augend, addend) {
11610       return (+augend || 0) + (+addend || 0);
11611     }
11612
11613     /**
11614      * Calculates `n` rounded up to `precision`.
11615      *
11616      * @static
11617      * @memberOf _
11618      * @category Math
11619      * @param {number} n The number to round up.
11620      * @param {number} [precision=0] The precision to round up to.
11621      * @returns {number} Returns the rounded up number.
11622      * @example
11623      *
11624      * _.ceil(4.006);
11625      * // => 5
11626      *
11627      * _.ceil(6.004, 2);
11628      * // => 6.01
11629      *
11630      * _.ceil(6040, -2);
11631      * // => 6100
11632      */
11633     var ceil = createRound('ceil');
11634
11635     /**
11636      * Calculates `n` rounded down to `precision`.
11637      *
11638      * @static
11639      * @memberOf _
11640      * @category Math
11641      * @param {number} n The number to round down.
11642      * @param {number} [precision=0] The precision to round down to.
11643      * @returns {number} Returns the rounded down number.
11644      * @example
11645      *
11646      * _.floor(4.006);
11647      * // => 4
11648      *
11649      * _.floor(0.046, 2);
11650      * // => 0.04
11651      *
11652      * _.floor(4060, -2);
11653      * // => 4000
11654      */
11655     var floor = createRound('floor');
11656
11657     /**
11658      * Gets the maximum value of `collection`. If `collection` is empty or falsey
11659      * `-Infinity` is returned. If an iteratee function is provided it is invoked
11660      * for each value in `collection` to generate the criterion by which the value
11661      * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11662      * arguments: (value, index, collection).
11663      *
11664      * If a property name is provided for `iteratee` the created `_.property`
11665      * style callback returns the property value of the given element.
11666      *
11667      * If a value is also provided for `thisArg` the created `_.matchesProperty`
11668      * style callback returns `true` for elements that have a matching property
11669      * value, else `false`.
11670      *
11671      * If an object is provided for `iteratee` the created `_.matches` style
11672      * callback returns `true` for elements that have the properties of the given
11673      * object, else `false`.
11674      *
11675      * @static
11676      * @memberOf _
11677      * @category Math
11678      * @param {Array|Object|string} collection The collection to iterate over.
11679      * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11680      * @param {*} [thisArg] The `this` binding of `iteratee`.
11681      * @returns {*} Returns the maximum value.
11682      * @example
11683      *
11684      * _.max([4, 2, 8, 6]);
11685      * // => 8
11686      *
11687      * _.max([]);
11688      * // => -Infinity
11689      *
11690      * var users = [
11691      *   { 'user': 'barney', 'age': 36 },
11692      *   { 'user': 'fred',   'age': 40 }
11693      * ];
11694      *
11695      * _.max(users, function(chr) {
11696      *   return chr.age;
11697      * });
11698      * // => { 'user': 'fred', 'age': 40 }
11699      *
11700      * // using the `_.property` callback shorthand
11701      * _.max(users, 'age');
11702      * // => { 'user': 'fred', 'age': 40 }
11703      */
11704     var max = createExtremum(gt, NEGATIVE_INFINITY);
11705
11706     /**
11707      * Gets the minimum value of `collection`. If `collection` is empty or falsey
11708      * `Infinity` is returned. If an iteratee function is provided it is invoked
11709      * for each value in `collection` to generate the criterion by which the value
11710      * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11711      * arguments: (value, index, collection).
11712      *
11713      * If a property name is provided for `iteratee` the created `_.property`
11714      * style callback returns the property value of the given element.
11715      *
11716      * If a value is also provided for `thisArg` the created `_.matchesProperty`
11717      * style callback returns `true` for elements that have a matching property
11718      * value, else `false`.
11719      *
11720      * If an object is provided for `iteratee` the created `_.matches` style
11721      * callback returns `true` for elements that have the properties of the given
11722      * object, else `false`.
11723      *
11724      * @static
11725      * @memberOf _
11726      * @category Math
11727      * @param {Array|Object|string} collection The collection to iterate over.
11728      * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11729      * @param {*} [thisArg] The `this` binding of `iteratee`.
11730      * @returns {*} Returns the minimum value.
11731      * @example
11732      *
11733      * _.min([4, 2, 8, 6]);
11734      * // => 2
11735      *
11736      * _.min([]);
11737      * // => Infinity
11738      *
11739      * var users = [
11740      *   { 'user': 'barney', 'age': 36 },
11741      *   { 'user': 'fred',   'age': 40 }
11742      * ];
11743      *
11744      * _.min(users, function(chr) {
11745      *   return chr.age;
11746      * });
11747      * // => { 'user': 'barney', 'age': 36 }
11748      *
11749      * // using the `_.property` callback shorthand
11750      * _.min(users, 'age');
11751      * // => { 'user': 'barney', 'age': 36 }
11752      */
11753     var min = createExtremum(lt, POSITIVE_INFINITY);
11754
11755     /**
11756      * Calculates `n` rounded to `precision`.
11757      *
11758      * @static
11759      * @memberOf _
11760      * @category Math
11761      * @param {number} n The number to round.
11762      * @param {number} [precision=0] The precision to round to.
11763      * @returns {number} Returns the rounded number.
11764      * @example
11765      *
11766      * _.round(4.006);
11767      * // => 4
11768      *
11769      * _.round(4.006, 2);
11770      * // => 4.01
11771      *
11772      * _.round(4060, -2);
11773      * // => 4100
11774      */
11775     var round = createRound('round');
11776
11777     /**
11778      * Gets the sum of the values in `collection`.
11779      *
11780      * @static
11781      * @memberOf _
11782      * @category Math
11783      * @param {Array|Object|string} collection The collection to iterate over.
11784      * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11785      * @param {*} [thisArg] The `this` binding of `iteratee`.
11786      * @returns {number} Returns the sum.
11787      * @example
11788      *
11789      * _.sum([4, 6]);
11790      * // => 10
11791      *
11792      * _.sum({ 'a': 4, 'b': 6 });
11793      * // => 10
11794      *
11795      * var objects = [
11796      *   { 'n': 4 },
11797      *   { 'n': 6 }
11798      * ];
11799      *
11800      * _.sum(objects, function(object) {
11801      *   return object.n;
11802      * });
11803      * // => 10
11804      *
11805      * // using the `_.property` callback shorthand
11806      * _.sum(objects, 'n');
11807      * // => 10
11808      */
11809     function sum(collection, iteratee, thisArg) {
11810       if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
11811         iteratee = undefined;
11812       }
11813       iteratee = getCallback(iteratee, thisArg, 3);
11814       return iteratee.length == 1
11815         ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
11816         : baseSum(collection, iteratee);
11817     }
11818
11819     /*------------------------------------------------------------------------*/
11820
11821     // Ensure wrappers are instances of `baseLodash`.
11822     lodash.prototype = baseLodash.prototype;
11823
11824     LodashWrapper.prototype = baseCreate(baseLodash.prototype);
11825     LodashWrapper.prototype.constructor = LodashWrapper;
11826
11827     LazyWrapper.prototype = baseCreate(baseLodash.prototype);
11828     LazyWrapper.prototype.constructor = LazyWrapper;
11829
11830     // Add functions to the `Map` cache.
11831     MapCache.prototype['delete'] = mapDelete;
11832     MapCache.prototype.get = mapGet;
11833     MapCache.prototype.has = mapHas;
11834     MapCache.prototype.set = mapSet;
11835
11836     // Add functions to the `Set` cache.
11837     SetCache.prototype.push = cachePush;
11838
11839     // Assign cache to `_.memoize`.
11840     memoize.Cache = MapCache;
11841
11842     // Add functions that return wrapped values when chaining.
11843     lodash.after = after;
11844     lodash.ary = ary;
11845     lodash.assign = assign;
11846     lodash.at = at;
11847     lodash.before = before;
11848     lodash.bind = bind;
11849     lodash.bindAll = bindAll;
11850     lodash.bindKey = bindKey;
11851     lodash.callback = callback;
11852     lodash.chain = chain;
11853     lodash.chunk = chunk;
11854     lodash.compact = compact;
11855     lodash.constant = constant;
11856     lodash.countBy = countBy;
11857     lodash.create = create;
11858     lodash.curry = curry;
11859     lodash.curryRight = curryRight;
11860     lodash.debounce = debounce;
11861     lodash.defaults = defaults;
11862     lodash.defaultsDeep = defaultsDeep;
11863     lodash.defer = defer;
11864     lodash.delay = delay;
11865     lodash.difference = difference;
11866     lodash.drop = drop;
11867     lodash.dropRight = dropRight;
11868     lodash.dropRightWhile = dropRightWhile;
11869     lodash.dropWhile = dropWhile;
11870     lodash.fill = fill;
11871     lodash.filter = filter;
11872     lodash.flatten = flatten;
11873     lodash.flattenDeep = flattenDeep;
11874     lodash.flow = flow;
11875     lodash.flowRight = flowRight;
11876     lodash.forEach = forEach;
11877     lodash.forEachRight = forEachRight;
11878     lodash.forIn = forIn;
11879     lodash.forInRight = forInRight;
11880     lodash.forOwn = forOwn;
11881     lodash.forOwnRight = forOwnRight;
11882     lodash.functions = functions;
11883     lodash.groupBy = groupBy;
11884     lodash.indexBy = indexBy;
11885     lodash.initial = initial;
11886     lodash.intersection = intersection;
11887     lodash.invert = invert;
11888     lodash.invoke = invoke;
11889     lodash.keys = keys;
11890     lodash.keysIn = keysIn;
11891     lodash.map = map;
11892     lodash.mapKeys = mapKeys;
11893     lodash.mapValues = mapValues;
11894     lodash.matches = matches;
11895     lodash.matchesProperty = matchesProperty;
11896     lodash.memoize = memoize;
11897     lodash.merge = merge;
11898     lodash.method = method;
11899     lodash.methodOf = methodOf;
11900     lodash.mixin = mixin;
11901     lodash.modArgs = modArgs;
11902     lodash.negate = negate;
11903     lodash.omit = omit;
11904     lodash.once = once;
11905     lodash.pairs = pairs;
11906     lodash.partial = partial;
11907     lodash.partialRight = partialRight;
11908     lodash.partition = partition;
11909     lodash.pick = pick;
11910     lodash.pluck = pluck;
11911     lodash.property = property;
11912     lodash.propertyOf = propertyOf;
11913     lodash.pull = pull;
11914     lodash.pullAt = pullAt;
11915     lodash.range = range;
11916     lodash.rearg = rearg;
11917     lodash.reject = reject;
11918     lodash.remove = remove;
11919     lodash.rest = rest;
11920     lodash.restParam = restParam;
11921     lodash.set = set;
11922     lodash.shuffle = shuffle;
11923     lodash.slice = slice;
11924     lodash.sortBy = sortBy;
11925     lodash.sortByAll = sortByAll;
11926     lodash.sortByOrder = sortByOrder;
11927     lodash.spread = spread;
11928     lodash.take = take;
11929     lodash.takeRight = takeRight;
11930     lodash.takeRightWhile = takeRightWhile;
11931     lodash.takeWhile = takeWhile;
11932     lodash.tap = tap;
11933     lodash.throttle = throttle;
11934     lodash.thru = thru;
11935     lodash.times = times;
11936     lodash.toArray = toArray;
11937     lodash.toPlainObject = toPlainObject;
11938     lodash.transform = transform;
11939     lodash.union = union;
11940     lodash.uniq = uniq;
11941     lodash.unzip = unzip;
11942     lodash.unzipWith = unzipWith;
11943     lodash.values = values;
11944     lodash.valuesIn = valuesIn;
11945     lodash.where = where;
11946     lodash.without = without;
11947     lodash.wrap = wrap;
11948     lodash.xor = xor;
11949     lodash.zip = zip;
11950     lodash.zipObject = zipObject;
11951     lodash.zipWith = zipWith;
11952
11953     // Add aliases.
11954     lodash.backflow = flowRight;
11955     lodash.collect = map;
11956     lodash.compose = flowRight;
11957     lodash.each = forEach;
11958     lodash.eachRight = forEachRight;
11959     lodash.extend = assign;
11960     lodash.iteratee = callback;
11961     lodash.methods = functions;
11962     lodash.object = zipObject;
11963     lodash.select = filter;
11964     lodash.tail = rest;
11965     lodash.unique = uniq;
11966
11967     // Add functions to `lodash.prototype`.
11968     mixin(lodash, lodash);
11969
11970     /*------------------------------------------------------------------------*/
11971
11972     // Add functions that return unwrapped values when chaining.
11973     lodash.add = add;
11974     lodash.attempt = attempt;
11975     lodash.camelCase = camelCase;
11976     lodash.capitalize = capitalize;
11977     lodash.ceil = ceil;
11978     lodash.clone = clone;
11979     lodash.cloneDeep = cloneDeep;
11980     lodash.deburr = deburr;
11981     lodash.endsWith = endsWith;
11982     lodash.escape = escape;
11983     lodash.escapeRegExp = escapeRegExp;
11984     lodash.every = every;
11985     lodash.find = find;
11986     lodash.findIndex = findIndex;
11987     lodash.findKey = findKey;
11988     lodash.findLast = findLast;
11989     lodash.findLastIndex = findLastIndex;
11990     lodash.findLastKey = findLastKey;
11991     lodash.findWhere = findWhere;
11992     lodash.first = first;
11993     lodash.floor = floor;
11994     lodash.get = get;
11995     lodash.gt = gt;
11996     lodash.gte = gte;
11997     lodash.has = has;
11998     lodash.identity = identity;
11999     lodash.includes = includes;
12000     lodash.indexOf = indexOf;
12001     lodash.inRange = inRange;
12002     lodash.isArguments = isArguments;
12003     lodash.isArray = isArray;
12004     lodash.isBoolean = isBoolean;
12005     lodash.isDate = isDate;
12006     lodash.isElement = isElement;
12007     lodash.isEmpty = isEmpty;
12008     lodash.isEqual = isEqual;
12009     lodash.isError = isError;
12010     lodash.isFinite = isFinite;
12011     lodash.isFunction = isFunction;
12012     lodash.isMatch = isMatch;
12013     lodash.isNaN = isNaN;
12014     lodash.isNative = isNative;
12015     lodash.isNull = isNull;
12016     lodash.isNumber = isNumber;
12017     lodash.isObject = isObject;
12018     lodash.isPlainObject = isPlainObject;
12019     lodash.isRegExp = isRegExp;
12020     lodash.isString = isString;
12021     lodash.isTypedArray = isTypedArray;
12022     lodash.isUndefined = isUndefined;
12023     lodash.kebabCase = kebabCase;
12024     lodash.last = last;
12025     lodash.lastIndexOf = lastIndexOf;
12026     lodash.lt = lt;
12027     lodash.lte = lte;
12028     lodash.max = max;
12029     lodash.min = min;
12030     lodash.noConflict = noConflict;
12031     lodash.noop = noop;
12032     lodash.now = now;
12033     lodash.pad = pad;
12034     lodash.padLeft = padLeft;
12035     lodash.padRight = padRight;
12036     lodash.parseInt = parseInt;
12037     lodash.random = random;
12038     lodash.reduce = reduce;
12039     lodash.reduceRight = reduceRight;
12040     lodash.repeat = repeat;
12041     lodash.result = result;
12042     lodash.round = round;
12043     lodash.runInContext = runInContext;
12044     lodash.size = size;
12045     lodash.snakeCase = snakeCase;
12046     lodash.some = some;
12047     lodash.sortedIndex = sortedIndex;
12048     lodash.sortedLastIndex = sortedLastIndex;
12049     lodash.startCase = startCase;
12050     lodash.startsWith = startsWith;
12051     lodash.sum = sum;
12052     lodash.template = template;
12053     lodash.trim = trim;
12054     lodash.trimLeft = trimLeft;
12055     lodash.trimRight = trimRight;
12056     lodash.trunc = trunc;
12057     lodash.unescape = unescape;
12058     lodash.uniqueId = uniqueId;
12059     lodash.words = words;
12060
12061     // Add aliases.
12062     lodash.all = every;
12063     lodash.any = some;
12064     lodash.contains = includes;
12065     lodash.eq = isEqual;
12066     lodash.detect = find;
12067     lodash.foldl = reduce;
12068     lodash.foldr = reduceRight;
12069     lodash.head = first;
12070     lodash.include = includes;
12071     lodash.inject = reduce;
12072
12073     mixin(lodash, (function() {
12074       var source = {};
12075       baseForOwn(lodash, function(func, methodName) {
12076         if (!lodash.prototype[methodName]) {
12077           source[methodName] = func;
12078         }
12079       });
12080       return source;
12081     }()), false);
12082
12083     /*------------------------------------------------------------------------*/
12084
12085     // Add functions capable of returning wrapped and unwrapped values when chaining.
12086     lodash.sample = sample;
12087
12088     lodash.prototype.sample = function(n) {
12089       if (!this.__chain__ && n == null) {
12090         return sample(this.value());
12091       }
12092       return this.thru(function(value) {
12093         return sample(value, n);
12094       });
12095     };
12096
12097     /*------------------------------------------------------------------------*/
12098
12099     /**
12100      * The semantic version number.
12101      *
12102      * @static
12103      * @memberOf _
12104      * @type string
12105      */
12106     lodash.VERSION = VERSION;
12107
12108     // Assign default placeholders.
12109     arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
12110       lodash[methodName].placeholder = lodash;
12111     });
12112
12113     // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
12114     arrayEach(['drop', 'take'], function(methodName, index) {
12115       LazyWrapper.prototype[methodName] = function(n) {
12116         var filtered = this.__filtered__;
12117         if (filtered && !index) {
12118           return new LazyWrapper(this);
12119         }
12120         n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
12121
12122         var result = this.clone();
12123         if (filtered) {
12124           result.__takeCount__ = nativeMin(result.__takeCount__, n);
12125         } else {
12126           result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
12127         }
12128         return result;
12129       };
12130
12131       LazyWrapper.prototype[methodName + 'Right'] = function(n) {
12132         return this.reverse()[methodName](n).reverse();
12133       };
12134     });
12135
12136     // Add `LazyWrapper` methods that accept an `iteratee` value.
12137     arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
12138       var type = index + 1,
12139           isFilter = type != LAZY_MAP_FLAG;
12140
12141       LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
12142         var result = this.clone();
12143         result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
12144         result.__filtered__ = result.__filtered__ || isFilter;
12145         return result;
12146       };
12147     });
12148
12149     // Add `LazyWrapper` methods for `_.first` and `_.last`.
12150     arrayEach(['first', 'last'], function(methodName, index) {
12151       var takeName = 'take' + (index ? 'Right' : '');
12152
12153       LazyWrapper.prototype[methodName] = function() {
12154         return this[takeName](1).value()[0];
12155       };
12156     });
12157
12158     // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
12159     arrayEach(['initial', 'rest'], function(methodName, index) {
12160       var dropName = 'drop' + (index ? '' : 'Right');
12161
12162       LazyWrapper.prototype[methodName] = function() {
12163         return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
12164       };
12165     });
12166
12167     // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
12168     arrayEach(['pluck', 'where'], function(methodName, index) {
12169       var operationName = index ? 'filter' : 'map',
12170           createCallback = index ? baseMatches : property;
12171
12172       LazyWrapper.prototype[methodName] = function(value) {
12173         return this[operationName](createCallback(value));
12174       };
12175     });
12176
12177     LazyWrapper.prototype.compact = function() {
12178       return this.filter(identity);
12179     };
12180
12181     LazyWrapper.prototype.reject = function(predicate, thisArg) {
12182       predicate = getCallback(predicate, thisArg, 1);
12183       return this.filter(function(value) {
12184         return !predicate(value);
12185       });
12186     };
12187
12188     LazyWrapper.prototype.slice = function(start, end) {
12189       start = start == null ? 0 : (+start || 0);
12190
12191       var result = this;
12192       if (result.__filtered__ && (start > 0 || end < 0)) {
12193         return new LazyWrapper(result);
12194       }
12195       if (start < 0) {
12196         result = result.takeRight(-start);
12197       } else if (start) {
12198         result = result.drop(start);
12199       }
12200       if (end !== undefined) {
12201         end = (+end || 0);
12202         result = end < 0 ? result.dropRight(-end) : result.take(end - start);
12203       }
12204       return result;
12205     };
12206
12207     LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
12208       return this.reverse().takeWhile(predicate, thisArg).reverse();
12209     };
12210
12211     LazyWrapper.prototype.toArray = function() {
12212       return this.take(POSITIVE_INFINITY);
12213     };
12214
12215     // Add `LazyWrapper` methods to `lodash.prototype`.
12216     baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12217       var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
12218           retUnwrapped = /^(?:first|last)$/.test(methodName),
12219           lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
12220
12221       if (!lodashFunc) {
12222         return;
12223       }
12224       lodash.prototype[methodName] = function() {
12225         var args = retUnwrapped ? [1] : arguments,
12226             chainAll = this.__chain__,
12227             value = this.__wrapped__,
12228             isHybrid = !!this.__actions__.length,
12229             isLazy = value instanceof LazyWrapper,
12230             iteratee = args[0],
12231             useLazy = isLazy || isArray(value);
12232
12233         if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
12234           // Avoid lazy use if the iteratee has a "length" value other than `1`.
12235           isLazy = useLazy = false;
12236         }
12237         var interceptor = function(value) {
12238           return (retUnwrapped && chainAll)
12239             ? lodashFunc(value, 1)[0]
12240             : lodashFunc.apply(undefined, arrayPush([value], args));
12241         };
12242
12243         var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
12244             onlyLazy = isLazy && !isHybrid;
12245
12246         if (retUnwrapped && !chainAll) {
12247           if (onlyLazy) {
12248             value = value.clone();
12249             value.__actions__.push(action);
12250             return func.call(value);
12251           }
12252           return lodashFunc.call(undefined, this.value())[0];
12253         }
12254         if (!retUnwrapped && useLazy) {
12255           value = onlyLazy ? value : new LazyWrapper(this);
12256           var result = func.apply(value, args);
12257           result.__actions__.push(action);
12258           return new LodashWrapper(result, chainAll);
12259         }
12260         return this.thru(interceptor);
12261       };
12262     });
12263
12264     // Add `Array` and `String` methods to `lodash.prototype`.
12265     arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
12266       var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
12267           chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
12268           retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
12269
12270       lodash.prototype[methodName] = function() {
12271         var args = arguments;
12272         if (retUnwrapped && !this.__chain__) {
12273           return func.apply(this.value(), args);
12274         }
12275         return this[chainName](function(value) {
12276           return func.apply(value, args);
12277         });
12278       };
12279     });
12280
12281     // Map minified function names to their real names.
12282     baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12283       var lodashFunc = lodash[methodName];
12284       if (lodashFunc) {
12285         var key = lodashFunc.name,
12286             names = realNames[key] || (realNames[key] = []);
12287
12288         names.push({ 'name': methodName, 'func': lodashFunc });
12289       }
12290     });
12291
12292     realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
12293
12294     // Add functions to the lazy wrapper.
12295     LazyWrapper.prototype.clone = lazyClone;
12296     LazyWrapper.prototype.reverse = lazyReverse;
12297     LazyWrapper.prototype.value = lazyValue;
12298
12299     // Add chaining functions to the `lodash` wrapper.
12300     lodash.prototype.chain = wrapperChain;
12301     lodash.prototype.commit = wrapperCommit;
12302     lodash.prototype.concat = wrapperConcat;
12303     lodash.prototype.plant = wrapperPlant;
12304     lodash.prototype.reverse = wrapperReverse;
12305     lodash.prototype.toString = wrapperToString;
12306     lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
12307
12308     // Add function aliases to the `lodash` wrapper.
12309     lodash.prototype.collect = lodash.prototype.map;
12310     lodash.prototype.head = lodash.prototype.first;
12311     lodash.prototype.select = lodash.prototype.filter;
12312     lodash.prototype.tail = lodash.prototype.rest;
12313
12314     return lodash;
12315   }
12316
12317   /*--------------------------------------------------------------------------*/
12318
12319   // Export lodash.
12320   var _ = runInContext();
12321
12322   // Some AMD build optimizers like r.js check for condition patterns like the following:
12323   if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
12324     // Expose lodash to the global object when an AMD loader is present to avoid
12325     // errors in cases where lodash is loaded by a script tag and not intended
12326     // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
12327     // more details.
12328     root._ = _;
12329
12330     // Define as an anonymous module so, through path mapping, it can be
12331     // referenced as the "underscore" module.
12332     define(function() {
12333       return _;
12334     });
12335   }
12336   // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
12337   else if (freeExports && freeModule) {
12338     // Export for Node.js or RingoJS.
12339     if (moduleExports) {
12340       (freeModule.exports = _)._ = _;
12341     }
12342     // Export for Rhino with CommonJS support.
12343     else {
12344       freeExports._ = _;
12345     }
12346   }
12347   else {
12348     // Export for a browser or Rhino.
12349     root._ = _;
12350   }
12351 }.call(this));