Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / core.js
1 /**
2  * @license
3  * lodash 4.0.1 (Custom Build) <https://lodash.com/>
4  * Build: `lodash core -o ./dist/lodash.core.js`
5  * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7  * Copyright 2009-2016 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 = '4.0.1';
17
18   /** Used to compose bitmasks for wrapper metadata. */
19   var BIND_FLAG = 1,
20       PARTIAL_FLAG = 32;
21
22   /** Used to compose bitmasks for comparison styles. */
23   var UNORDERED_COMPARE_FLAG = 1,
24       PARTIAL_COMPARE_FLAG = 2;
25
26   /** Used as the `TypeError` message for "Functions" methods. */
27   var FUNC_ERROR_TEXT = 'Expected a function';
28
29   /** Used as references for various `Number` constants. */
30   var MAX_SAFE_INTEGER = 9007199254740991;
31
32   /** `Object#toString` result references. */
33   var argsTag = '[object Arguments]',
34       arrayTag = '[object Array]',
35       boolTag = '[object Boolean]',
36       dateTag = '[object Date]',
37       errorTag = '[object Error]',
38       funcTag = '[object Function]',
39       genTag = '[object GeneratorFunction]',
40       numberTag = '[object Number]',
41       objectTag = '[object Object]',
42       regexpTag = '[object RegExp]',
43       stringTag = '[object String]';
44
45   /** Used to match HTML entities and HTML characters. */
46   var reUnescapedHtml = /[&<>"'`]/g,
47       reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
48
49   /** Used to detect unsigned integer values. */
50   var reIsUint = /^(?:0|[1-9]\d*)$/;
51
52   /** Used to map characters to HTML entities. */
53   var htmlEscapes = {
54     '&': '&amp;',
55     '<': '&lt;',
56     '>': '&gt;',
57     '"': '&quot;',
58     "'": '&#39;',
59     '`': '&#96;'
60   };
61
62   /** Used to determine if values are of the language type `Object`. */
63   var objectTypes = {
64     'function': true,
65     'object': true
66   };
67
68   /** Detect free variable `exports`. */
69   var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
70
71   /** Detect free variable `module`. */
72   var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
73
74   /** Detect free variable `global` from Node.js. */
75   var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
76
77   /** Detect free variable `self`. */
78   var freeSelf = checkGlobal(objectTypes[typeof self] && self);
79
80   /** Detect free variable `window`. */
81   var freeWindow = checkGlobal(objectTypes[typeof window] && window);
82
83   /** Detect the popular CommonJS extension `module.exports`. */
84   var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
85
86   /** Detect `this` as the global object. */
87   var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
88
89   /**
90    * Used as a reference to the global object.
91    *
92    * The `this` value is used if it's the global object to avoid Greasemonkey's
93    * restricted `window` object, otherwise the `window` object is used.
94    */
95   var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
96
97   /*--------------------------------------------------------------------------*/
98
99   /**
100    * Creates a new array concatenating `array` with `other`.
101    *
102    * @private
103    * @param {Array} array The first array to concatenate.
104    * @param {Array} other The second array to concatenate.
105    * @returns {Array} Returns the new concatenated array.
106    */
107   function arrayConcat(array, other) {
108     return arrayPush(copyArray(array), values);
109   }
110
111   /**
112    * Appends the elements of `values` to `array`.
113    *
114    * @private
115    * @param {Array} array The array to modify.
116    * @param {Array} values The values to append.
117    * @returns {Array} Returns `array`.
118    */
119   function arrayPush(array, values) {
120     var index = -1,
121         length = values.length,
122         offset = array.length;
123
124     while (++index < length) {
125       array[offset + index] = values[index];
126     }
127     return array;
128   }
129
130   /**
131    * The base implementation of methods like `_.max` and `_.min` which accepts a
132    * `comparator` to determine the extremum value.
133    *
134    * @private
135    * @param {Array} array The array to iterate over.
136    * @param {Function} iteratee The iteratee invoked per iteration.
137    * @param {Function} comparator The comparator used to compare values.
138    * @returns {*} Returns the extremum value.
139    */
140   function baseExtremum(array, iteratee, comparator) {
141     var index = -1,
142         length = array.length;
143
144     while (++index < length) {
145       var value = array[index],
146           current = iteratee(value);
147
148       if (current != null && (computed === undefined
149             ? current === current
150             : comparator(current, computed)
151           )) {
152         var computed = current,
153             result = value;
154       }
155     }
156     return result;
157   }
158
159   /**
160    * The base implementation of methods like `_.find` and `_.findKey`, without
161    * support for iteratee shorthands, which iterates over `collection` using
162    * `eachFunc`.
163    *
164    * @private
165    * @param {Array|Object} collection The collection to search.
166    * @param {Function} predicate The function invoked per iteration.
167    * @param {Function} eachFunc The function to iterate over `collection`.
168    * @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
169    * @returns {*} Returns the found element or its key, else `undefined`.
170    */
171   function baseFind(collection, predicate, eachFunc, retKey) {
172     var result;
173     eachFunc(collection, function(value, key, collection) {
174       if (predicate(value, key, collection)) {
175         result = retKey ? key : value;
176         return false;
177       }
178     });
179     return result;
180   }
181
182   /**
183    * The base implementation of `_.reduce` and `_.reduceRight`, without support
184    * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
185    *
186    * @private
187    * @param {Array|Object} collection The collection to iterate over.
188    * @param {Function} iteratee The function invoked per iteration.
189    * @param {*} accumulator The initial value.
190    * @param {boolean} initAccum Specify using the first or last element of `collection` as the initial value.
191    * @param {Function} eachFunc The function to iterate over `collection`.
192    * @returns {*} Returns the accumulated value.
193    */
194   function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
195     eachFunc(collection, function(value, index, collection) {
196       accumulator = initAccum
197         ? (initAccum = false, value)
198         : iteratee(accumulator, value, index, collection);
199     });
200     return accumulator;
201   }
202
203   /**
204    * The base implementation of `_.times` without support for iteratee shorthands
205    * or max array length checks.
206    *
207    * @private
208    * @param {number} n The number of times to invoke `iteratee`.
209    * @param {Function} iteratee The function invoked per iteration.
210    * @returns {Array} Returns the array of results.
211    */
212   function baseTimes(n, iteratee) {
213     var index = -1,
214         result = Array(n);
215
216     while (++index < n) {
217       result[index] = iteratee(index);
218     }
219     return result;
220   }
221
222   /**
223    * The base implementation of `_.values` and `_.valuesIn` which creates an
224    * array of `object` property values corresponding to the property names
225    * of `props`.
226    *
227    * @private
228    * @param {Object} object The object to query.
229    * @param {Array} props The property names to get values for.
230    * @returns {Object} Returns the array of property values.
231    */
232   function baseValues(object, props) {
233     return baseMap(props, function(key) {
234       return object[key];
235     });
236   }
237
238   /**
239    * Checks if `value` is a global object.
240    *
241    * @private
242    * @param {*} value The value to check.
243    * @returns {null|Object} Returns `value` if it's a global object, else `null`.
244    */
245   function checkGlobal(value) {
246     return (value && value.Object === Object) ? value : null;
247   }
248
249   /**
250    * Compares values to sort them in ascending order.
251    *
252    * @private
253    * @param {*} value The value to compare.
254    * @param {*} other The other value to compare.
255    * @returns {number} Returns the sort order indicator for `value`.
256    */
257   function compareAscending(value, other) {
258     if (value !== other) {
259       var valIsNull = value === null,
260           valIsUndef = value === undefined,
261           valIsReflexive = value === value;
262
263       var othIsNull = other === null,
264           othIsUndef = other === undefined,
265           othIsReflexive = other === other;
266
267       if ((value > other && !othIsNull) || !valIsReflexive ||
268           (valIsNull && !othIsUndef && othIsReflexive) ||
269           (valIsUndef && othIsReflexive)) {
270         return 1;
271       }
272       if ((value < other && !valIsNull) || !othIsReflexive ||
273           (othIsNull && !valIsUndef && valIsReflexive) ||
274           (othIsUndef && valIsReflexive)) {
275         return -1;
276       }
277     }
278     return 0;
279   }
280
281   /**
282    * Used by `_.escape` to convert characters to HTML entities.
283    *
284    * @private
285    * @param {string} chr The matched character to escape.
286    * @returns {string} Returns the escaped character.
287    */
288   function escapeHtmlChar(chr) {
289     return htmlEscapes[chr];
290   }
291
292   /**
293    * Checks if `value` is a host object in IE < 9.
294    *
295    * @private
296    * @param {*} value The value to check.
297    * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
298    */
299   function isHostObject(value) {
300     // Many host objects are `Object` objects that can coerce to strings
301     // despite having improperly defined `toString` methods.
302     var result = false;
303     if (value != null && typeof value.toString != 'function') {
304       try {
305         result = !!(value + '');
306       } catch (e) {}
307     }
308     return result;
309   }
310
311   /**
312    * Checks if `value` is a valid array-like index.
313    *
314    * @private
315    * @param {*} value The value to check.
316    * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
317    * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
318    */
319   function isIndex(value, length) {
320     value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
321     length = length == null ? MAX_SAFE_INTEGER : length;
322     return value > -1 && value % 1 == 0 && value < length;
323   }
324
325   /**
326    * Converts `iterator` to an array.
327    *
328    * @private
329    * @param {Object} iterator The iterator to convert.
330    * @returns {Array} Returns the converted array.
331    */
332   function iteratorToArray(iterator) {
333     var data,
334         result = [];
335
336     while (!(data = iterator.next()).done) {
337       result.push(data.value);
338     }
339     return result;
340   }
341
342   /*--------------------------------------------------------------------------*/
343
344   /** Used for built-in method references. */
345   var arrayProto = Array.prototype,
346       objectProto = Object.prototype;
347
348   /** Used to check objects for own properties. */
349   var hasOwnProperty = objectProto.hasOwnProperty;
350
351   /** Used to generate unique IDs. */
352   var idCounter = 0;
353
354   /**
355    * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
356    * of values.
357    */
358   var objectToString = objectProto.toString;
359
360   /** Used to restore the original `_` reference in `_.noConflict`. */
361   var oldDash = root._;
362
363   /** Built-in value references. */
364   var Reflect = root.Reflect,
365       Symbol = root.Symbol,
366       Uint8Array = root.Uint8Array,
367       enumerate = Reflect ? Reflect.enumerate : undefined,
368       propertyIsEnumerable = objectProto.propertyIsEnumerable;
369
370   /* Built-in method references for those with the same name as other `lodash` methods. */
371   var nativeIsFinite = root.isFinite,
372       nativeKeys = Object.keys,
373       nativeMax = Math.max;
374
375   /*------------------------------------------------------------------------*/
376
377   /**
378    * Creates a `lodash` object which wraps `value` to enable implicit method
379    * chaining. Methods that operate on and return arrays, collections, and
380    * functions can be chained together. Methods that retrieve a single value or
381    * may return a primitive value will automatically end the chain sequence and
382    * return the unwrapped value. Otherwise, the value must be unwrapped with
383    * `_#value`.
384    *
385    * Explicit chaining, which must be unwrapped with `_#value` in all cases,
386    * may be enabled using `_.chain`.
387    *
388    * The execution of chained methods is lazy, that is, it's deferred until
389    * `_#value` is implicitly or explicitly called.
390    *
391    * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
392    * fusion is an optimization to merge iteratee calls; this avoids the creation
393    * of intermediate arrays and can greatly reduce the number of iteratee executions.
394    * Sections of a chain sequence qualify for shortcut fusion if the section is
395    * applied to an array of at least two hundred elements and any iteratees
396    * accept only one argument. The heuristic for whether a section qualifies
397    * for shortcut fusion is subject to change.
398    *
399    * Chaining is supported in custom builds as long as the `_#value` method is
400    * directly or indirectly included in the build.
401    *
402    * In addition to lodash methods, wrappers have `Array` and `String` methods.
403    *
404    * The wrapper `Array` methods are:
405    * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
406    *
407    * The wrapper `String` methods are:
408    * `replace` and `split`
409    *
410    * The wrapper methods that support shortcut fusion are:
411    * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
412    * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
413    * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
414    *
415    * The chainable wrapper methods are:
416    * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
417    * `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
418    * `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
419    * `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
420    * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
421    * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
422    * `flowRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
423    * `intersection`, `intersectionBy`, `intersectionWith`, `invert`, `invokeMap`,
424    * `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
425    * `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
426    * `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
427    * `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
428    * `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
429    * `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
430    * `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
431    * `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
432    * `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
433    * `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
434    * `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
435    * `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
436    * `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
437    *
438    * The wrapper methods that are **not** chainable by default are:
439    * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
440    * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
441    * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
442    * `findLast`, `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`,
443    * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
444    * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
445    * `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
446    * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
447    * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`, `isMatchWith`,
448    * `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`, `isObject`, `isObjectLike`,
449    * `isPlainObject`, `isRegExp`, `isSafeInteger`, `isString`, `isUndefined`,
450    * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`,
451    * `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`,
452    * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`,
453    * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
454    * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
455    * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
456    * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toLower`,
457    * `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`,
458    * `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
459    * `upperCase`, `upperFirst`, `value`, and `words`
460    *
461    * @name _
462    * @constructor
463    * @category Seq
464    * @param {*} value The value to wrap in a `lodash` instance.
465    * @returns {Object} Returns the new `lodash` wrapper instance.
466    * @example
467    *
468    * function square(n) {
469    *   return n * n;
470    * }
471    *
472    * var wrapped = _([1, 2, 3]);
473    *
474    * // returns an unwrapped value
475    * wrapped.reduce(_.add);
476    * // => 6
477    *
478    * // returns a wrapped value
479    * var squares = wrapped.map(square);
480    *
481    * _.isArray(squares);
482    * // => false
483    *
484    * _.isArray(squares.value());
485    * // => true
486    */
487   function lodash(value) {
488     if (isObjectLike(value) && !isArray(value)) {
489       if (value instanceof LodashWrapper) {
490         return value;
491       }
492       if (hasOwnProperty.call(value, '__wrapped__')) {
493         return wrapperClone(value);
494       }
495     }
496     return new LodashWrapper(value);
497   }
498
499   /**
500    * The base constructor for creating `lodash` wrapper objects.
501    *
502    * @private
503    * @param {*} value The value to wrap.
504    * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
505    */
506   function LodashWrapper(value, chainAll) {
507     this.__wrapped__ = value;
508     this.__actions__ = [];
509     this.__chain__ = !!chainAll;
510   }
511
512   /*------------------------------------------------------------------------*/
513
514   /**
515    * Used by `_.defaults` to customize its `_.assignIn` use.
516    *
517    * @private
518    * @param {*} objValue The destination value.
519    * @param {*} srcValue The source value.
520    * @param {string} key The key of the property to assign.
521    * @param {Object} object The parent object of `objValue`.
522    * @returns {*} Returns the value to assign.
523    */
524   function assignInDefaults(objValue, srcValue, key, object) {
525     if (objValue === undefined ||
526         (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
527       return srcValue;
528     }
529     return objValue;
530   }
531
532   /**
533    * Assigns `value` to `key` of `object` if the existing value is not equivalent
534    * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
535    * for equality comparisons.
536    *
537    * @private
538    * @param {Object} object The object to modify.
539    * @param {string} key The key of the property to assign.
540    * @param {*} value The value to assign.
541    */
542   function assignValue(object, key, value) {
543     var objValue = object[key];
544     if ((!eq(objValue, value) ||
545           (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
546         (value === undefined && !(key in object))) {
547       object[key] = value;
548     }
549   }
550
551   /**
552    * The base implementation of `_.create` without support for assigning
553    * properties to the created object.
554    *
555    * @private
556    * @param {Object} prototype The object to inherit from.
557    * @returns {Object} Returns the new object.
558    */
559   var baseCreate = (function() {
560     function object() {}
561     return function(prototype) {
562       if (isObject(prototype)) {
563         object.prototype = prototype;
564         var result = new object;
565         object.prototype = undefined;
566       }
567       return result || {};
568     };
569   }());
570
571   /**
572    * The base implementation of `_.delay` and `_.defer` which accepts an array
573    * of `func` arguments.
574    *
575    * @private
576    * @param {Function} func The function to delay.
577    * @param {number} wait The number of milliseconds to delay invocation.
578    * @param {Object} args The arguments provide to `func`.
579    * @returns {number} Returns the timer id.
580    */
581   function baseDelay(func, wait, args) {
582     if (typeof func != 'function') {
583       throw new TypeError(FUNC_ERROR_TEXT);
584     }
585     return setTimeout(function() { func.apply(undefined, args); }, wait);
586   }
587
588   /**
589    * The base implementation of `_.forEach` without support for iteratee shorthands.
590    *
591    * @private
592    * @param {Array|Object} collection The collection to iterate over.
593    * @param {Function} iteratee The function invoked per iteration.
594    * @returns {Array|Object} Returns `collection`.
595    */
596   var baseEach = createBaseEach(baseForOwn);
597
598   /**
599    * The base implementation of `_.every` without support for iteratee shorthands.
600    *
601    * @private
602    * @param {Array|Object} collection The collection to iterate over.
603    * @param {Function} predicate The function invoked per iteration.
604    * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
605    */
606   function baseEvery(collection, predicate) {
607     var result = true;
608     baseEach(collection, function(value, index, collection) {
609       result = !!predicate(value, index, collection);
610       return result;
611     });
612     return result;
613   }
614
615   /**
616    * The base implementation of `_.filter` without support for iteratee shorthands.
617    *
618    * @private
619    * @param {Array|Object} collection The collection to iterate over.
620    * @param {Function} predicate The function invoked per iteration.
621    * @returns {Array} Returns the new filtered array.
622    */
623   function baseFilter(collection, predicate) {
624     var result = [];
625     baseEach(collection, function(value, index, collection) {
626       if (predicate(value, index, collection)) {
627         result.push(value);
628       }
629     });
630     return result;
631   }
632
633   /**
634    * The base implementation of `_.flatten` with support for restricting flattening.
635    *
636    * @private
637    * @param {Array} array The array to flatten.
638    * @param {boolean} [isDeep] Specify a deep flatten.
639    * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
640    * @param {Array} [result=[]] The initial result value.
641    * @returns {Array} Returns the new flattened array.
642    */
643   function baseFlatten(array, isDeep, isStrict, result) {
644     result || (result = []);
645
646     var index = -1,
647         length = array.length;
648
649     while (++index < length) {
650       var value = array[index];
651       if (isArrayLikeObject(value) &&
652           (isStrict || isArray(value) || isArguments(value))) {
653         if (isDeep) {
654           // Recursively flatten arrays (susceptible to call stack limits).
655           baseFlatten(value, isDeep, isStrict, result);
656         } else {
657           arrayPush(result, value);
658         }
659       } else if (!isStrict) {
660         result[result.length] = value;
661       }
662     }
663     return result;
664   }
665
666   /**
667    * The base implementation of `baseForIn` and `baseForOwn` which iterates
668    * over `object` properties returned by `keysFunc` invoking `iteratee` for
669    * each property. Iteratee functions may exit iteration early by explicitly
670    * returning `false`.
671    *
672    * @private
673    * @param {Object} object The object to iterate over.
674    * @param {Function} iteratee The function invoked per iteration.
675    * @param {Function} keysFunc The function to get the keys of `object`.
676    * @returns {Object} Returns `object`.
677    */
678   var baseFor = createBaseFor();
679
680   /**
681    * The base implementation of `_.forOwn` without support for iteratee shorthands.
682    *
683    * @private
684    * @param {Object} object The object to iterate over.
685    * @param {Function} iteratee The function invoked per iteration.
686    * @returns {Object} Returns `object`.
687    */
688   function baseForOwn(object, iteratee) {
689     return object && baseFor(object, iteratee, keys);
690   }
691
692   /**
693    * The base implementation of `_.functions` which creates an array of
694    * `object` function property names filtered from those provided.
695    *
696    * @private
697    * @param {Object} object The object to inspect.
698    * @param {Array} props The property names to filter.
699    * @returns {Array} Returns the new array of filtered property names.
700    */
701   function baseFunctions(object, props) {
702     return baseFilter(props, function(key) {
703       return isFunction(object[key]);
704     });
705   }
706
707   /**
708    * The base implementation of `_.isEqual` which supports partial comparisons
709    * and tracks traversed objects.
710    *
711    * @private
712    * @param {*} value The value to compare.
713    * @param {*} other The other value to compare.
714    * @param {Function} [customizer] The function to customize comparisons.
715    * @param {boolean} [bitmask] The bitmask of comparison flags.
716    *  The bitmask may be composed of the following flags:
717    *     1 - Unordered comparison
718    *     2 - Partial comparison
719    * @param {Object} [stack] Tracks traversed `value` and `other` objects.
720    * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
721    */
722   function baseIsEqual(value, other, customizer, bitmask, stack) {
723     if (value === other) {
724       return true;
725     }
726     if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
727       return value !== value && other !== other;
728     }
729     return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
730   }
731
732   /**
733    * A specialized version of `baseIsEqual` for arrays and objects which performs
734    * deep comparisons and tracks traversed objects enabling objects with circular
735    * references to be compared.
736    *
737    * @private
738    * @param {Object} object The object to compare.
739    * @param {Object} other The other object to compare.
740    * @param {Function} equalFunc The function to determine equivalents of values.
741    * @param {Function} [customizer] The function to customize comparisons.
742    * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
743    * @param {Object} [stack] Tracks traversed `object` and `other` objects.
744    * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
745    */
746   function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
747     var objIsArr = isArray(object),
748         othIsArr = isArray(other),
749         objTag = arrayTag,
750         othTag = arrayTag;
751
752     if (!objIsArr) {
753       objTag = objectToString.call(object);
754       if (objTag == argsTag) {
755         objTag = objectTag;
756       }
757     }
758     if (!othIsArr) {
759       othTag = objectToString.call(other);
760       if (othTag == argsTag) {
761         othTag = objectTag;
762       }
763     }
764     var objIsObj = objTag == objectTag && !isHostObject(object),
765         othIsObj = othTag == objectTag && !isHostObject(other),
766         isSameTag = objTag == othTag;
767
768     if (isSameTag && !(objIsArr || objIsObj)) {
769       return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
770     }
771     var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
772     if (!isPartial) {
773       var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
774           othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
775
776       if (objIsWrapped || othIsWrapped) {
777         return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
778       }
779     }
780     if (!isSameTag) {
781       return false;
782     }
783     stack || (stack = []);
784     var stacked = find(stack, function(entry) {
785       return entry[0] === object;
786     });
787     if (stacked && stacked[1]) {
788       return stacked[1] == other;
789     }
790     stack.push([object, other]);
791     var result =  (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
792     stack.pop();
793     return result;
794   }
795
796   /**
797    * The base implementation of `_.iteratee`.
798    *
799    * @private
800    * @param {*} [value=_.identity] The value to convert to an iteratee.
801    * @returns {Function} Returns the iteratee.
802    */
803   function baseIteratee(func) {
804     var type = typeof func;
805     if (type == 'function') {
806       return func;
807     }
808     return func == null
809       ? identity
810       : (type == 'object' ? baseMatches : baseProperty)(func);
811   }
812
813   /**
814    * The base implementation of `_.keys` which doesn't skip the constructor
815    * property of prototypes or treat sparse arrays as dense.
816    *
817    * @private
818    * @type Function
819    * @param {Object} object The object to query.
820    * @returns {Array} Returns the array of property names.
821    */
822   function baseKeys(object) {
823     return nativeKeys(Object(object));
824   }
825
826   /**
827    * The base implementation of `_.keysIn` which doesn't skip the constructor
828    * property of prototypes or treat sparse arrays as dense.
829    *
830    * @private
831    * @param {Object} object The object to query.
832    * @returns {Array} Returns the array of property names.
833    */
834   function baseKeysIn(object) {
835     object = object == null ? object : Object(object);
836
837     var result = [];
838     for (var key in object) {
839       result.push(key);
840     }
841     return result;
842   }
843
844   // Fallback for IE < 9 with es6-shim.
845   if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
846     baseKeysIn = function(object) {
847       return iteratorToArray(enumerate(object));
848     };
849   }
850
851   /**
852    * The base implementation of `_.map` without support for iteratee shorthands.
853    *
854    * @private
855    * @param {Array|Object} collection The collection to iterate over.
856    * @param {Function} iteratee The function invoked per iteration.
857    * @returns {Array} Returns the new mapped array.
858    */
859   function baseMap(collection, iteratee) {
860     var index = -1,
861         result = isArrayLike(collection) ? Array(collection.length) : [];
862
863     baseEach(collection, function(value, key, collection) {
864       result[++index] = iteratee(value, key, collection);
865     });
866     return result;
867   }
868
869   /**
870    * The base implementation of `_.matches` which doesn't clone `source`.
871    *
872    * @private
873    * @param {Object} source The object of property values to match.
874    * @returns {Function} Returns the new function.
875    */
876   function baseMatches(source) {
877     var props = keys(source);
878     return function(object) {
879       var length = props.length;
880       if (object == null) {
881         return !length;
882       }
883       object = Object(object);
884       while (length--) {
885         var key = props[length];
886         if (!(key in object &&
887               baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
888             )) {
889           return false;
890         }
891       }
892       return true;
893     };
894   }
895
896   /**
897    * The base implementation of `_.pick` without support for individual
898    * property names.
899    *
900    * @private
901    * @param {Object} object The source object.
902    * @param {string[]} props The property names to pick.
903    * @returns {Object} Returns the new object.
904    */
905   function basePick(object, props) {
906     object = Object(object);
907     return reduce(props, function(result, key) {
908       if (key in object) {
909         result[key] = object[key];
910       }
911       return result;
912     }, {});
913   }
914
915   /**
916    * The base implementation of `_.property` without support for deep paths.
917    *
918    * @private
919    * @param {string} key The key of the property to get.
920    * @returns {Function} Returns the new function.
921    */
922   function baseProperty(key) {
923     return function(object) {
924       return object == null ? undefined : object[key];
925     };
926   }
927
928   /**
929    * The base implementation of `_.slice` without an iteratee call guard.
930    *
931    * @private
932    * @param {Array} array The array to slice.
933    * @param {number} [start=0] The start position.
934    * @param {number} [end=array.length] The end position.
935    * @returns {Array} Returns the slice of `array`.
936    */
937   function baseSlice(array, start, end) {
938     var index = -1,
939         length = array.length;
940
941     if (start < 0) {
942       start = -start > length ? 0 : (length + start);
943     }
944     end = end > length ? length : end;
945     if (end < 0) {
946       end += length;
947     }
948     length = start > end ? 0 : ((end - start) >>> 0);
949     start >>>= 0;
950
951     var result = Array(length);
952     while (++index < length) {
953       result[index] = array[index + start];
954     }
955     return result;
956   }
957
958   /**
959    * Copies the values of `source` to `array`.
960    *
961    * @private
962    * @param {Array} source The array to copy values from.
963    * @param {Array} [array=[]] The array to copy values to.
964    * @returns {Array} Returns `array`.
965    */
966   function copyArray(source) {
967     return baseSlice(source, 0, source.length);
968   }
969
970   /**
971    * The base implementation of `_.some` without support for iteratee shorthands.
972    *
973    * @private
974    * @param {Array|Object} collection The collection to iterate over.
975    * @param {Function} predicate The function invoked per iteration.
976    * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
977    */
978   function baseSome(collection, predicate) {
979     var result;
980
981     baseEach(collection, function(value, index, collection) {
982       result = predicate(value, index, collection);
983       return !result;
984     });
985     return !!result;
986   }
987
988   /**
989    * The base implementation of `wrapperValue` which returns the result of
990    * performing a sequence of actions on the unwrapped `value`, where each
991    * successive action is supplied the return value of the previous.
992    *
993    * @private
994    * @param {*} value The unwrapped value.
995    * @param {Array} actions Actions to perform to resolve the unwrapped value.
996    * @returns {*} Returns the resolved value.
997    */
998   function baseWrapperValue(value, actions) {
999     var result = value;
1000     return reduce(actions, function(result, action) {
1001       return action.func.apply(action.thisArg, arrayPush([result], action.args));
1002     }, result);
1003   }
1004
1005   /**
1006    * Copies properties of `source` to `object`.
1007    *
1008    * @private
1009    * @param {Object} source The object to copy properties from.
1010    * @param {Array} props The property names to copy.
1011    * @param {Object} [object={}] The object to copy properties to.
1012    * @returns {Object} Returns `object`.
1013    */
1014   var copyObject = copyObjectWith;
1015
1016   /**
1017    * This function is like `copyObject` except that it accepts a function to
1018    * customize copied values.
1019    *
1020    * @private
1021    * @param {Object} source The object to copy properties from.
1022    * @param {Array} props The property names to copy.
1023    * @param {Object} [object={}] The object to copy properties to.
1024    * @param {Function} [customizer] The function to customize copied values.
1025    * @returns {Object} Returns `object`.
1026    */
1027   function copyObjectWith(source, props, object, customizer) {
1028     object || (object = {});
1029
1030     var index = -1,
1031         length = props.length;
1032
1033     while (++index < length) {
1034       var key = props[index],
1035           newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
1036
1037       assignValue(object, key, newValue);
1038     }
1039     return object;
1040   }
1041
1042   /**
1043    * Creates a function like `_.assign`.
1044    *
1045    * @private
1046    * @param {Function} assigner The function to assign values.
1047    * @returns {Function} Returns the new assigner function.
1048    */
1049   function createAssigner(assigner) {
1050     return rest(function(object, sources) {
1051       var index = -1,
1052           length = sources.length,
1053           customizer = length > 1 ? sources[length - 1] : undefined;
1054
1055       customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
1056       object = Object(object);
1057       while (++index < length) {
1058         var source = sources[index];
1059         if (source) {
1060           assigner(object, source, index, customizer);
1061         }
1062       }
1063       return object;
1064     });
1065   }
1066
1067   /**
1068    * Creates a `baseEach` or `baseEachRight` function.
1069    *
1070    * @private
1071    * @param {Function} eachFunc The function to iterate over a collection.
1072    * @param {boolean} [fromRight] Specify iterating from right to left.
1073    * @returns {Function} Returns the new base function.
1074    */
1075   function createBaseEach(eachFunc, fromRight) {
1076     return function(collection, iteratee) {
1077       if (collection == null) {
1078         return collection;
1079       }
1080       if (!isArrayLike(collection)) {
1081         return eachFunc(collection, iteratee);
1082       }
1083       var length = collection.length,
1084           index = fromRight ? length : -1,
1085           iterable = Object(collection);
1086
1087       while ((fromRight ? index-- : ++index < length)) {
1088         if (iteratee(iterable[index], index, iterable) === false) {
1089           break;
1090         }
1091       }
1092       return collection;
1093     };
1094   }
1095
1096   /**
1097    * Creates a base function for methods like `_.forIn`.
1098    *
1099    * @private
1100    * @param {boolean} [fromRight] Specify iterating from right to left.
1101    * @returns {Function} Returns the new base function.
1102    */
1103   function createBaseFor(fromRight) {
1104     return function(object, iteratee, keysFunc) {
1105       var index = -1,
1106           iterable = Object(object),
1107           props = keysFunc(object),
1108           length = props.length;
1109
1110       while (length--) {
1111         var key = props[fromRight ? length : ++index];
1112         if (iteratee(iterable[key], key, iterable) === false) {
1113           break;
1114         }
1115       }
1116       return object;
1117     };
1118   }
1119
1120   /**
1121    * Creates a function that produces an instance of `Ctor` regardless of
1122    * whether it was invoked as part of a `new` expression or by `call` or `apply`.
1123    *
1124    * @private
1125    * @param {Function} Ctor The constructor to wrap.
1126    * @returns {Function} Returns the new wrapped function.
1127    */
1128   function createCtorWrapper(Ctor) {
1129     return function() {
1130       // Use a `switch` statement to work with class constructors.
1131       // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
1132       // for more details.
1133       var args = arguments;
1134       var thisBinding = baseCreate(Ctor.prototype),
1135           result = Ctor.apply(thisBinding, args);
1136
1137       // Mimic the constructor's `return` behavior.
1138       // See https://es5.github.io/#x13.2.2 for more details.
1139       return isObject(result) ? result : thisBinding;
1140     };
1141   }
1142
1143   /**
1144    * Creates a function that wraps `func` to invoke it with the optional `this`
1145    * binding of `thisArg` and the `partials` prepended to those provided to
1146    * the wrapper.
1147    *
1148    * @private
1149    * @param {Function} func The function to wrap.
1150    * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
1151    * @param {*} thisArg The `this` binding of `func`.
1152    * @param {Array} partials The arguments to prepend to those provided to the new function.
1153    * @returns {Function} Returns the new wrapped function.
1154    */
1155   function createPartialWrapper(func, bitmask, thisArg, partials) {
1156     if (typeof func != 'function') {
1157       throw new TypeError(FUNC_ERROR_TEXT);
1158     }
1159     var isBind = bitmask & BIND_FLAG,
1160         Ctor = createCtorWrapper(func);
1161
1162     function wrapper() {
1163       var argsIndex = -1,
1164           argsLength = arguments.length,
1165           leftIndex = -1,
1166           leftLength = partials.length,
1167           args = Array(leftLength + argsLength),
1168           fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
1169
1170       while (++leftIndex < leftLength) {
1171         args[leftIndex] = partials[leftIndex];
1172       }
1173       while (argsLength--) {
1174         args[leftIndex++] = arguments[++argsIndex];
1175       }
1176       return fn.apply(isBind ? thisArg : this, args);
1177     }
1178     return wrapper;
1179   }
1180
1181   /**
1182    * A specialized version of `baseIsEqualDeep` for arrays with support for
1183    * partial deep comparisons.
1184    *
1185    * @private
1186    * @param {Array} array The array to compare.
1187    * @param {Array} other The other array to compare.
1188    * @param {Function} equalFunc The function to determine equivalents of values.
1189    * @param {Function} [customizer] The function to customize comparisons.
1190    * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1191    * @param {Object} [stack] Tracks traversed `array` and `other` objects.
1192    * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1193    */
1194   function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
1195     var index = -1,
1196         isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1197         isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
1198         arrLength = array.length,
1199         othLength = other.length;
1200
1201     if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1202       return false;
1203     }
1204     var result = true;
1205
1206     // Ignore non-index properties.
1207     while (++index < arrLength) {
1208       var arrValue = array[index],
1209           othValue = other[index];
1210
1211       var compared;
1212       if (compared !== undefined) {
1213         if (compared) {
1214           continue;
1215         }
1216         result = false;
1217         break;
1218       }
1219       // Recursively compare arrays (susceptible to call stack limits).
1220       if (isUnordered) {
1221         if (!baseSome(other, function(othValue) {
1222               return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
1223             })) {
1224           result = false;
1225           break;
1226         }
1227       } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
1228         result = false;
1229         break;
1230       }
1231     }
1232     return result;
1233   }
1234
1235   /**
1236    * A specialized version of `baseIsEqualDeep` for comparing objects of
1237    * the same `toStringTag`.
1238    *
1239    * **Note:** This function only supports comparing values with tags of
1240    * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1241    *
1242    * @private
1243    * @param {Object} object The object to compare.
1244    * @param {Object} other The other object to compare.
1245    * @param {string} tag The `toStringTag` of the objects to compare.
1246    * @param {Function} equalFunc The function to determine equivalents of values.
1247    * @param {Function} [customizer] The function to customize comparisons.
1248    * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1249    * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1250    */
1251   function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
1252     switch (tag) {
1253
1254       case boolTag:
1255       case dateTag:
1256         // Coerce dates and booleans to numbers, dates to milliseconds and booleans
1257         // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
1258         return +object == +other;
1259
1260       case errorTag:
1261         return object.name == other.name && object.message == other.message;
1262
1263       case numberTag:
1264         // Treat `NaN` vs. `NaN` as equal.
1265         return (object != +object) ? other != +other : object == +other;
1266
1267       case regexpTag:
1268       case stringTag:
1269         // Coerce regexes to strings and treat strings primitives and string
1270         // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
1271         return object == (other + '');
1272
1273     }
1274     return false;
1275   }
1276
1277   /**
1278    * A specialized version of `baseIsEqualDeep` for objects with support for
1279    * partial deep comparisons.
1280    *
1281    * @private
1282    * @param {Object} object The object to compare.
1283    * @param {Object} other The other object to compare.
1284    * @param {Function} equalFunc The function to determine equivalents of values.
1285    * @param {Function} [customizer] The function to customize comparisons.
1286    * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
1287    * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1288    * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1289    */
1290   function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
1291     var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
1292         objProps = keys(object),
1293         objLength = objProps.length,
1294         othProps = keys(other),
1295         othLength = othProps.length;
1296
1297     if (objLength != othLength && !isPartial) {
1298       return false;
1299     }
1300     var index = objLength;
1301     while (index--) {
1302       var key = objProps[index];
1303       if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1304         return false;
1305       }
1306     }
1307     var result = true;
1308
1309     var skipCtor = isPartial;
1310     while (++index < objLength) {
1311       key = objProps[index];
1312       var objValue = object[key],
1313           othValue = other[key];
1314
1315       var compared;
1316       // Recursively compare objects (susceptible to call stack limits).
1317       if (!(compared === undefined
1318             ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
1319             : compared
1320           )) {
1321         result = false;
1322         break;
1323       }
1324       skipCtor || (skipCtor = key == 'constructor');
1325     }
1326     if (result && !skipCtor) {
1327       var objCtor = object.constructor,
1328           othCtor = other.constructor;
1329
1330       // Non `Object` object instances with different constructors are not equal.
1331       if (objCtor != othCtor &&
1332           ('constructor' in object && 'constructor' in other) &&
1333           !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1334             typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1335         result = false;
1336       }
1337     }
1338     return result;
1339   }
1340
1341   /**
1342    * Gets the "length" property value of `object`.
1343    *
1344    * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
1345    * that affects Safari on at least iOS 8.1-8.3 ARM64.
1346    *
1347    * @private
1348    * @param {Object} object The object to query.
1349    * @returns {*} Returns the "length" value.
1350    */
1351   var getLength = baseProperty('length');
1352
1353   /**
1354    * Creates an array of index keys for `object` values of arrays,
1355    * `arguments` objects, and strings, otherwise `null` is returned.
1356    *
1357    * @private
1358    * @param {Object} object The object to query.
1359    * @returns {Array|null} Returns index keys, else `null`.
1360    */
1361   function indexKeys(object) {
1362     var length = object ? object.length : undefined;
1363     return (isLength(length) && (isArray(object) || isString(object) || isArguments(object)))
1364       ? baseTimes(length, String)
1365       : null;
1366   }
1367
1368   /**
1369    * Checks if `value` is likely a prototype object.
1370    *
1371    * @private
1372    * @param {*} value The value to check.
1373    * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1374    */
1375   function isPrototype(value) {
1376     var Ctor = value && value.constructor,
1377         proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1378
1379     return value === proto;
1380   }
1381
1382   /**
1383    * Converts `value` to a function if it's not one.
1384    *
1385    * @private
1386    * @param {*} value The value to process.
1387    * @returns {Function} Returns the function.
1388    */
1389   function toFunction(value) {
1390     return typeof value == 'function' ? value : identity;
1391   }
1392
1393   /**
1394    * Creates a clone of `wrapper`.
1395    *
1396    * @private
1397    * @param {Object} wrapper The wrapper to clone.
1398    * @returns {Object} Returns the cloned wrapper.
1399    */
1400   function wrapperClone(wrapper) {
1401     var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
1402     result.__actions__ = copyArray(wrapper.__actions__);
1403     return result;
1404   }
1405
1406   /*------------------------------------------------------------------------*/
1407
1408   /**
1409    * Creates an array with all falsey values removed. The values `false`, `null`,
1410    * `0`, `""`, `undefined`, and `NaN` are falsey.
1411    *
1412    * @static
1413    * @memberOf _
1414    * @category Array
1415    * @param {Array} array The array to compact.
1416    * @returns {Array} Returns the new array of filtered values.
1417    * @example
1418    *
1419    * _.compact([0, 1, false, 2, '', 3]);
1420    * // => [1, 2, 3]
1421    */
1422   function compact(array) {
1423     return baseFilter(array, Boolean);
1424   }
1425
1426   /**
1427    * Creates a new array concatenating `array` with any additional arrays
1428    * and/or values.
1429    *
1430    * @static
1431    * @memberOf _
1432    * @category Array
1433    * @param {Array} array The array to concatenate.
1434    * @param {...*} [values] The values to concatenate.
1435    * @returns {Array} Returns the new concatenated array.
1436    * @example
1437    *
1438    * var array = [1];
1439    * var other = _.concat(array, 2, [3], [[4]]);
1440    *
1441    * console.log(other);
1442    * // => [1, 2, 3, [4]]
1443    *
1444    * console.log(array);
1445    * // => [1]
1446    */
1447   var concat = rest(function(array, values) {
1448     if (!isArray(array)) {
1449       array = array == null ? [] : [Object(array)];
1450     }
1451     values = baseFlatten(values);
1452     return arrayConcat(array, values);
1453   });
1454
1455   /**
1456    * Flattens `array` a single level.
1457    *
1458    * @static
1459    * @memberOf _
1460    * @category Array
1461    * @param {Array} array The array to flatten.
1462    * @returns {Array} Returns the new flattened array.
1463    * @example
1464    *
1465    * _.flatten([1, [2, 3, [4]]]);
1466    * // => [1, 2, 3, [4]]
1467    */
1468   function flatten(array) {
1469     var length = array ? array.length : 0;
1470     return length ? baseFlatten(array) : [];
1471   }
1472
1473   /**
1474    * This method is like `_.flatten` except that it recursively flattens `array`.
1475    *
1476    * @static
1477    * @memberOf _
1478    * @category Array
1479    * @param {Array} array The array to recursively flatten.
1480    * @returns {Array} Returns the new flattened array.
1481    * @example
1482    *
1483    * _.flattenDeep([1, [2, 3, [4]]]);
1484    * // => [1, 2, 3, 4]
1485    */
1486   function flattenDeep(array) {
1487     var length = array ? array.length : 0;
1488     return length ? baseFlatten(array, true) : [];
1489   }
1490
1491   /**
1492    * Gets the first element of `array`.
1493    *
1494    * @static
1495    * @memberOf _
1496    * @alias first
1497    * @category Array
1498    * @param {Array} array The array to query.
1499    * @returns {*} Returns the first element of `array`.
1500    * @example
1501    *
1502    * _.head([1, 2, 3]);
1503    * // => 1
1504    *
1505    * _.head([]);
1506    * // => undefined
1507    */
1508   function head(array) {
1509     return array ? array[0] : undefined;
1510   }
1511
1512   /**
1513    * Gets the index at which the first occurrence of `value` is found in `array`
1514    * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
1515    * for equality comparisons. If `fromIndex` is negative, it's used as the offset
1516    * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
1517    * performs a faster binary search.
1518    *
1519    * @static
1520    * @memberOf _
1521    * @category Array
1522    * @param {Array} array The array to search.
1523    * @param {*} value The value to search for.
1524    * @param {number} [fromIndex=0] The index to search from.
1525    * @returns {number} Returns the index of the matched value, else `-1`.
1526    * @example
1527    *
1528    * _.indexOf([1, 2, 1, 2], 2);
1529    * // => 1
1530    *
1531    * // using `fromIndex`
1532    * _.indexOf([1, 2, 1, 2], 2, 2);
1533    * // => 3
1534    */
1535   function indexOf(array, value, fromIndex) {
1536     var length = array ? array.length : 0;
1537     if (typeof fromIndex == 'number') {
1538       fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
1539     } else {
1540       fromIndex = 0;
1541     }
1542     var index = (fromIndex || 0) - 1,
1543         isReflexive = value === value;
1544
1545     while (++index < length) {
1546       var other = array[index];
1547       if ((isReflexive ? other === value : other !== other)) {
1548         return index;
1549       }
1550     }
1551     return -1;
1552   }
1553
1554   /**
1555    * Gets the last element of `array`.
1556    *
1557    * @static
1558    * @memberOf _
1559    * @category Array
1560    * @param {Array} array The array to query.
1561    * @returns {*} Returns the last element of `array`.
1562    * @example
1563    *
1564    * _.last([1, 2, 3]);
1565    * // => 3
1566    */
1567   function last(array) {
1568     var length = array ? array.length : 0;
1569     return length ? array[length - 1] : undefined;
1570   }
1571
1572   /**
1573    * Creates a slice of `array` from `start` up to, but not including, `end`.
1574    *
1575    * **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
1576    * to ensure dense arrays are returned.
1577    *
1578    * @static
1579    * @memberOf _
1580    * @category Array
1581    * @param {Array} array The array to slice.
1582    * @param {number} [start=0] The start position.
1583    * @param {number} [end=array.length] The end position.
1584    * @returns {Array} Returns the slice of `array`.
1585    */
1586   function slice(array, start, end) {
1587     var length = array ? array.length : 0;
1588     start = start == null ? 0 : +start;
1589     end = end === undefined ? length : +end;
1590     return length ? baseSlice(array, start, end) : [];
1591   }
1592
1593   /*------------------------------------------------------------------------*/
1594
1595   /**
1596    * Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
1597    * The result of such method chaining must be unwrapped with `_#value`.
1598    *
1599    * @static
1600    * @memberOf _
1601    * @category Seq
1602    * @param {*} value The value to wrap.
1603    * @returns {Object} Returns the new `lodash` wrapper instance.
1604    * @example
1605    *
1606    * var users = [
1607    *   { 'user': 'barney',  'age': 36 },
1608    *   { 'user': 'fred',    'age': 40 },
1609    *   { 'user': 'pebbles', 'age': 1 }
1610    * ];
1611    *
1612    * var youngest = _
1613    *   .chain(users)
1614    *   .sortBy('age')
1615    *   .map(function(o) {
1616    *     return o.user + ' is ' + o.age;
1617    *   })
1618    *   .head()
1619    *   .value();
1620    * // => 'pebbles is 1'
1621    */
1622   function chain(value) {
1623     var result = lodash(value);
1624     result.__chain__ = true;
1625     return result;
1626   }
1627
1628   /**
1629    * This method invokes `interceptor` and returns `value`. The interceptor is
1630    * invoked with one argument; (value). The purpose of this method is to "tap into"
1631    * a method chain in order to perform operations on intermediate results within
1632    * the chain.
1633    *
1634    * @static
1635    * @memberOf _
1636    * @category Seq
1637    * @param {*} value The value to provide to `interceptor`.
1638    * @param {Function} interceptor The function to invoke.
1639    * @returns {*} Returns `value`.
1640    * @example
1641    *
1642    * _([1, 2, 3])
1643    *  .tap(function(array) {
1644    *    array.pop();
1645    *  })
1646    *  .reverse()
1647    *  .value();
1648    * // => [2, 1]
1649    */
1650   function tap(value, interceptor) {
1651     interceptor(value);
1652     return value;
1653   }
1654
1655   /**
1656    * This method is like `_.tap` except that it returns the result of `interceptor`.
1657    *
1658    * @static
1659    * @memberOf _
1660    * @category Seq
1661    * @param {*} value The value to provide to `interceptor`.
1662    * @param {Function} interceptor The function to invoke.
1663    * @returns {*} Returns the result of `interceptor`.
1664    * @example
1665    *
1666    * _('  abc  ')
1667    *  .chain()
1668    *  .trim()
1669    *  .thru(function(value) {
1670    *    return [value];
1671    *  })
1672    *  .value();
1673    * // => ['abc']
1674    */
1675   function thru(value, interceptor) {
1676     return interceptor(value);
1677   }
1678
1679   /**
1680    * Enables explicit method chaining on the wrapper object.
1681    *
1682    * @name chain
1683    * @memberOf _
1684    * @category Seq
1685    * @returns {Object} Returns the new `lodash` wrapper instance.
1686    * @example
1687    *
1688    * var users = [
1689    *   { 'user': 'barney', 'age': 36 },
1690    *   { 'user': 'fred',   'age': 40 }
1691    * ];
1692    *
1693    * // without explicit chaining
1694    * _(users).head();
1695    * // => { 'user': 'barney', 'age': 36 }
1696    *
1697    * // with explicit chaining
1698    * _(users)
1699    *   .chain()
1700    *   .head()
1701    *   .pick('user')
1702    *   .value();
1703    * // => { 'user': 'barney' }
1704    */
1705   function wrapperChain() {
1706     return chain(this);
1707   }
1708
1709   /**
1710    * Executes the chained sequence to extract the unwrapped value.
1711    *
1712    * @name value
1713    * @memberOf _
1714    * @alias toJSON, valueOf
1715    * @category Seq
1716    * @returns {*} Returns the resolved unwrapped value.
1717    * @example
1718    *
1719    * _([1, 2, 3]).value();
1720    * // => [1, 2, 3]
1721    */
1722   function wrapperValue() {
1723     return baseWrapperValue(this.__wrapped__, this.__actions__);
1724   }
1725
1726   /*------------------------------------------------------------------------*/
1727
1728   /**
1729    * Checks if `predicate` returns truthy for **all** elements of `collection`.
1730    * Iteration is stopped once `predicate` returns falsey. The predicate is
1731    * invoked with three arguments: (value, index|key, collection).
1732    *
1733    * @static
1734    * @memberOf _
1735    * @category Collection
1736    * @param {Array|Object} collection The collection to iterate over.
1737    * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1738    * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
1739    * @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
1740    * @example
1741    *
1742    * _.every([true, 1, null, 'yes'], Boolean);
1743    * // => false
1744    *
1745    * var users = [
1746    *   { 'user': 'barney', 'active': false },
1747    *   { 'user': 'fred',   'active': false }
1748    * ];
1749    *
1750    * // using the `_.matches` iteratee shorthand
1751    * _.every(users, { 'user': 'barney', 'active': false });
1752    * // => false
1753    *
1754    * // using the `_.matchesProperty` iteratee shorthand
1755    * _.every(users, ['active', false]);
1756    * // => true
1757    *
1758    * // using the `_.property` iteratee shorthand
1759    * _.every(users, 'active');
1760    * // => false
1761    */
1762   function every(collection, predicate, guard) {
1763     predicate = guard ? undefined : predicate;
1764     return baseEvery(collection, baseIteratee(predicate));
1765   }
1766
1767   /**
1768    * Iterates over elements of `collection`, returning an array of all elements
1769    * `predicate` returns truthy for. The predicate is invoked with three arguments:
1770    * (value, index|key, collection).
1771    *
1772    * @static
1773    * @memberOf _
1774    * @category Collection
1775    * @param {Array|Object} collection The collection to iterate over.
1776    * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1777    * @returns {Array} Returns the new filtered array.
1778    * @example
1779    *
1780    * var users = [
1781    *   { 'user': 'barney', 'age': 36, 'active': true },
1782    *   { 'user': 'fred',   'age': 40, 'active': false }
1783    * ];
1784    *
1785    * _.filter(users, function(o) { return !o.active; });
1786    * // => objects for ['fred']
1787    *
1788    * // using the `_.matches` iteratee shorthand
1789    * _.filter(users, { 'age': 36, 'active': true });
1790    * // => objects for ['barney']
1791    *
1792    * // using the `_.matchesProperty` iteratee shorthand
1793    * _.filter(users, ['active', false]);
1794    * // => objects for ['fred']
1795    *
1796    * // using the `_.property` iteratee shorthand
1797    * _.filter(users, 'active');
1798    * // => objects for ['barney']
1799    */
1800   function filter(collection, predicate) {
1801     return baseFilter(collection, baseIteratee(predicate));
1802   }
1803
1804   /**
1805    * Iterates over elements of `collection`, returning the first element
1806    * `predicate` returns truthy for. The predicate is invoked with three arguments:
1807    * (value, index|key, collection).
1808    *
1809    * @static
1810    * @memberOf _
1811    * @category Collection
1812    * @param {Array|Object} collection The collection to search.
1813    * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
1814    * @returns {*} Returns the matched element, else `undefined`.
1815    * @example
1816    *
1817    * var users = [
1818    *   { 'user': 'barney',  'age': 36, 'active': true },
1819    *   { 'user': 'fred',    'age': 40, 'active': false },
1820    *   { 'user': 'pebbles', 'age': 1,  'active': true }
1821    * ];
1822    *
1823    * _.find(users, function(o) { return o.age < 40; });
1824    * // => object for 'barney'
1825    *
1826    * // using the `_.matches` iteratee shorthand
1827    * _.find(users, { 'age': 1, 'active': true });
1828    * // => object for 'pebbles'
1829    *
1830    * // using the `_.matchesProperty` iteratee shorthand
1831    * _.find(users, ['active', false]);
1832    * // => object for 'fred'
1833    *
1834    * // using the `_.property` iteratee shorthand
1835    * _.find(users, 'active');
1836    * // => object for 'barney'
1837    */
1838   function find(collection, predicate) {
1839     return baseFind(collection, baseIteratee(predicate), baseEach);
1840   }
1841
1842   /**
1843    * Iterates over elements of `collection` invoking `iteratee` for each element.
1844    * The iteratee is invoked with three arguments: (value, index|key, collection).
1845    * Iteratee functions may exit iteration early by explicitly returning `false`.
1846    *
1847    * **Note:** As with other "Collections" methods, objects with a "length" property
1848    * are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
1849    * for object iteration.
1850    *
1851    * @static
1852    * @memberOf _
1853    * @alias each
1854    * @category Collection
1855    * @param {Array|Object} collection The collection to iterate over.
1856    * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1857    * @returns {Array|Object} Returns `collection`.
1858    * @example
1859    *
1860    * _([1, 2]).forEach(function(value) {
1861    *   console.log(value);
1862    * });
1863    * // => logs `1` then `2`
1864    *
1865    * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
1866    *   console.log(key);
1867    * });
1868    * // => logs 'a' then 'b' (iteration order is not guaranteed)
1869    */
1870   function forEach(collection, iteratee) {
1871     return baseEach(collection, toFunction(iteratee));
1872   }
1873
1874   /**
1875    * Invokes the method at `path` of each element in `collection`, returning
1876    * an array of the results of each invoked method. Any additional arguments
1877    * are provided to each invoked method. If `methodName` is a function it's
1878    * invoked for, and `this` bound to, each element in `collection`.
1879    *
1880    * @static
1881    * @memberOf _
1882    * @category Collection
1883    * @param {Array|Object} collection The collection to iterate over.
1884    * @param {Array|Function|string} path The path of the method to invoke or
1885    *  the function invoked per iteration.
1886    * @param {...*} [args] The arguments to invoke each method with.
1887    * @returns {Array} Returns the array of results.
1888    * @example
1889    *
1890    * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
1891    * // => [[1, 5, 7], [1, 2, 3]]
1892    *
1893    * _.invokeMap([123, 456], String.prototype.split, '');
1894    * // => [['1', '2', '3'], ['4', '5', '6']]
1895    */
1896   var invokeMap = rest(function(collection, path, args) {
1897     var isFunc = typeof path == 'function';
1898     return baseMap(collection, function(value) {
1899       var func = isFunc ? path : value[path];
1900       return func == null ? func : func.apply(value, args);
1901     });
1902   });
1903
1904   /**
1905    * Creates an array of values by running each element in `collection` through
1906    * `iteratee`. The iteratee is invoked with three arguments:
1907    * (value, index|key, collection).
1908    *
1909    * Many lodash methods are guarded to work as iteratees for methods like
1910    * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
1911    *
1912    * The guarded methods are:
1913    * `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
1914    * `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
1915    * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
1916    * and `words`
1917    *
1918    * @static
1919    * @memberOf _
1920    * @category Collection
1921    * @param {Array|Object} collection The collection to iterate over.
1922    * @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
1923    * @returns {Array} Returns the new mapped array.
1924    * @example
1925    *
1926    * function square(n) {
1927    *   return n * n;
1928    * }
1929    *
1930    * _.map([4, 8], square);
1931    * // => [16, 64]
1932    *
1933    * _.map({ 'a': 4, 'b': 8 }, square);
1934    * // => [16, 64] (iteration order is not guaranteed)
1935    *
1936    * var users = [
1937    *   { 'user': 'barney' },
1938    *   { 'user': 'fred' }
1939    * ];
1940    *
1941    * // using the `_.property` iteratee shorthand
1942    * _.map(users, 'user');
1943    * // => ['barney', 'fred']
1944    */
1945   function map(collection, iteratee) {
1946     return baseMap(collection, baseIteratee(iteratee));
1947   }
1948
1949   /**
1950    * Reduces `collection` to a value which is the accumulated result of running
1951    * each element in `collection` through `iteratee`, where each successive
1952    * invocation is supplied the return value of the previous. If `accumulator`
1953    * is not provided the first element of `collection` is used as the initial
1954    * value. The iteratee is invoked with four arguments:
1955    * (accumulator, value, index|key, collection).
1956    *
1957    * Many lodash methods are guarded to work as iteratees for methods like
1958    * `_.reduce`, `_.reduceRight`, and `_.transform`.
1959    *
1960    * The guarded methods are:
1961    * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
1962    * and `sortBy`
1963    *
1964    * @static
1965    * @memberOf _
1966    * @category Collection
1967    * @param {Array|Object} collection The collection to iterate over.
1968    * @param {Function} [iteratee=_.identity] The function invoked per iteration.
1969    * @param {*} [accumulator] The initial value.
1970    * @returns {*} Returns the accumulated value.
1971    * @example
1972    *
1973    * _.reduce([1, 2], function(sum, n) {
1974    *   return sum + n;
1975    * });
1976    * // => 3
1977    *
1978    * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
1979    *   (result[value] || (result[value] = [])).push(key);
1980    *   return result;
1981    * }, {});
1982    * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
1983    */
1984   function reduce(collection, iteratee, accumulator) {
1985     return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
1986   }
1987
1988   /**
1989    * Gets the size of `collection` by returning its length for array-like
1990    * values or the number of own enumerable properties for objects.
1991    *
1992    * @static
1993    * @memberOf _
1994    * @category Collection
1995    * @param {Array|Object} collection The collection to inspect.
1996    * @returns {number} Returns the collection size.
1997    * @example
1998    *
1999    * _.size([1, 2, 3]);
2000    * // => 3
2001    *
2002    * _.size({ 'a': 1, 'b': 2 });
2003    * // => 2
2004    *
2005    * _.size('pebbles');
2006    * // => 7
2007    */
2008   function size(collection) {
2009     if (collection == null) {
2010       return 0;
2011     }
2012     collection = isArrayLike(collection) ? collection : keys(collection);
2013     return collection.length;
2014   }
2015
2016   /**
2017    * Checks if `predicate` returns truthy for **any** element of `collection`.
2018    * Iteration is stopped once `predicate` returns truthy. The predicate is
2019    * invoked with three arguments: (value, index|key, collection).
2020    *
2021    * @static
2022    * @memberOf _
2023    * @category Collection
2024    * @param {Array|Object} collection The collection to iterate over.
2025    * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
2026    * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
2027    * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
2028    * @example
2029    *
2030    * _.some([null, 0, 'yes', false], Boolean);
2031    * // => true
2032    *
2033    * var users = [
2034    *   { 'user': 'barney', 'active': true },
2035    *   { 'user': 'fred',   'active': false }
2036    * ];
2037    *
2038    * // using the `_.matches` iteratee shorthand
2039    * _.some(users, { 'user': 'barney', 'active': false });
2040    * // => false
2041    *
2042    * // using the `_.matchesProperty` iteratee shorthand
2043    * _.some(users, ['active', false]);
2044    * // => true
2045    *
2046    * // using the `_.property` iteratee shorthand
2047    * _.some(users, 'active');
2048    * // => true
2049    */
2050   function some(collection, predicate, guard) {
2051     predicate = guard ? undefined : predicate;
2052     return baseSome(collection, baseIteratee(predicate));
2053   }
2054
2055   /**
2056    * Creates an array of elements, sorted in ascending order by the results of
2057    * running each element in a collection through each iteratee. This method
2058    * performs a stable sort, that is, it preserves the original sort order of
2059    * equal elements. The iteratees are invoked with one argument: (value).
2060    *
2061    * @static
2062    * @memberOf _
2063    * @category Collection
2064    * @param {Array|Object} collection The collection to iterate over.
2065    * @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
2066    *  The iteratees to sort by, specified individually or in arrays.
2067    * @returns {Array} Returns the new sorted array.
2068    * @example
2069    *
2070    * var users = [
2071    *   { 'user': 'fred',   'age': 48 },
2072    *   { 'user': 'barney', 'age': 36 },
2073    *   { 'user': 'fred',   'age': 42 },
2074    *   { 'user': 'barney', 'age': 34 }
2075    * ];
2076    *
2077    * _.sortBy(users, function(o) { return o.user; });
2078    * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2079    *
2080    * _.sortBy(users, ['user', 'age']);
2081    * // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
2082    *
2083    * _.sortBy(users, 'user', function(o) {
2084    *   return Math.floor(o.age / 10);
2085    * });
2086    * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
2087    */
2088   function sortBy(collection, iteratee) {
2089     var index = 0;
2090     iteratee = baseIteratee(iteratee);
2091
2092     return baseMap(baseMap(collection, function(value, key, collection) {
2093       return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
2094     }).sort(function(object, other) {
2095       return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
2096     }), baseProperty('value'));
2097   }
2098
2099   /*------------------------------------------------------------------------*/
2100
2101   /**
2102    * Gets the timestamp of the number of milliseconds that have elapsed since
2103    * the Unix epoch (1 January 1970 00:00:00 UTC).
2104    *
2105    * @static
2106    * @memberOf _
2107    * @type Function
2108    * @category Date
2109    * @returns {number} Returns the timestamp.
2110    * @example
2111    *
2112    * _.defer(function(stamp) {
2113    *   console.log(_.now() - stamp);
2114    * }, _.now());
2115    * // => logs the number of milliseconds it took for the deferred function to be invoked
2116    */
2117   var now = Date.now;
2118
2119   /*------------------------------------------------------------------------*/
2120
2121   /**
2122    * Creates a function that invokes `func`, with the `this` binding and arguments
2123    * of the created function, while it's called less than `n` times. Subsequent
2124    * calls to the created function return the result of the last `func` invocation.
2125    *
2126    * @static
2127    * @memberOf _
2128    * @category Function
2129    * @param {number} n The number of calls at which `func` is no longer invoked.
2130    * @param {Function} func The function to restrict.
2131    * @returns {Function} Returns the new restricted function.
2132    * @example
2133    *
2134    * jQuery(element).on('click', _.before(5, addContactToList));
2135    * // => allows adding up to 4 contacts to the list
2136    */
2137   function before(n, func) {
2138     var result;
2139     if (typeof func != 'function') {
2140       throw new TypeError(FUNC_ERROR_TEXT);
2141     }
2142     n = toInteger(n);
2143     return function() {
2144       if (--n > 0) {
2145         result = func.apply(this, arguments);
2146       }
2147       if (n <= 1) {
2148         func = undefined;
2149       }
2150       return result;
2151     };
2152   }
2153
2154   /**
2155    * Creates a function that invokes `func` with the `this` binding of `thisArg`
2156    * and prepends any additional `_.bind` arguments to those provided to the
2157    * bound function.
2158    *
2159    * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
2160    * may be used as a placeholder for partially applied arguments.
2161    *
2162    * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
2163    * property of bound functions.
2164    *
2165    * @static
2166    * @memberOf _
2167    * @category Function
2168    * @param {Function} func The function to bind.
2169    * @param {*} thisArg The `this` binding of `func`.
2170    * @param {...*} [partials] The arguments to be partially applied.
2171    * @returns {Function} Returns the new bound function.
2172    * @example
2173    *
2174    * var greet = function(greeting, punctuation) {
2175    *   return greeting + ' ' + this.user + punctuation;
2176    * };
2177    *
2178    * var object = { 'user': 'fred' };
2179    *
2180    * var bound = _.bind(greet, object, 'hi');
2181    * bound('!');
2182    * // => 'hi fred!'
2183    *
2184    * // using placeholders
2185    * var bound = _.bind(greet, object, _, '!');
2186    * bound('hi');
2187    * // => 'hi fred!'
2188    */
2189   var bind = rest(function(func, thisArg, partials) {
2190     return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
2191   });
2192
2193   /**
2194    * Defers invoking the `func` until the current call stack has cleared. Any
2195    * additional arguments are provided to `func` when it's invoked.
2196    *
2197    * @static
2198    * @memberOf _
2199    * @category Function
2200    * @param {Function} func The function to defer.
2201    * @param {...*} [args] The arguments to invoke `func` with.
2202    * @returns {number} Returns the timer id.
2203    * @example
2204    *
2205    * _.defer(function(text) {
2206    *   console.log(text);
2207    * }, 'deferred');
2208    * // logs 'deferred' after one or more milliseconds
2209    */
2210   var defer = rest(function(func, args) {
2211     return baseDelay(func, 1, args);
2212   });
2213
2214   /**
2215    * Invokes `func` after `wait` milliseconds. Any additional arguments are
2216    * provided to `func` when it's invoked.
2217    *
2218    * @static
2219    * @memberOf _
2220    * @category Function
2221    * @param {Function} func The function to delay.
2222    * @param {number} wait The number of milliseconds to delay invocation.
2223    * @param {...*} [args] The arguments to invoke `func` with.
2224    * @returns {number} Returns the timer id.
2225    * @example
2226    *
2227    * _.delay(function(text) {
2228    *   console.log(text);
2229    * }, 1000, 'later');
2230    * // => logs 'later' after one second
2231    */
2232   var delay = rest(function(func, wait, args) {
2233     return baseDelay(func, toNumber(wait) || 0, args);
2234   });
2235
2236   /**
2237    * Creates a function that negates the result of the predicate `func`. The
2238    * `func` predicate is invoked with the `this` binding and arguments of the
2239    * created function.
2240    *
2241    * @static
2242    * @memberOf _
2243    * @category Function
2244    * @param {Function} predicate The predicate to negate.
2245    * @returns {Function} Returns the new function.
2246    * @example
2247    *
2248    * function isEven(n) {
2249    *   return n % 2 == 0;
2250    * }
2251    *
2252    * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
2253    * // => [1, 3, 5]
2254    */
2255   function negate(predicate) {
2256     if (typeof predicate != 'function') {
2257       throw new TypeError(FUNC_ERROR_TEXT);
2258     }
2259     return function() {
2260       return !predicate.apply(this, arguments);
2261     };
2262   }
2263
2264   /**
2265    * Creates a function that is restricted to invoking `func` once. Repeat calls
2266    * to the function return the value of the first invocation. The `func` is
2267    * invoked with the `this` binding and arguments of the created function.
2268    *
2269    * @static
2270    * @memberOf _
2271    * @category Function
2272    * @param {Function} func The function to restrict.
2273    * @returns {Function} Returns the new restricted function.
2274    * @example
2275    *
2276    * var initialize = _.once(createApplication);
2277    * initialize();
2278    * initialize();
2279    * // `initialize` invokes `createApplication` once
2280    */
2281   function once(func) {
2282     return before(2, func);
2283   }
2284
2285   /**
2286    * Creates a function that invokes `func` with the `this` binding of the
2287    * created function and arguments from `start` and beyond provided as an array.
2288    *
2289    * **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
2290    *
2291    * @static
2292    * @memberOf _
2293    * @category Function
2294    * @param {Function} func The function to apply a rest parameter to.
2295    * @param {number} [start=func.length-1] The start position of the rest parameter.
2296    * @returns {Function} Returns the new function.
2297    * @example
2298    *
2299    * var say = _.rest(function(what, names) {
2300    *   return what + ' ' + _.initial(names).join(', ') +
2301    *     (_.size(names) > 1 ? ', & ' : '') + _.last(names);
2302    * });
2303    *
2304    * say('hello', 'fred', 'barney', 'pebbles');
2305    * // => 'hello fred, barney, & pebbles'
2306    */
2307   function rest(func, start) {
2308     if (typeof func != 'function') {
2309       throw new TypeError(FUNC_ERROR_TEXT);
2310     }
2311     start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
2312     return function() {
2313       var args = arguments,
2314           index = -1,
2315           length = nativeMax(args.length - start, 0),
2316           array = Array(length);
2317
2318       while (++index < length) {
2319         array[index] = args[start + index];
2320       }
2321       var otherArgs = Array(start + 1);
2322       index = -1;
2323       while (++index < start) {
2324         otherArgs[index] = args[index];
2325       }
2326       otherArgs[start] = array;
2327       return func.apply(this, otherArgs);
2328     };
2329   }
2330
2331   /*------------------------------------------------------------------------*/
2332
2333   /**
2334    * Creates a shallow clone of `value`.
2335    *
2336    * **Note:** This method is loosely based on the
2337    * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
2338    * and supports cloning arrays, array buffers, booleans, date objects, maps,
2339    * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
2340    * arrays. The own enumerable properties of `arguments` objects are cloned
2341    * as plain objects. An empty object is returned for uncloneable values such
2342    * as error objects, functions, DOM nodes, and WeakMaps.
2343    *
2344    * @static
2345    * @memberOf _
2346    * @category Lang
2347    * @param {*} value The value to clone.
2348    * @returns {*} Returns the cloned value.
2349    * @example
2350    *
2351    * var objects = [{ 'a': 1 }, { 'b': 2 }];
2352    *
2353    * var shallow = _.clone(objects);
2354    * console.log(shallow[0] === objects[0]);
2355    * // => true
2356    */
2357   function clone(value) {
2358     if (!isObject(value)) {
2359       return value;
2360     }
2361     return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
2362   }
2363
2364   /**
2365    * Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2366    * comparison between two values to determine if they are equivalent.
2367    *
2368    * @static
2369    * @memberOf _
2370    * @category Lang
2371    * @param {*} value The value to compare.
2372    * @param {*} other The other value to compare.
2373    * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2374    * @example
2375    *
2376    * var object = { 'user': 'fred' };
2377    * var other = { 'user': 'fred' };
2378    *
2379    * _.eq(object, object);
2380    * // => true
2381    *
2382    * _.eq(object, other);
2383    * // => false
2384    *
2385    * _.eq('a', 'a');
2386    * // => true
2387    *
2388    * _.eq('a', Object('a'));
2389    * // => false
2390    *
2391    * _.eq(NaN, NaN);
2392    * // => true
2393    */
2394   function eq(value, other) {
2395     return value === other || (value !== value && other !== other);
2396   }
2397
2398   /**
2399    * Checks if `value` is greater than `other`.
2400    *
2401    * @static
2402    * @memberOf _
2403    * @category Lang
2404    * @param {*} value The value to compare.
2405    * @param {*} other The other value to compare.
2406    * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
2407    * @example
2408    *
2409    * _.gt(3, 1);
2410    * // => true
2411    *
2412    * _.gt(3, 3);
2413    * // => false
2414    *
2415    * _.gt(1, 3);
2416    * // => false
2417    */
2418   function gt(value, other) {
2419     return value > other;
2420   }
2421
2422   /**
2423    * Checks if `value` is likely an `arguments` object.
2424    *
2425    * @static
2426    * @memberOf _
2427    * @category Lang
2428    * @param {*} value The value to check.
2429    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2430    * @example
2431    *
2432    * _.isArguments(function() { return arguments; }());
2433    * // => true
2434    *
2435    * _.isArguments([1, 2, 3]);
2436    * // => false
2437    */
2438   function isArguments(value) {
2439     // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
2440     return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
2441       (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
2442   }
2443
2444   /**
2445    * Checks if `value` is classified as an `Array` object.
2446    *
2447    * @static
2448    * @memberOf _
2449    * @type Function
2450    * @category Lang
2451    * @param {*} value The value to check.
2452    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2453    * @example
2454    *
2455    * _.isArray([1, 2, 3]);
2456    * // => true
2457    *
2458    * _.isArray(document.body.children);
2459    * // => false
2460    *
2461    * _.isArray('abc');
2462    * // => false
2463    *
2464    * _.isArray(_.noop);
2465    * // => false
2466    */
2467   var isArray = Array.isArray;
2468
2469   /**
2470    * Checks if `value` is array-like. A value is considered array-like if it's
2471    * not a function and has a `value.length` that's an integer greater than or
2472    * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
2473    *
2474    * @static
2475    * @memberOf _
2476    * @type Function
2477    * @category Lang
2478    * @param {*} value The value to check.
2479    * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
2480    * @example
2481    *
2482    * _.isArrayLike([1, 2, 3]);
2483    * // => true
2484    *
2485    * _.isArrayLike(document.body.children);
2486    * // => true
2487    *
2488    * _.isArrayLike('abc');
2489    * // => true
2490    *
2491    * _.isArrayLike(_.noop);
2492    * // => false
2493    */
2494   function isArrayLike(value) {
2495     return value != null &&
2496       !(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
2497   }
2498
2499   /**
2500    * This method is like `_.isArrayLike` except that it also checks if `value`
2501    * is an object.
2502    *
2503    * @static
2504    * @memberOf _
2505    * @type Function
2506    * @category Lang
2507    * @param {*} value The value to check.
2508    * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
2509    * @example
2510    *
2511    * _.isArrayLikeObject([1, 2, 3]);
2512    * // => true
2513    *
2514    * _.isArrayLikeObject(document.body.children);
2515    * // => true
2516    *
2517    * _.isArrayLikeObject('abc');
2518    * // => false
2519    *
2520    * _.isArrayLikeObject(_.noop);
2521    * // => false
2522    */
2523   function isArrayLikeObject(value) {
2524     return isObjectLike(value) && isArrayLike(value);
2525   }
2526
2527   /**
2528    * Checks if `value` is classified as a boolean primitive or object.
2529    *
2530    * @static
2531    * @memberOf _
2532    * @category Lang
2533    * @param {*} value The value to check.
2534    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2535    * @example
2536    *
2537    * _.isBoolean(false);
2538    * // => true
2539    *
2540    * _.isBoolean(null);
2541    * // => false
2542    */
2543   function isBoolean(value) {
2544     return value === true || value === false ||
2545       (isObjectLike(value) && objectToString.call(value) == boolTag);
2546   }
2547
2548   /**
2549    * Checks if `value` is classified as a `Date` object.
2550    *
2551    * @static
2552    * @memberOf _
2553    * @category Lang
2554    * @param {*} value The value to check.
2555    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2556    * @example
2557    *
2558    * _.isDate(new Date);
2559    * // => true
2560    *
2561    * _.isDate('Mon April 23 2012');
2562    * // => false
2563    */
2564   function isDate(value) {
2565     return isObjectLike(value) && objectToString.call(value) == dateTag;
2566   }
2567
2568   /**
2569    * Checks if `value` is empty. A value is considered empty unless it's an
2570    * `arguments` object, array, string, or jQuery-like collection with a length
2571    * greater than `0` or an object with own enumerable properties.
2572    *
2573    * @static
2574    * @memberOf _
2575    * @category Lang
2576    * @param {Array|Object|string} value The value to inspect.
2577    * @returns {boolean} Returns `true` if `value` is empty, else `false`.
2578    * @example
2579    *
2580    * _.isEmpty(null);
2581    * // => true
2582    *
2583    * _.isEmpty(true);
2584    * // => true
2585    *
2586    * _.isEmpty(1);
2587    * // => true
2588    *
2589    * _.isEmpty([1, 2, 3]);
2590    * // => false
2591    *
2592    * _.isEmpty({ 'a': 1 });
2593    * // => false
2594    */
2595   function isEmpty(value) {
2596     return (!isObjectLike(value) || isFunction(value.splice))
2597       ? !size(value)
2598       : !keys(value).length;
2599   }
2600
2601   /**
2602    * Performs a deep comparison between two values to determine if they are
2603    * equivalent.
2604    *
2605    * **Note:** This method supports comparing arrays, array buffers, booleans,
2606    * date objects, error objects, maps, numbers, `Object` objects, regexes,
2607    * sets, strings, symbols, and typed arrays. `Object` objects are compared
2608    * by their own, not inherited, enumerable properties. Functions and DOM
2609    * nodes are **not** supported.
2610    *
2611    * @static
2612    * @memberOf _
2613    * @category Lang
2614    * @param {*} value The value to compare.
2615    * @param {*} other The other value to compare.
2616    * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2617    * @example
2618    *
2619    * var object = { 'user': 'fred' };
2620    * var other = { 'user': 'fred' };
2621    *
2622    * _.isEqual(object, other);
2623    * // => true
2624    *
2625    * object === other;
2626    * // => false
2627    */
2628   function isEqual(value, other) {
2629     return baseIsEqual(value, other);
2630   }
2631
2632   /**
2633    * Checks if `value` is a finite primitive number.
2634    *
2635    * **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
2636    *
2637    * @static
2638    * @memberOf _
2639    * @category Lang
2640    * @param {*} value The value to check.
2641    * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
2642    * @example
2643    *
2644    * _.isFinite(3);
2645    * // => true
2646    *
2647    * _.isFinite(Number.MAX_VALUE);
2648    * // => true
2649    *
2650    * _.isFinite(3.14);
2651    * // => true
2652    *
2653    * _.isFinite(Infinity);
2654    * // => false
2655    */
2656   function isFinite(value) {
2657     return typeof value == 'number' && nativeIsFinite(value);
2658   }
2659
2660   /**
2661    * Checks if `value` is classified as a `Function` object.
2662    *
2663    * @static
2664    * @memberOf _
2665    * @category Lang
2666    * @param {*} value The value to check.
2667    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2668    * @example
2669    *
2670    * _.isFunction(_);
2671    * // => true
2672    *
2673    * _.isFunction(/abc/);
2674    * // => false
2675    */
2676   function isFunction(value) {
2677     // The use of `Object#toString` avoids issues with the `typeof` operator
2678     // in Safari 8 which returns 'object' for typed array constructors, and
2679     // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
2680     var tag = isObject(value) ? objectToString.call(value) : '';
2681     return tag == funcTag || tag == genTag;
2682   }
2683
2684   /**
2685    * Checks if `value` is a valid array-like length.
2686    *
2687    * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
2688    *
2689    * @static
2690    * @memberOf _
2691    * @category Lang
2692    * @param {*} value The value to check.
2693    * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
2694    * @example
2695    *
2696    * _.isLength(3);
2697    * // => true
2698    *
2699    * _.isLength(Number.MIN_VALUE);
2700    * // => false
2701    *
2702    * _.isLength(Infinity);
2703    * // => false
2704    *
2705    * _.isLength('3');
2706    * // => false
2707    */
2708   function isLength(value) {
2709     return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
2710   }
2711
2712   /**
2713    * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
2714    * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
2715    *
2716    * @static
2717    * @memberOf _
2718    * @category Lang
2719    * @param {*} value The value to check.
2720    * @returns {boolean} Returns `true` if `value` is an object, else `false`.
2721    * @example
2722    *
2723    * _.isObject({});
2724    * // => true
2725    *
2726    * _.isObject([1, 2, 3]);
2727    * // => true
2728    *
2729    * _.isObject(_.noop);
2730    * // => true
2731    *
2732    * _.isObject(null);
2733    * // => false
2734    */
2735   function isObject(value) {
2736     // Avoid a V8 JIT bug in Chrome 19-20.
2737     // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
2738     var type = typeof value;
2739     return !!value && (type == 'object' || type == 'function');
2740   }
2741
2742   /**
2743    * Checks if `value` is object-like. A value is object-like if it's not `null`
2744    * and has a `typeof` result of "object".
2745    *
2746    * @static
2747    * @memberOf _
2748    * @category Lang
2749    * @param {*} value The value to check.
2750    * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
2751    * @example
2752    *
2753    * _.isObjectLike({});
2754    * // => true
2755    *
2756    * _.isObjectLike([1, 2, 3]);
2757    * // => true
2758    *
2759    * _.isObjectLike(_.noop);
2760    * // => false
2761    *
2762    * _.isObjectLike(null);
2763    * // => false
2764    */
2765   function isObjectLike(value) {
2766     return !!value && typeof value == 'object';
2767   }
2768
2769   /**
2770    * Checks if `value` is `NaN`.
2771    *
2772    * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
2773    * which returns `true` for `undefined` and other non-numeric values.
2774    *
2775    * @static
2776    * @memberOf _
2777    * @category Lang
2778    * @param {*} value The value to check.
2779    * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
2780    * @example
2781    *
2782    * _.isNaN(NaN);
2783    * // => true
2784    *
2785    * _.isNaN(new Number(NaN));
2786    * // => true
2787    *
2788    * isNaN(undefined);
2789    * // => true
2790    *
2791    * _.isNaN(undefined);
2792    * // => false
2793    */
2794   function isNaN(value) {
2795     // An `NaN` primitive is the only value that is not equal to itself.
2796     // Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
2797     return isNumber(value) && value != +value;
2798   }
2799
2800   /**
2801    * Checks if `value` is `null`.
2802    *
2803    * @static
2804    * @memberOf _
2805    * @category Lang
2806    * @param {*} value The value to check.
2807    * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
2808    * @example
2809    *
2810    * _.isNull(null);
2811    * // => true
2812    *
2813    * _.isNull(void 0);
2814    * // => false
2815    */
2816   function isNull(value) {
2817     return value === null;
2818   }
2819
2820   /**
2821    * Checks if `value` is classified as a `Number` primitive or object.
2822    *
2823    * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
2824    * as numbers, use the `_.isFinite` method.
2825    *
2826    * @static
2827    * @memberOf _
2828    * @category Lang
2829    * @param {*} value The value to check.
2830    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2831    * @example
2832    *
2833    * _.isNumber(3);
2834    * // => true
2835    *
2836    * _.isNumber(Number.MIN_VALUE);
2837    * // => true
2838    *
2839    * _.isNumber(Infinity);
2840    * // => true
2841    *
2842    * _.isNumber('3');
2843    * // => false
2844    */
2845   function isNumber(value) {
2846     return typeof value == 'number' ||
2847       (isObjectLike(value) && objectToString.call(value) == numberTag);
2848   }
2849
2850   /**
2851    * Checks if `value` is classified as a `RegExp` object.
2852    *
2853    * @static
2854    * @memberOf _
2855    * @category Lang
2856    * @param {*} value The value to check.
2857    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2858    * @example
2859    *
2860    * _.isRegExp(/abc/);
2861    * // => true
2862    *
2863    * _.isRegExp('/abc/');
2864    * // => false
2865    */
2866   function isRegExp(value) {
2867     return isObject(value) && objectToString.call(value) == regexpTag;
2868   }
2869
2870   /**
2871    * Checks if `value` is classified as a `String` primitive or object.
2872    *
2873    * @static
2874    * @memberOf _
2875    * @category Lang
2876    * @param {*} value The value to check.
2877    * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
2878    * @example
2879    *
2880    * _.isString('abc');
2881    * // => true
2882    *
2883    * _.isString(1);
2884    * // => false
2885    */
2886   function isString(value) {
2887     return typeof value == 'string' ||
2888       (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
2889   }
2890
2891   /**
2892    * Checks if `value` is `undefined`.
2893    *
2894    * @static
2895    * @memberOf _
2896    * @category Lang
2897    * @param {*} value The value to check.
2898    * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
2899    * @example
2900    *
2901    * _.isUndefined(void 0);
2902    * // => true
2903    *
2904    * _.isUndefined(null);
2905    * // => false
2906    */
2907   function isUndefined(value) {
2908     return value === undefined;
2909   }
2910
2911   /**
2912    * Checks if `value` is less than `other`.
2913    *
2914    * @static
2915    * @memberOf _
2916    * @category Lang
2917    * @param {*} value The value to compare.
2918    * @param {*} other The other value to compare.
2919    * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
2920    * @example
2921    *
2922    * _.lt(1, 3);
2923    * // => true
2924    *
2925    * _.lt(3, 3);
2926    * // => false
2927    *
2928    * _.lt(3, 1);
2929    * // => false
2930    */
2931   function lt(value, other) {
2932     return value < other;
2933   }
2934
2935   /**
2936    * Converts `value` to an array.
2937    *
2938    * @static
2939    * @memberOf _
2940    * @category Lang
2941    * @param {*} value The value to convert.
2942    * @returns {Array} Returns the converted array.
2943    * @example
2944    *
2945    * _.toArray({ 'a': 1, 'b': 2 });
2946    * // => [1, 2]
2947    *
2948    * _.toArray('abc');
2949    * // => ['a', 'b', 'c']
2950    *
2951    * _.toArray(1);
2952    * // => []
2953    *
2954    * _.toArray(null);
2955    * // => []
2956    */
2957   function toArray(value) {
2958     if (!isArrayLike(value)) {
2959       return values(value);
2960     }
2961     return value.length ? copyArray(value) : [];
2962   }
2963
2964   /**
2965    * Converts `value` to an integer.
2966    *
2967    * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
2968    *
2969    * @static
2970    * @memberOf _
2971    * @category Lang
2972    * @param {*} value The value to convert.
2973    * @returns {number} Returns the converted integer.
2974    * @example
2975    *
2976    * _.toInteger(3);
2977    * // => 3
2978    *
2979    * _.toInteger(Number.MIN_VALUE);
2980    * // => 0
2981    *
2982    * _.toInteger(Infinity);
2983    * // => 1.7976931348623157e+308
2984    *
2985    * _.toInteger('3');
2986    * // => 3
2987    */
2988   var toInteger = Number;
2989
2990   /**
2991    * Converts `value` to a number.
2992    *
2993    * @static
2994    * @memberOf _
2995    * @category Lang
2996    * @param {*} value The value to process.
2997    * @returns {number} Returns the number.
2998    * @example
2999    *
3000    * _.toNumber(3);
3001    * // => 3
3002    *
3003    * _.toNumber(Number.MIN_VALUE);
3004    * // => 5e-324
3005    *
3006    * _.toNumber(Infinity);
3007    * // => Infinity
3008    *
3009    * _.toNumber('3');
3010    * // => 3
3011    */
3012   var toNumber = Number;
3013
3014   /**
3015    * Converts `value` to a string if it's not one. An empty string is returned
3016    * for `null` and `undefined` values. The sign of `-0` is preserved.
3017    *
3018    * @static
3019    * @memberOf _
3020    * @category Lang
3021    * @param {*} value The value to process.
3022    * @returns {string} Returns the string.
3023    * @example
3024    *
3025    * _.toString(null);
3026    * // => ''
3027    *
3028    * _.toString(-0);
3029    * // => '-0'
3030    *
3031    * _.toString([1, 2, 3]);
3032    * // => '1,2,3'
3033    */
3034   function toString(value) {
3035     if (typeof value == 'string') {
3036       return value;
3037     }
3038     return value == null ? '' : (value + '');
3039   }
3040
3041   /*------------------------------------------------------------------------*/
3042
3043   /**
3044    * Assigns own enumerable properties of source objects to the destination
3045    * object. Source objects are applied from left to right. Subsequent sources
3046    * overwrite property assignments of previous sources.
3047    *
3048    * **Note:** This method mutates `object` and is loosely based on
3049    * [`Object.assign`](https://mdn.io/Object/assign).
3050    *
3051    * @static
3052    * @memberOf _
3053    * @category Object
3054    * @param {Object} object The destination object.
3055    * @param {...Object} [sources] The source objects.
3056    * @returns {Object} Returns `object`.
3057    * @example
3058    *
3059    * function Foo() {
3060    *   this.c = 3;
3061    * }
3062    *
3063    * function Bar() {
3064    *   this.e = 5;
3065    * }
3066    *
3067    * Foo.prototype.d = 4;
3068    * Bar.prototype.f = 6;
3069    *
3070    * _.assign({ 'a': 1 }, new Foo, new Bar);
3071    * // => { 'a': 1, 'c': 3, 'e': 5 }
3072    */
3073   var assign = createAssigner(function(object, source) {
3074     copyObject(source, keys(source), object);
3075   });
3076
3077   /**
3078    * This method is like `_.assign` except that it iterates over own and
3079    * inherited source properties.
3080    *
3081    * **Note:** This method mutates `object`.
3082    *
3083    * @static
3084    * @memberOf _
3085    * @alias extend
3086    * @category Object
3087    * @param {Object} object The destination object.
3088    * @param {...Object} [sources] The source objects.
3089    * @returns {Object} Returns `object`.
3090    * @example
3091    *
3092    * function Foo() {
3093    *   this.b = 2;
3094    * }
3095    *
3096    * function Bar() {
3097    *   this.d = 4;
3098    * }
3099    *
3100    * Foo.prototype.c = 3;
3101    * Bar.prototype.e = 5;
3102    *
3103    * _.assignIn({ 'a': 1 }, new Foo, new Bar);
3104    * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
3105    */
3106   var assignIn = createAssigner(function(object, source) {
3107     copyObject(source, keysIn(source), object);
3108   });
3109
3110   /**
3111    * This method is like `_.assignIn` except that it accepts `customizer` which
3112    * is invoked to produce the assigned values. If `customizer` returns `undefined`
3113    * assignment is handled by the method instead. The `customizer` is invoked
3114    * with five arguments: (objValue, srcValue, key, object, source).
3115    *
3116    * **Note:** This method mutates `object`.
3117    *
3118    * @static
3119    * @memberOf _
3120    * @alias extendWith
3121    * @category Object
3122    * @param {Object} object The destination object.
3123    * @param {...Object} sources The source objects.
3124    * @param {Function} [customizer] The function to customize assigned values.
3125    * @returns {Object} Returns `object`.
3126    * @example
3127    *
3128    * function customizer(objValue, srcValue) {
3129    *   return _.isUndefined(objValue) ? srcValue : objValue;
3130    * }
3131    *
3132    * var defaults = _.partialRight(_.assignInWith, customizer);
3133    *
3134    * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
3135    * // => { 'a': 1, 'b': 2 }
3136    */
3137   var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
3138     copyObjectWith(source, keysIn(source), object, customizer);
3139   });
3140
3141   /**
3142    * Creates an object that inherits from the `prototype` object. If a `properties`
3143    * object is provided its own enumerable properties are assigned to the created object.
3144    *
3145    * @static
3146    * @memberOf _
3147    * @category Object
3148    * @param {Object} prototype The object to inherit from.
3149    * @param {Object} [properties] The properties to assign to the object.
3150    * @returns {Object} Returns the new object.
3151    * @example
3152    *
3153    * function Shape() {
3154    *   this.x = 0;
3155    *   this.y = 0;
3156    * }
3157    *
3158    * function Circle() {
3159    *   Shape.call(this);
3160    * }
3161    *
3162    * Circle.prototype = _.create(Shape.prototype, {
3163    *   'constructor': Circle
3164    * });
3165    *
3166    * var circle = new Circle;
3167    * circle instanceof Circle;
3168    * // => true
3169    *
3170    * circle instanceof Shape;
3171    * // => true
3172    */
3173   function create(prototype, properties) {
3174     var result = baseCreate(prototype);
3175     return properties ? assign(result, properties) : result;
3176   }
3177
3178   /**
3179    * Assigns own and inherited enumerable properties of source objects to the
3180    * destination object for all destination properties that resolve to `undefined`.
3181    * Source objects are applied from left to right. Once a property is set,
3182    * additional values of the same property are ignored.
3183    *
3184    * **Note:** This method mutates `object`.
3185    *
3186    * @static
3187    * @memberOf _
3188    * @category Object
3189    * @param {Object} object The destination object.
3190    * @param {...Object} [sources] The source objects.
3191    * @returns {Object} Returns `object`.
3192    * @example
3193    *
3194    * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
3195    * // => { 'user': 'barney', 'age': 36 }
3196    */
3197   var defaults = rest(function(args) {
3198     args.push(undefined, assignInDefaults);
3199     return assignInWith.apply(undefined, args);
3200   });
3201
3202   /**
3203    * Checks if `path` is a direct property of `object`.
3204    *
3205    * @static
3206    * @memberOf _
3207    * @category Object
3208    * @param {Object} object The object to query.
3209    * @param {Array|string} path The path to check.
3210    * @returns {boolean} Returns `true` if `path` exists, else `false`.
3211    * @example
3212    *
3213    * var object = { 'a': { 'b': { 'c': 3 } } };
3214    * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
3215    *
3216    * _.has(object, 'a');
3217    * // => true
3218    *
3219    * _.has(object, 'a.b.c');
3220    * // => true
3221    *
3222    * _.has(object, ['a', 'b', 'c']);
3223    * // => true
3224    *
3225    * _.has(other, 'a');
3226    * // => false
3227    */
3228   function has(object, path) {
3229     return object != null && hasOwnProperty.call(object, path);
3230   }
3231
3232   /**
3233    * Creates an array of the own enumerable property names of `object`.
3234    *
3235    * **Note:** Non-object values are coerced to objects. See the
3236    * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
3237    * for more details.
3238    *
3239    * @static
3240    * @memberOf _
3241    * @category Object
3242    * @param {Object} object The object to query.
3243    * @returns {Array} Returns the array of property names.
3244    * @example
3245    *
3246    * function Foo() {
3247    *   this.a = 1;
3248    *   this.b = 2;
3249    * }
3250    *
3251    * Foo.prototype.c = 3;
3252    *
3253    * _.keys(new Foo);
3254    * // => ['a', 'b'] (iteration order is not guaranteed)
3255    *
3256    * _.keys('hi');
3257    * // => ['0', '1']
3258    */
3259   function keys(object) {
3260     var isProto = isPrototype(object);
3261     if (!(isProto || isArrayLike(object))) {
3262       return baseKeys(object);
3263     }
3264     var indexes = indexKeys(object),
3265         skipIndexes = !!indexes,
3266         result = indexes || [],
3267         length = result.length;
3268
3269     for (var key in object) {
3270       if (hasOwnProperty.call(object, key) &&
3271           !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3272           !(isProto && key == 'constructor')) {
3273         result.push(key);
3274       }
3275     }
3276     return result;
3277   }
3278
3279   /**
3280    * Creates an array of the own and inherited enumerable property names of `object`.
3281    *
3282    * **Note:** Non-object values are coerced to objects.
3283    *
3284    * @static
3285    * @memberOf _
3286    * @category Object
3287    * @param {Object} object The object to query.
3288    * @returns {Array} Returns the array of property names.
3289    * @example
3290    *
3291    * function Foo() {
3292    *   this.a = 1;
3293    *   this.b = 2;
3294    * }
3295    *
3296    * Foo.prototype.c = 3;
3297    *
3298    * _.keysIn(new Foo);
3299    * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
3300    */
3301   function keysIn(object) {
3302     var index = -1,
3303         isProto = isPrototype(object),
3304         props = baseKeysIn(object),
3305         propsLength = props.length,
3306         indexes = indexKeys(object),
3307         skipIndexes = !!indexes,
3308         result = indexes || [],
3309         length = result.length;
3310
3311     while (++index < propsLength) {
3312       var key = props[index];
3313       if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
3314           !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3315         result.push(key);
3316       }
3317     }
3318     return result;
3319   }
3320
3321   /**
3322    * Creates an object composed of the picked `object` properties.
3323    *
3324    * @static
3325    * @memberOf _
3326    * @category Object
3327    * @param {Object} object The source object.
3328    * @param {...(string|string[])} [props] The property names to pick, specified
3329    *  individually or in arrays.
3330    * @returns {Object} Returns the new object.
3331    * @example
3332    *
3333    * var object = { 'a': 1, 'b': '2', 'c': 3 };
3334    *
3335    * _.pick(object, ['a', 'c']);
3336    * // => { 'a': 1, 'c': 3 }
3337    */
3338   var pick = rest(function(object, props) {
3339     return object == null ? {} : basePick(object, baseFlatten(props));
3340   });
3341
3342   /**
3343    * This method is like `_.get` except that if the resolved value is a function
3344    * it's invoked with the `this` binding of its parent object and its result
3345    * is returned.
3346    *
3347    * @static
3348    * @memberOf _
3349    * @category Object
3350    * @param {Object} object The object to query.
3351    * @param {Array|string} path The path of the property to resolve.
3352    * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
3353    * @returns {*} Returns the resolved value.
3354    * @example
3355    *
3356    * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
3357    *
3358    * _.result(object, 'a[0].b.c1');
3359    * // => 3
3360    *
3361    * _.result(object, 'a[0].b.c2');
3362    * // => 4
3363    *
3364    * _.result(object, 'a[0].b.c3', 'default');
3365    * // => 'default'
3366    *
3367    * _.result(object, 'a[0].b.c3', _.constant('default'));
3368    * // => 'default'
3369    */
3370   function result(object, path, defaultValue) {
3371     var value = object == null ? undefined : object[path];
3372     if (value === undefined) {
3373       value = defaultValue;
3374     }
3375     return isFunction(value) ? value.call(object) : value;
3376   }
3377
3378   /**
3379    * Creates an array of the own enumerable property values of `object`.
3380    *
3381    * **Note:** Non-object values are coerced to objects.
3382    *
3383    * @static
3384    * @memberOf _
3385    * @category Object
3386    * @param {Object} object The object to query.
3387    * @returns {Array} Returns the array of property values.
3388    * @example
3389    *
3390    * function Foo() {
3391    *   this.a = 1;
3392    *   this.b = 2;
3393    * }
3394    *
3395    * Foo.prototype.c = 3;
3396    *
3397    * _.values(new Foo);
3398    * // => [1, 2] (iteration order is not guaranteed)
3399    *
3400    * _.values('hi');
3401    * // => ['h', 'i']
3402    */
3403   function values(object) {
3404     return object ? baseValues(object, keys(object)) : [];
3405   }
3406
3407   /*------------------------------------------------------------------------*/
3408
3409   /**
3410    * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
3411    * their corresponding HTML entities.
3412    *
3413    * **Note:** No other characters are escaped. To escape additional
3414    * characters use a third-party library like [_he_](https://mths.be/he).
3415    *
3416    * Though the ">" character is escaped for symmetry, characters like
3417    * ">" and "/" don't need escaping in HTML and have no special meaning
3418    * unless they're part of a tag or unquoted attribute value.
3419    * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
3420    * (under "semi-related fun fact") for more details.
3421    *
3422    * Backticks are escaped because in IE < 9, they can break out of
3423    * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
3424    * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
3425    * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
3426    * for more details.
3427    *
3428    * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
3429    * to reduce XSS vectors.
3430    *
3431    * @static
3432    * @memberOf _
3433    * @category String
3434    * @param {string} [string=''] The string to escape.
3435    * @returns {string} Returns the escaped string.
3436    * @example
3437    *
3438    * _.escape('fred, barney, & pebbles');
3439    * // => 'fred, barney, &amp; pebbles'
3440    */
3441   function escape(string) {
3442     string = toString(string);
3443     return (string && reHasUnescapedHtml.test(string))
3444       ? string.replace(reUnescapedHtml, escapeHtmlChar)
3445       : string;
3446   }
3447
3448   /*------------------------------------------------------------------------*/
3449
3450   /**
3451    * This method returns the first argument provided to it.
3452    *
3453    * @static
3454    * @memberOf _
3455    * @category Util
3456    * @param {*} value Any value.
3457    * @returns {*} Returns `value`.
3458    * @example
3459    *
3460    * var object = { 'user': 'fred' };
3461    *
3462    * _.identity(object) === object;
3463    * // => true
3464    */
3465   function identity(value) {
3466     return value;
3467   }
3468
3469   /**
3470    * Creates a function that invokes `func` with the arguments of the created
3471    * function. If `func` is a property name the created callback returns the
3472    * property value for a given element. If `func` is an object the created
3473    * callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
3474    *
3475    * @static
3476    * @memberOf _
3477    * @category Util
3478    * @param {*} [func=_.identity] The value to convert to a callback.
3479    * @returns {Function} Returns the callback.
3480    * @example
3481    *
3482    * var users = [
3483    *   { 'user': 'barney', 'age': 36 },
3484    *   { 'user': 'fred',   'age': 40 }
3485    * ];
3486    *
3487    * // create custom iteratee shorthands
3488    * _.iteratee = _.wrap(_.iteratee, function(callback, func) {
3489    *   var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
3490    *   return !p ? callback(func) : function(object) {
3491    *     return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
3492    *   };
3493    * });
3494    *
3495    * _.filter(users, 'age > 36');
3496    * // => [{ 'user': 'fred', 'age': 40 }]
3497    */
3498   var iteratee = baseIteratee;
3499
3500   /**
3501    * Creates a function that performs a deep partial comparison between a given
3502    * object and `source`, returning `true` if the given object has equivalent
3503    * property values, else `false`.
3504    *
3505    * **Note:** This method supports comparing the same values as `_.isEqual`.
3506    *
3507    * @static
3508    * @memberOf _
3509    * @category Util
3510    * @param {Object} source The object of property values to match.
3511    * @returns {Function} Returns the new function.
3512    * @example
3513    *
3514    * var users = [
3515    *   { 'user': 'barney', 'age': 36, 'active': true },
3516    *   { 'user': 'fred',   'age': 40, 'active': false }
3517    * ];
3518    *
3519    * _.filter(users, _.matches({ 'age': 40, 'active': false }));
3520    * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
3521    */
3522   function matches(source) {
3523     return baseMatches(assign({}, source));
3524   }
3525
3526   /**
3527    * Adds all own enumerable function properties of a source object to the
3528    * destination object. If `object` is a function then methods are added to
3529    * its prototype as well.
3530    *
3531    * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
3532    * avoid conflicts caused by modifying the original.
3533    *
3534    * @static
3535    * @memberOf _
3536    * @category Util
3537    * @param {Function|Object} [object=lodash] The destination object.
3538    * @param {Object} source The object of functions to add.
3539    * @param {Object} [options] The options object.
3540    * @param {boolean} [options.chain=true] Specify whether the functions added
3541    *  are chainable.
3542    * @returns {Function|Object} Returns `object`.
3543    * @example
3544    *
3545    * function vowels(string) {
3546    *   return _.filter(string, function(v) {
3547    *     return /[aeiou]/i.test(v);
3548    *   });
3549    * }
3550    *
3551    * _.mixin({ 'vowels': vowels });
3552    * _.vowels('fred');
3553    * // => ['e']
3554    *
3555    * _('fred').vowels().value();
3556    * // => ['e']
3557    *
3558    * _.mixin({ 'vowels': vowels }, { 'chain': false });
3559    * _('fred').vowels();
3560    * // => ['e']
3561    */
3562   function mixin(object, source, options) {
3563     var props = keys(source),
3564         methodNames = baseFunctions(source, props);
3565
3566     if (options == null &&
3567         !(isObject(source) && (methodNames.length || !props.length))) {
3568       options = source;
3569       source = object;
3570       object = this;
3571       methodNames = baseFunctions(source, keys(source));
3572     }
3573     var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
3574         isFunc = isFunction(object);
3575
3576     baseEach(methodNames, function(methodName) {
3577       var func = source[methodName];
3578       object[methodName] = func;
3579       if (isFunc) {
3580         object.prototype[methodName] = function() {
3581           var chainAll = this.__chain__;
3582           if (chain || chainAll) {
3583             var result = object(this.__wrapped__),
3584                 actions = result.__actions__ = copyArray(this.__actions__);
3585
3586             actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
3587             result.__chain__ = chainAll;
3588             return result;
3589           }
3590           return func.apply(object, arrayPush([this.value()], arguments));
3591         };
3592       }
3593     });
3594
3595     return object;
3596   }
3597
3598   /**
3599    * Reverts the `_` variable to its previous value and returns a reference to
3600    * the `lodash` function.
3601    *
3602    * @static
3603    * @memberOf _
3604    * @category Util
3605    * @returns {Function} Returns the `lodash` function.
3606    * @example
3607    *
3608    * var lodash = _.noConflict();
3609    */
3610   function noConflict() {
3611     if (root._ === this) {
3612       root._ = oldDash;
3613     }
3614     return this;
3615   }
3616
3617   /**
3618    * A no-operation function that returns `undefined` regardless of the
3619    * arguments it receives.
3620    *
3621    * @static
3622    * @memberOf _
3623    * @category Util
3624    * @example
3625    *
3626    * var object = { 'user': 'fred' };
3627    *
3628    * _.noop(object) === undefined;
3629    * // => true
3630    */
3631   function noop() {
3632     // No operation performed.
3633   }
3634
3635   /**
3636    * Generates a unique ID. If `prefix` is provided the ID is appended to it.
3637    *
3638    * @static
3639    * @memberOf _
3640    * @category Util
3641    * @param {string} [prefix] The value to prefix the ID with.
3642    * @returns {string} Returns the unique ID.
3643    * @example
3644    *
3645    * _.uniqueId('contact_');
3646    * // => 'contact_104'
3647    *
3648    * _.uniqueId();
3649    * // => '105'
3650    */
3651   function uniqueId(prefix) {
3652     var id = ++idCounter;
3653     return toString(prefix) + id;
3654   }
3655
3656   /*------------------------------------------------------------------------*/
3657
3658   /**
3659    * Computes the maximum value of `array`. If `array` is empty or falsey
3660    * `undefined` is returned.
3661    *
3662    * @static
3663    * @memberOf _
3664    * @category Math
3665    * @param {Array} array The array to iterate over.
3666    * @returns {*} Returns the maximum value.
3667    * @example
3668    *
3669    * _.max([4, 2, 8, 6]);
3670    * // => 8
3671    *
3672    * _.max([]);
3673    * // => undefined
3674    */
3675   function max(array) {
3676     return (array && array.length)
3677       ? baseExtremum(array, identity, gt)
3678       : undefined;
3679   }
3680
3681   /**
3682    * Computes the minimum value of `array`. If `array` is empty or falsey
3683    * `undefined` is returned.
3684    *
3685    * @static
3686    * @memberOf _
3687    * @category Math
3688    * @param {Array} array The array to iterate over.
3689    * @returns {*} Returns the minimum value.
3690    * @example
3691    *
3692    * _.min([4, 2, 8, 6]);
3693    * // => 2
3694    *
3695    * _.min([]);
3696    * // => undefined
3697    */
3698   function min(array) {
3699     return (array && array.length)
3700       ? baseExtremum(array, identity, lt)
3701       : undefined;
3702   }
3703
3704   /*------------------------------------------------------------------------*/
3705
3706   LodashWrapper.prototype = baseCreate(lodash.prototype);
3707   LodashWrapper.prototype.constructor = LodashWrapper;
3708
3709   // Add functions that return wrapped values when chaining.
3710   lodash.assignIn = assignIn;
3711   lodash.before = before;
3712   lodash.bind = bind;
3713   lodash.chain = chain;
3714   lodash.compact = compact;
3715   lodash.concat = concat;
3716   lodash.create = create;
3717   lodash.defaults = defaults;
3718   lodash.defer = defer;
3719   lodash.delay = delay;
3720   lodash.filter = filter;
3721   lodash.flatten = flatten;
3722   lodash.flattenDeep = flattenDeep;
3723   lodash.invokeMap = invokeMap;
3724   lodash.iteratee = iteratee;
3725   lodash.keys = keys;
3726   lodash.map = map;
3727   lodash.matches = matches;
3728   lodash.mixin = mixin;
3729   lodash.negate = negate;
3730   lodash.once = once;
3731   lodash.pick = pick;
3732   lodash.slice = slice;
3733   lodash.sortBy = sortBy;
3734   lodash.tap = tap;
3735   lodash.thru = thru;
3736   lodash.toArray = toArray;
3737   lodash.values = values;
3738
3739   // Add aliases.
3740   lodash.extend = assignIn;
3741
3742   // Add functions to `lodash.prototype`.
3743   mixin(lodash, lodash);
3744
3745   /*------------------------------------------------------------------------*/
3746
3747   // Add functions that return unwrapped values when chaining.
3748   lodash.clone = clone;
3749   lodash.escape = escape;
3750   lodash.every = every;
3751   lodash.find = find;
3752   lodash.forEach = forEach;
3753   lodash.has = has;
3754   lodash.head = head;
3755   lodash.identity = identity;
3756   lodash.indexOf = indexOf;
3757   lodash.isArguments = isArguments;
3758   lodash.isArray = isArray;
3759   lodash.isBoolean = isBoolean;
3760   lodash.isDate = isDate;
3761   lodash.isEmpty = isEmpty;
3762   lodash.isEqual = isEqual;
3763   lodash.isFinite = isFinite;
3764   lodash.isFunction = isFunction;
3765   lodash.isNaN = isNaN;
3766   lodash.isNull = isNull;
3767   lodash.isNumber = isNumber;
3768   lodash.isObject = isObject;
3769   lodash.isRegExp = isRegExp;
3770   lodash.isString = isString;
3771   lodash.isUndefined = isUndefined;
3772   lodash.last = last;
3773   lodash.max = max;
3774   lodash.min = min;
3775   lodash.noConflict = noConflict;
3776   lodash.noop = noop;
3777   lodash.now = now;
3778   lodash.reduce = reduce;
3779   lodash.result = result;
3780   lodash.size = size;
3781   lodash.some = some;
3782   lodash.uniqueId = uniqueId;
3783
3784   // Add aliases.
3785   lodash.each = forEach;
3786   lodash.first = head;
3787
3788   mixin(lodash, (function() {
3789     var source = {};
3790     baseForOwn(lodash, function(func, methodName) {
3791       if (!hasOwnProperty.call(lodash.prototype, methodName)) {
3792         source[methodName] = func;
3793       }
3794     });
3795     return source;
3796   }()), { 'chain': false });
3797
3798   /*------------------------------------------------------------------------*/
3799
3800   /**
3801    * The semantic version number.
3802    *
3803    * @static
3804    * @memberOf _
3805    * @type string
3806    */
3807   lodash.VERSION = VERSION;
3808
3809   // Add `Array` and `String` methods to `lodash.prototype`.
3810   baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
3811     var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
3812         chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
3813         retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
3814
3815     lodash.prototype[methodName] = function() {
3816       var args = arguments;
3817       if (retUnwrapped && !this.__chain__) {
3818         return func.apply(this.value(), args);
3819       }
3820       return this[chainName](function(value) {
3821         return func.apply(value, args);
3822       });
3823     };
3824   });
3825
3826   // Add chaining functions to the `lodash` wrapper.
3827   lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
3828
3829   /*--------------------------------------------------------------------------*/
3830
3831   // Expose lodash on the free variable `window` or `self` when available. This
3832   // prevents errors in cases where lodash is loaded by a script tag in the presence
3833   // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
3834   (freeWindow || freeSelf || {})._ = lodash;
3835
3836   // Some AMD build optimizers like r.js check for condition patterns like the following:
3837   if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
3838     // Define as an anonymous module so, through path mapping, it can be
3839     // referenced as the "underscore" module.
3840     define(function() {
3841       return lodash;
3842     });
3843   }
3844   // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
3845   else if (freeExports && freeModule) {
3846     // Export for Node.js.
3847     if (moduleExports) {
3848       (freeModule.exports = lodash)._ = lodash;
3849     }
3850     // Export for CommonJS support.
3851     freeExports._ = lodash;
3852   }
3853   else {
3854     // Export to the global object.
3855     root._ = lodash;
3856   }
3857 }.call(this));