blob: 6e4a6b5e801f36e6424a7f269b1dbb8b6c59c5d5 [file] [log] [blame]
Matteo Scandolo7cd88ba2015-12-16 14:23:08 -08001/**
2 * @license
3 * lodash 3.10.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash modern exports="amd,commonjs,node" iife="angular.module('ngLodash', []).constant('lodash', null).config(function ($provide) { %output% $provide.constant('lodash', _);});" --output build/ng-lodash.js`
5 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
9 */
10angular.module('ngLodash', []).constant('lodash', null).config([
11 '$provide',
12 function ($provide) {
13 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
14 var undefined;
15 /** Used as the semantic version number. */
16 var VERSION = '3.10.1';
17 /** Used to compose bitmasks for wrapper metadata. */
18 var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_BOUND_FLAG = 4, CURRY_FLAG = 8, CURRY_RIGHT_FLAG = 16, PARTIAL_FLAG = 32, PARTIAL_RIGHT_FLAG = 64, ARY_FLAG = 128, REARG_FLAG = 256;
19 /** Used as default options for `_.trunc`. */
20 var DEFAULT_TRUNC_LENGTH = 30, DEFAULT_TRUNC_OMISSION = '...';
21 /** Used to detect when a function becomes hot. */
22 var HOT_COUNT = 150, HOT_SPAN = 16;
23 /** Used as the size to enable large array optimizations. */
24 var LARGE_ARRAY_SIZE = 200;
25 /** Used to indicate the type of lazy iteratees. */
26 var LAZY_FILTER_FLAG = 1, LAZY_MAP_FLAG = 2;
27 /** Used as the `TypeError` message for "Functions" methods. */
28 var FUNC_ERROR_TEXT = 'Expected a function';
29 /** Used as the internal argument placeholder. */
30 var PLACEHOLDER = '__lodash_placeholder__';
31 /** `Object#toString` result references. */
32 var argsTag = '[object Arguments]', arrayTag = '[object Array]', boolTag = '[object Boolean]', dateTag = '[object Date]', errorTag = '[object Error]', funcTag = '[object Function]', mapTag = '[object Map]', numberTag = '[object Number]', objectTag = '[object Object]', regexpTag = '[object RegExp]', setTag = '[object Set]', stringTag = '[object String]', weakMapTag = '[object WeakMap]';
33 var arrayBufferTag = '[object ArrayBuffer]', float32Tag = '[object Float32Array]', float64Tag = '[object Float64Array]', int8Tag = '[object Int8Array]', int16Tag = '[object Int16Array]', int32Tag = '[object Int32Array]', uint8Tag = '[object Uint8Array]', uint8ClampedTag = '[object Uint8ClampedArray]', uint16Tag = '[object Uint16Array]', uint32Tag = '[object Uint32Array]';
34 /** Used to match empty string literals in compiled template source. */
35 var reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
36 /** Used to match HTML entities and HTML characters. */
37 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g, reUnescapedHtml = /[&<>"'`]/g, reHasEscapedHtml = RegExp(reEscapedHtml.source), reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
38 /** Used to match template delimiters. */
39 var reEscape = /<%-([\s\S]+?)%>/g, reEvaluate = /<%([\s\S]+?)%>/g, reInterpolate = /<%=([\s\S]+?)%>/g;
40 /** Used to match property names within property paths. */
41 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
42 /**
43 * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
44 * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
45 */
46 var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g, reHasRegExpChars = RegExp(reRegExpChars.source);
47 /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
48 var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
49 /** Used to match backslashes in property paths. */
50 var reEscapeChar = /\\(\\)?/g;
51 /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
52 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
53 /** Used to match `RegExp` flags from their coerced string values. */
54 var reFlags = /\w*$/;
55 /** Used to detect hexadecimal string values. */
56 var reHasHexPrefix = /^0[xX]/;
57 /** Used to detect host constructors (Safari > 5). */
58 var reIsHostCtor = /^\[object .+?Constructor\]$/;
59 /** Used to detect unsigned integer values. */
60 var reIsUint = /^\d+$/;
61 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
62 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
63 /** Used to ensure capturing order of template delimiters. */
64 var reNoMatch = /($^)/;
65 /** Used to match unescaped characters in compiled string literals. */
66 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
67 /** Used to match words to create compound words. */
68 var reWords = function () {
69 var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]', lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
70 return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
71 }();
72 /** Used to assign default `context` object properties. */
73 var contextProps = [
74 'Array',
75 'ArrayBuffer',
76 'Date',
77 'Error',
78 'Float32Array',
79 'Float64Array',
80 'Function',
81 'Int8Array',
82 'Int16Array',
83 'Int32Array',
84 'Math',
85 'Number',
86 'Object',
87 'RegExp',
88 'Set',
89 'String',
90 '_',
91 'clearTimeout',
92 'isFinite',
93 'parseFloat',
94 'parseInt',
95 'setTimeout',
96 'TypeError',
97 'Uint8Array',
98 'Uint8ClampedArray',
99 'Uint16Array',
100 'Uint32Array',
101 'WeakMap'
102 ];
103 /** Used to make template sourceURLs easier to identify. */
104 var templateCounter = -1;
105 /** Used to identify `toStringTag` values of typed arrays. */
106 var typedArrayTags = {};
107 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
108 typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
109 /** Used to identify `toStringTag` values supported by `_.clone`. */
110 var cloneableTags = {};
111 cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[stringTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
112 cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[mapTag] = cloneableTags[setTag] = cloneableTags[weakMapTag] = false;
113 /** Used to map latin-1 supplementary letters to basic latin letters. */
114 var deburredLetters = {
115 '\xc0': 'A',
116 '\xc1': 'A',
117 '\xc2': 'A',
118 '\xc3': 'A',
119 '\xc4': 'A',
120 '\xc5': 'A',
121 '\xe0': 'a',
122 '\xe1': 'a',
123 '\xe2': 'a',
124 '\xe3': 'a',
125 '\xe4': 'a',
126 '\xe5': 'a',
127 '\xc7': 'C',
128 '\xe7': 'c',
129 '\xd0': 'D',
130 '\xf0': 'd',
131 '\xc8': 'E',
132 '\xc9': 'E',
133 '\xca': 'E',
134 '\xcb': 'E',
135 '\xe8': 'e',
136 '\xe9': 'e',
137 '\xea': 'e',
138 '\xeb': 'e',
139 '\xcc': 'I',
140 '\xcd': 'I',
141 '\xce': 'I',
142 '\xcf': 'I',
143 '\xec': 'i',
144 '\xed': 'i',
145 '\xee': 'i',
146 '\xef': 'i',
147 '\xd1': 'N',
148 '\xf1': 'n',
149 '\xd2': 'O',
150 '\xd3': 'O',
151 '\xd4': 'O',
152 '\xd5': 'O',
153 '\xd6': 'O',
154 '\xd8': 'O',
155 '\xf2': 'o',
156 '\xf3': 'o',
157 '\xf4': 'o',
158 '\xf5': 'o',
159 '\xf6': 'o',
160 '\xf8': 'o',
161 '\xd9': 'U',
162 '\xda': 'U',
163 '\xdb': 'U',
164 '\xdc': 'U',
165 '\xf9': 'u',
166 '\xfa': 'u',
167 '\xfb': 'u',
168 '\xfc': 'u',
169 '\xdd': 'Y',
170 '\xfd': 'y',
171 '\xff': 'y',
172 '\xc6': 'Ae',
173 '\xe6': 'ae',
174 '\xde': 'Th',
175 '\xfe': 'th',
176 '\xdf': 'ss'
177 };
178 /** Used to map characters to HTML entities. */
179 var htmlEscapes = {
180 '&': '&amp;',
181 '<': '&lt;',
182 '>': '&gt;',
183 '"': '&quot;',
184 '\'': '&#39;',
185 '`': '&#96;'
186 };
187 /** Used to map HTML entities to characters. */
188 var htmlUnescapes = {
189 '&amp;': '&',
190 '&lt;': '<',
191 '&gt;': '>',
192 '&quot;': '"',
193 '&#39;': '\'',
194 '&#96;': '`'
195 };
196 /** Used to determine if values are of the language type `Object`. */
197 var objectTypes = {
198 'function': true,
199 'object': true
200 };
201 /** Used to escape characters for inclusion in compiled regexes. */
202 var regexpEscapes = {
203 '0': 'x30',
204 '1': 'x31',
205 '2': 'x32',
206 '3': 'x33',
207 '4': 'x34',
208 '5': 'x35',
209 '6': 'x36',
210 '7': 'x37',
211 '8': 'x38',
212 '9': 'x39',
213 'A': 'x41',
214 'B': 'x42',
215 'C': 'x43',
216 'D': 'x44',
217 'E': 'x45',
218 'F': 'x46',
219 'a': 'x61',
220 'b': 'x62',
221 'c': 'x63',
222 'd': 'x64',
223 'e': 'x65',
224 'f': 'x66',
225 'n': 'x6e',
226 'r': 'x72',
227 't': 'x74',
228 'u': 'x75',
229 'v': 'x76',
230 'x': 'x78'
231 };
232 /** Used to escape characters for inclusion in compiled string literals. */
233 var stringEscapes = {
234 '\\': '\\',
235 '\'': '\'',
236 '\n': 'n',
237 '\r': 'r',
238 '\u2028': 'u2028',
239 '\u2029': 'u2029'
240 };
241 /** Detect free variable `exports`. */
242 var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
243 /** Detect free variable `module`. */
244 var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
245 /** Detect free variable `global` from Node.js. */
246 var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
247 /** Detect free variable `self`. */
248 var freeSelf = objectTypes[typeof self] && self && self.Object && self;
249 /** Detect free variable `window`. */
250 var freeWindow = objectTypes[typeof window] && window && window.Object && window;
251 /** Detect the popular CommonJS extension `module.exports`. */
252 var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
253 /**
254 * Used as a reference to the global object.
255 *
256 * The `this` value is used if it's the global object to avoid Greasemonkey's
257 * restricted `window` object, otherwise the `window` object is used.
258 */
259 var root = freeGlobal || freeWindow !== (this && this.window) && freeWindow || freeSelf || this;
260 /*--------------------------------------------------------------------------*/
261 /**
262 * The base implementation of `compareAscending` which compares values and
263 * sorts them in ascending order without guaranteeing a stable sort.
264 *
265 * @private
266 * @param {*} value The value to compare.
267 * @param {*} other The other value to compare.
268 * @returns {number} Returns the sort order indicator for `value`.
269 */
270 function baseCompareAscending(value, other) {
271 if (value !== other) {
272 var valIsNull = value === null, valIsUndef = value === undefined, valIsReflexive = value === value;
273 var othIsNull = other === null, othIsUndef = other === undefined, othIsReflexive = other === other;
274 if (value > other && !othIsNull || !valIsReflexive || valIsNull && !othIsUndef && othIsReflexive || valIsUndef && othIsReflexive) {
275 return 1;
276 }
277 if (value < other && !valIsNull || !othIsReflexive || othIsNull && !valIsUndef && valIsReflexive || othIsUndef && valIsReflexive) {
278 return -1;
279 }
280 }
281 return 0;
282 }
283 /**
284 * The base implementation of `_.findIndex` and `_.findLastIndex` without
285 * support for callback shorthands and `this` binding.
286 *
287 * @private
288 * @param {Array} array The array to search.
289 * @param {Function} predicate The function invoked per iteration.
290 * @param {boolean} [fromRight] Specify iterating from right to left.
291 * @returns {number} Returns the index of the matched value, else `-1`.
292 */
293 function baseFindIndex(array, predicate, fromRight) {
294 var length = array.length, index = fromRight ? length : -1;
295 while (fromRight ? index-- : ++index < length) {
296 if (predicate(array[index], index, array)) {
297 return index;
298 }
299 }
300 return -1;
301 }
302 /**
303 * The base implementation of `_.indexOf` without support for binary searches.
304 *
305 * @private
306 * @param {Array} array The array to search.
307 * @param {*} value The value to search for.
308 * @param {number} fromIndex The index to search from.
309 * @returns {number} Returns the index of the matched value, else `-1`.
310 */
311 function baseIndexOf(array, value, fromIndex) {
312 if (value !== value) {
313 return indexOfNaN(array, fromIndex);
314 }
315 var index = fromIndex - 1, length = array.length;
316 while (++index < length) {
317 if (array[index] === value) {
318 return index;
319 }
320 }
321 return -1;
322 }
323 /**
324 * The base implementation of `_.isFunction` without support for environments
325 * with incorrect `typeof` results.
326 *
327 * @private
328 * @param {*} value The value to check.
329 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
330 */
331 function baseIsFunction(value) {
332 // Avoid a Chakra JIT bug in compatibility modes of IE 11.
333 // See https://github.com/jashkenas/underscore/issues/1621 for more details.
334 return typeof value == 'function' || false;
335 }
336 /**
337 * Converts `value` to a string if it's not one. An empty string is returned
338 * for `null` or `undefined` values.
339 *
340 * @private
341 * @param {*} value The value to process.
342 * @returns {string} Returns the string.
343 */
344 function baseToString(value) {
345 return value == null ? '' : value + '';
346 }
347 /**
348 * Used by `_.trim` and `_.trimLeft` to get the index of the first character
349 * of `string` that is not found in `chars`.
350 *
351 * @private
352 * @param {string} string The string to inspect.
353 * @param {string} chars The characters to find.
354 * @returns {number} Returns the index of the first character not found in `chars`.
355 */
356 function charsLeftIndex(string, chars) {
357 var index = -1, length = string.length;
358 while (++index < length && chars.indexOf(string.charAt(index)) > -1) {
359 }
360 return index;
361 }
362 /**
363 * Used by `_.trim` and `_.trimRight` to get the index of the last character
364 * of `string` that is not found in `chars`.
365 *
366 * @private
367 * @param {string} string The string to inspect.
368 * @param {string} chars The characters to find.
369 * @returns {number} Returns the index of the last character not found in `chars`.
370 */
371 function charsRightIndex(string, chars) {
372 var index = string.length;
373 while (index-- && chars.indexOf(string.charAt(index)) > -1) {
374 }
375 return index;
376 }
377 /**
378 * Used by `_.sortBy` to compare transformed elements of a collection and stable
379 * sort them in ascending order.
380 *
381 * @private
382 * @param {Object} object The object to compare.
383 * @param {Object} other The other object to compare.
384 * @returns {number} Returns the sort order indicator for `object`.
385 */
386 function compareAscending(object, other) {
387 return baseCompareAscending(object.criteria, other.criteria) || object.index - other.index;
388 }
389 /**
390 * Used by `_.sortByOrder` to compare multiple properties of a value to another
391 * and stable sort them.
392 *
393 * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
394 * a value is sorted in ascending order if its corresponding order is "asc", and
395 * descending if "desc".
396 *
397 * @private
398 * @param {Object} object The object to compare.
399 * @param {Object} other The other object to compare.
400 * @param {boolean[]} orders The order to sort by for each property.
401 * @returns {number} Returns the sort order indicator for `object`.
402 */
403 function compareMultiple(object, other, orders) {
404 var index = -1, objCriteria = object.criteria, othCriteria = other.criteria, length = objCriteria.length, ordersLength = orders.length;
405 while (++index < length) {
406 var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
407 if (result) {
408 if (index >= ordersLength) {
409 return result;
410 }
411 var order = orders[index];
412 return result * (order === 'asc' || order === true ? 1 : -1);
413 }
414 }
415 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
416 // that causes it, under certain circumstances, to provide the same value for
417 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
418 // for more details.
419 //
420 // This also ensures a stable sort in V8 and other engines.
421 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
422 return object.index - other.index;
423 }
424 /**
425 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
426 *
427 * @private
428 * @param {string} letter The matched letter to deburr.
429 * @returns {string} Returns the deburred letter.
430 */
431 function deburrLetter(letter) {
432 return deburredLetters[letter];
433 }
434 /**
435 * Used by `_.escape` to convert characters to HTML entities.
436 *
437 * @private
438 * @param {string} chr The matched character to escape.
439 * @returns {string} Returns the escaped character.
440 */
441 function escapeHtmlChar(chr) {
442 return htmlEscapes[chr];
443 }
444 /**
445 * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
446 *
447 * @private
448 * @param {string} chr The matched character to escape.
449 * @param {string} leadingChar The capture group for a leading character.
450 * @param {string} whitespaceChar The capture group for a whitespace character.
451 * @returns {string} Returns the escaped character.
452 */
453 function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
454 if (leadingChar) {
455 chr = regexpEscapes[chr];
456 } else if (whitespaceChar) {
457 chr = stringEscapes[chr];
458 }
459 return '\\' + chr;
460 }
461 /**
462 * Used by `_.template` to escape characters for inclusion in compiled string literals.
463 *
464 * @private
465 * @param {string} chr The matched character to escape.
466 * @returns {string} Returns the escaped character.
467 */
468 function escapeStringChar(chr) {
469 return '\\' + stringEscapes[chr];
470 }
471 /**
472 * Gets the index at which the first occurrence of `NaN` is found in `array`.
473 *
474 * @private
475 * @param {Array} array The array to search.
476 * @param {number} fromIndex The index to search from.
477 * @param {boolean} [fromRight] Specify iterating from right to left.
478 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
479 */
480 function indexOfNaN(array, fromIndex, fromRight) {
481 var length = array.length, index = fromIndex + (fromRight ? 0 : -1);
482 while (fromRight ? index-- : ++index < length) {
483 var other = array[index];
484 if (other !== other) {
485 return index;
486 }
487 }
488 return -1;
489 }
490 /**
491 * Checks if `value` is object-like.
492 *
493 * @private
494 * @param {*} value The value to check.
495 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
496 */
497 function isObjectLike(value) {
498 return !!value && typeof value == 'object';
499 }
500 /**
501 * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
502 * character code is whitespace.
503 *
504 * @private
505 * @param {number} charCode The character code to inspect.
506 * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
507 */
508 function isSpace(charCode) {
509 return charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160 || charCode == 5760 || charCode == 6158 || charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279);
510 }
511 /**
512 * Replaces all `placeholder` elements in `array` with an internal placeholder
513 * and returns an array of their indexes.
514 *
515 * @private
516 * @param {Array} array The array to modify.
517 * @param {*} placeholder The placeholder to replace.
518 * @returns {Array} Returns the new array of placeholder indexes.
519 */
520 function replaceHolders(array, placeholder) {
521 var index = -1, length = array.length, resIndex = -1, result = [];
522 while (++index < length) {
523 if (array[index] === placeholder) {
524 array[index] = PLACEHOLDER;
525 result[++resIndex] = index;
526 }
527 }
528 return result;
529 }
530 /**
531 * An implementation of `_.uniq` optimized for sorted arrays without support
532 * for callback shorthands and `this` binding.
533 *
534 * @private
535 * @param {Array} array The array to inspect.
536 * @param {Function} [iteratee] The function invoked per iteration.
537 * @returns {Array} Returns the new duplicate free array.
538 */
539 function sortedUniq(array, iteratee) {
540 var seen, index = -1, length = array.length, resIndex = -1, result = [];
541 while (++index < length) {
542 var value = array[index], computed = iteratee ? iteratee(value, index, array) : value;
543 if (!index || seen !== computed) {
544 seen = computed;
545 result[++resIndex] = value;
546 }
547 }
548 return result;
549 }
550 /**
551 * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
552 * character of `string`.
553 *
554 * @private
555 * @param {string} string The string to inspect.
556 * @returns {number} Returns the index of the first non-whitespace character.
557 */
558 function trimmedLeftIndex(string) {
559 var index = -1, length = string.length;
560 while (++index < length && isSpace(string.charCodeAt(index))) {
561 }
562 return index;
563 }
564 /**
565 * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
566 * character of `string`.
567 *
568 * @private
569 * @param {string} string The string to inspect.
570 * @returns {number} Returns the index of the last non-whitespace character.
571 */
572 function trimmedRightIndex(string) {
573 var index = string.length;
574 while (index-- && isSpace(string.charCodeAt(index))) {
575 }
576 return index;
577 }
578 /**
579 * Used by `_.unescape` to convert HTML entities to characters.
580 *
581 * @private
582 * @param {string} chr The matched character to unescape.
583 * @returns {string} Returns the unescaped character.
584 */
585 function unescapeHtmlChar(chr) {
586 return htmlUnescapes[chr];
587 }
588 /*--------------------------------------------------------------------------*/
589 /**
590 * Create a new pristine `lodash` function using the given `context` object.
591 *
592 * @static
593 * @memberOf _
594 * @category Utility
595 * @param {Object} [context=root] The context object.
596 * @returns {Function} Returns a new `lodash` function.
597 * @example
598 *
599 * _.mixin({ 'foo': _.constant('foo') });
600 *
601 * var lodash = _.runInContext();
602 * lodash.mixin({ 'bar': lodash.constant('bar') });
603 *
604 * _.isFunction(_.foo);
605 * // => true
606 * _.isFunction(_.bar);
607 * // => false
608 *
609 * lodash.isFunction(lodash.foo);
610 * // => false
611 * lodash.isFunction(lodash.bar);
612 * // => true
613 *
614 * // using `context` to mock `Date#getTime` use in `_.now`
615 * var mock = _.runInContext({
616 * 'Date': function() {
617 * return { 'getTime': getTimeMock };
618 * }
619 * });
620 *
621 * // or creating a suped-up `defer` in Node.js
622 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
623 */
624 function runInContext(context) {
625 // Avoid issues with some ES3 environments that attempt to use values, named
626 // after built-in constructors like `Object`, for the creation of literals.
627 // ES5 clears this up by stating that literals must use built-in constructors.
628 // See https://es5.github.io/#x11.1.5 for more details.
629 context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
630 /** Native constructor references. */
631 var Array = context.Array, Date = context.Date, Error = context.Error, Function = context.Function, Math = context.Math, Number = context.Number, Object = context.Object, RegExp = context.RegExp, String = context.String, TypeError = context.TypeError;
632 /** Used for native method references. */
633 var arrayProto = Array.prototype, objectProto = Object.prototype, stringProto = String.prototype;
634 /** Used to resolve the decompiled source of functions. */
635 var fnToString = Function.prototype.toString;
636 /** Used to check objects for own properties. */
637 var hasOwnProperty = objectProto.hasOwnProperty;
638 /** Used to generate unique IDs. */
639 var idCounter = 0;
640 /**
641 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
642 * of values.
643 */
644 var objToString = objectProto.toString;
645 /** Used to restore the original `_` reference in `_.noConflict`. */
646 var oldDash = root._;
647 /** Used to detect if a method is native. */
648 var reIsNative = RegExp('^' + fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
649 /** Native method references. */
650 var ArrayBuffer = context.ArrayBuffer, clearTimeout = context.clearTimeout, parseFloat = context.parseFloat, pow = Math.pow, propertyIsEnumerable = objectProto.propertyIsEnumerable, Set = getNative(context, 'Set'), setTimeout = context.setTimeout, splice = arrayProto.splice, Uint8Array = context.Uint8Array, WeakMap = getNative(context, 'WeakMap');
651 /* Native method references for those with the same name as other `lodash` methods. */
652 var nativeCeil = Math.ceil, nativeCreate = getNative(Object, 'create'), nativeFloor = Math.floor, nativeIsArray = getNative(Array, 'isArray'), nativeIsFinite = context.isFinite, nativeKeys = getNative(Object, 'keys'), nativeMax = Math.max, nativeMin = Math.min, nativeNow = getNative(Date, 'now'), nativeParseInt = context.parseInt, nativeRandom = Math.random;
653 /** Used as references for `-Infinity` and `Infinity`. */
654 var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY, POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
655 /** Used as references for the maximum length and index of an array. */
656 var MAX_ARRAY_LENGTH = 4294967295, MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
657 /**
658 * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
659 * of an array-like value.
660 */
661 var MAX_SAFE_INTEGER = 9007199254740991;
662 /** Used to store function metadata. */
663 var metaMap = WeakMap && new WeakMap();
664 /** Used to lookup unminified function names. */
665 var realNames = {};
666 /*------------------------------------------------------------------------*/
667 /**
668 * Creates a `lodash` object which wraps `value` to enable implicit chaining.
669 * Methods that operate on and return arrays, collections, and functions can
670 * be chained together. Methods that retrieve a single value or may return a
671 * primitive value will automatically end the chain returning the unwrapped
672 * value. Explicit chaining may be enabled using `_.chain`. The execution of
673 * chained methods is lazy, that is, execution is deferred until `_#value`
674 * is implicitly or explicitly called.
675 *
676 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
677 * fusion is an optimization strategy which merge iteratee calls; this can help
678 * to avoid the creation of intermediate data structures and greatly reduce the
679 * number of iteratee executions.
680 *
681 * Chaining is supported in custom builds as long as the `_#value` method is
682 * directly or indirectly included in the build.
683 *
684 * In addition to lodash methods, wrappers have `Array` and `String` methods.
685 *
686 * The wrapper `Array` methods are:
687 * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
688 * `splice`, and `unshift`
689 *
690 * The wrapper `String` methods are:
691 * `replace` and `split`
692 *
693 * The wrapper methods that support shortcut fusion are:
694 * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
695 * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
696 * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
697 * and `where`
698 *
699 * The chainable wrapper methods are:
700 * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
701 * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
702 * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
703 * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
704 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
705 * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
706 * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
707 * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
708 * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
709 * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
710 * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
711 * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
712 * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
713 * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
714 * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
715 * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
716 * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
717 *
718 * The wrapper methods that are **not** chainable by default are:
719 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
720 * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
721 * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
722 * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
723 * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
724 * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
725 * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
726 * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
727 * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
728 * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
729 * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
730 * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
731 * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
732 * `unescape`, `uniqueId`, `value`, and `words`
733 *
734 * The wrapper method `sample` will return a wrapped value when `n` is provided,
735 * otherwise an unwrapped value is returned.
736 *
737 * @name _
738 * @constructor
739 * @category Chain
740 * @param {*} value The value to wrap in a `lodash` instance.
741 * @returns {Object} Returns the new `lodash` wrapper instance.
742 * @example
743 *
744 * var wrapped = _([1, 2, 3]);
745 *
746 * // returns an unwrapped value
747 * wrapped.reduce(function(total, n) {
748 * return total + n;
749 * });
750 * // => 6
751 *
752 * // returns a wrapped value
753 * var squares = wrapped.map(function(n) {
754 * return n * n;
755 * });
756 *
757 * _.isArray(squares);
758 * // => false
759 *
760 * _.isArray(squares.value());
761 * // => true
762 */
763 function lodash(value) {
764 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
765 if (value instanceof LodashWrapper) {
766 return value;
767 }
768 if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
769 return wrapperClone(value);
770 }
771 }
772 return new LodashWrapper(value);
773 }
774 /**
775 * The function whose prototype all chaining wrappers inherit from.
776 *
777 * @private
778 */
779 function baseLodash() {
780 }
781 /**
782 * The base constructor for creating `lodash` wrapper objects.
783 *
784 * @private
785 * @param {*} value The value to wrap.
786 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
787 * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
788 */
789 function LodashWrapper(value, chainAll, actions) {
790 this.__wrapped__ = value;
791 this.__actions__ = actions || [];
792 this.__chain__ = !!chainAll;
793 }
794 /**
795 * An object environment feature flags.
796 *
797 * @static
798 * @memberOf _
799 * @type Object
800 */
801 var support = lodash.support = {};
802 /**
803 * By default, the template delimiters used by lodash are like those in
804 * embedded Ruby (ERB). Change the following template settings to use
805 * alternative delimiters.
806 *
807 * @static
808 * @memberOf _
809 * @type Object
810 */
811 lodash.templateSettings = {
812 'escape': reEscape,
813 'evaluate': reEvaluate,
814 'interpolate': reInterpolate,
815 'variable': '',
816 'imports': { '_': lodash }
817 };
818 /*------------------------------------------------------------------------*/
819 /**
820 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
821 *
822 * @private
823 * @param {*} value The value to wrap.
824 */
825 function LazyWrapper(value) {
826 this.__wrapped__ = value;
827 this.__actions__ = [];
828 this.__dir__ = 1;
829 this.__filtered__ = false;
830 this.__iteratees__ = [];
831 this.__takeCount__ = POSITIVE_INFINITY;
832 this.__views__ = [];
833 }
834 /**
835 * Creates a clone of the lazy wrapper object.
836 *
837 * @private
838 * @name clone
839 * @memberOf LazyWrapper
840 * @returns {Object} Returns the cloned `LazyWrapper` object.
841 */
842 function lazyClone() {
843 var result = new LazyWrapper(this.__wrapped__);
844 result.__actions__ = arrayCopy(this.__actions__);
845 result.__dir__ = this.__dir__;
846 result.__filtered__ = this.__filtered__;
847 result.__iteratees__ = arrayCopy(this.__iteratees__);
848 result.__takeCount__ = this.__takeCount__;
849 result.__views__ = arrayCopy(this.__views__);
850 return result;
851 }
852 /**
853 * Reverses the direction of lazy iteration.
854 *
855 * @private
856 * @name reverse
857 * @memberOf LazyWrapper
858 * @returns {Object} Returns the new reversed `LazyWrapper` object.
859 */
860 function lazyReverse() {
861 if (this.__filtered__) {
862 var result = new LazyWrapper(this);
863 result.__dir__ = -1;
864 result.__filtered__ = true;
865 } else {
866 result = this.clone();
867 result.__dir__ *= -1;
868 }
869 return result;
870 }
871 /**
872 * Extracts the unwrapped value from its lazy wrapper.
873 *
874 * @private
875 * @name value
876 * @memberOf LazyWrapper
877 * @returns {*} Returns the unwrapped value.
878 */
879 function lazyValue() {
880 var array = this.__wrapped__.value(), dir = this.__dir__, isArr = isArray(array), isRight = dir < 0, arrLength = isArr ? array.length : 0, view = getView(0, arrLength, this.__views__), start = view.start, end = view.end, length = end - start, index = isRight ? end : start - 1, iteratees = this.__iteratees__, iterLength = iteratees.length, resIndex = 0, takeCount = nativeMin(length, this.__takeCount__);
881 if (!isArr || arrLength < LARGE_ARRAY_SIZE || arrLength == length && takeCount == length) {
882 return baseWrapperValue(array, this.__actions__);
883 }
884 var result = [];
885 outer:
886 while (length-- && resIndex < takeCount) {
887 index += dir;
888 var iterIndex = -1, value = array[index];
889 while (++iterIndex < iterLength) {
890 var data = iteratees[iterIndex], iteratee = data.iteratee, type = data.type, computed = iteratee(value);
891 if (type == LAZY_MAP_FLAG) {
892 value = computed;
893 } else if (!computed) {
894 if (type == LAZY_FILTER_FLAG) {
895 continue outer;
896 } else {
897 break outer;
898 }
899 }
900 }
901 result[resIndex++] = value;
902 }
903 return result;
904 }
905 /*------------------------------------------------------------------------*/
906 /**
907 * Creates a cache object to store key/value pairs.
908 *
909 * @private
910 * @static
911 * @name Cache
912 * @memberOf _.memoize
913 */
914 function MapCache() {
915 this.__data__ = {};
916 }
917 /**
918 * Removes `key` and its value from the cache.
919 *
920 * @private
921 * @name delete
922 * @memberOf _.memoize.Cache
923 * @param {string} key The key of the value to remove.
924 * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
925 */
926 function mapDelete(key) {
927 return this.has(key) && delete this.__data__[key];
928 }
929 /**
930 * Gets the cached value for `key`.
931 *
932 * @private
933 * @name get
934 * @memberOf _.memoize.Cache
935 * @param {string} key The key of the value to get.
936 * @returns {*} Returns the cached value.
937 */
938 function mapGet(key) {
939 return key == '__proto__' ? undefined : this.__data__[key];
940 }
941 /**
942 * Checks if a cached value for `key` exists.
943 *
944 * @private
945 * @name has
946 * @memberOf _.memoize.Cache
947 * @param {string} key The key of the entry to check.
948 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
949 */
950 function mapHas(key) {
951 return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
952 }
953 /**
954 * Sets `value` to `key` of the cache.
955 *
956 * @private
957 * @name set
958 * @memberOf _.memoize.Cache
959 * @param {string} key The key of the value to cache.
960 * @param {*} value The value to cache.
961 * @returns {Object} Returns the cache object.
962 */
963 function mapSet(key, value) {
964 if (key != '__proto__') {
965 this.__data__[key] = value;
966 }
967 return this;
968 }
969 /*------------------------------------------------------------------------*/
970 /**
971 *
972 * Creates a cache object to store unique values.
973 *
974 * @private
975 * @param {Array} [values] The values to cache.
976 */
977 function SetCache(values) {
978 var length = values ? values.length : 0;
979 this.data = {
980 'hash': nativeCreate(null),
981 'set': new Set()
982 };
983 while (length--) {
984 this.push(values[length]);
985 }
986 }
987 /**
988 * Checks if `value` is in `cache` mimicking the return signature of
989 * `_.indexOf` by returning `0` if the value is found, else `-1`.
990 *
991 * @private
992 * @param {Object} cache The cache to search.
993 * @param {*} value The value to search for.
994 * @returns {number} Returns `0` if `value` is found, else `-1`.
995 */
996 function cacheIndexOf(cache, value) {
997 var data = cache.data, result = typeof value == 'string' || isObject(value) ? data.set.has(value) : data.hash[value];
998 return result ? 0 : -1;
999 }
1000 /**
1001 * Adds `value` to the cache.
1002 *
1003 * @private
1004 * @name push
1005 * @memberOf SetCache
1006 * @param {*} value The value to cache.
1007 */
1008 function cachePush(value) {
1009 var data = this.data;
1010 if (typeof value == 'string' || isObject(value)) {
1011 data.set.add(value);
1012 } else {
1013 data.hash[value] = true;
1014 }
1015 }
1016 /*------------------------------------------------------------------------*/
1017 /**
1018 * Creates a new array joining `array` with `other`.
1019 *
1020 * @private
1021 * @param {Array} array The array to join.
1022 * @param {Array} other The other array to join.
1023 * @returns {Array} Returns the new concatenated array.
1024 */
1025 function arrayConcat(array, other) {
1026 var index = -1, length = array.length, othIndex = -1, othLength = other.length, result = Array(length + othLength);
1027 while (++index < length) {
1028 result[index] = array[index];
1029 }
1030 while (++othIndex < othLength) {
1031 result[index++] = other[othIndex];
1032 }
1033 return result;
1034 }
1035 /**
1036 * Copies the values of `source` to `array`.
1037 *
1038 * @private
1039 * @param {Array} source The array to copy values from.
1040 * @param {Array} [array=[]] The array to copy values to.
1041 * @returns {Array} Returns `array`.
1042 */
1043 function arrayCopy(source, array) {
1044 var index = -1, length = source.length;
1045 array || (array = Array(length));
1046 while (++index < length) {
1047 array[index] = source[index];
1048 }
1049 return array;
1050 }
1051 /**
1052 * A specialized version of `_.forEach` for arrays without support for callback
1053 * shorthands and `this` binding.
1054 *
1055 * @private
1056 * @param {Array} array The array to iterate over.
1057 * @param {Function} iteratee The function invoked per iteration.
1058 * @returns {Array} Returns `array`.
1059 */
1060 function arrayEach(array, iteratee) {
1061 var index = -1, length = array.length;
1062 while (++index < length) {
1063 if (iteratee(array[index], index, array) === false) {
1064 break;
1065 }
1066 }
1067 return array;
1068 }
1069 /**
1070 * A specialized version of `_.forEachRight` for arrays without support for
1071 * callback shorthands and `this` binding.
1072 *
1073 * @private
1074 * @param {Array} array The array to iterate over.
1075 * @param {Function} iteratee The function invoked per iteration.
1076 * @returns {Array} Returns `array`.
1077 */
1078 function arrayEachRight(array, iteratee) {
1079 var length = array.length;
1080 while (length--) {
1081 if (iteratee(array[length], length, array) === false) {
1082 break;
1083 }
1084 }
1085 return array;
1086 }
1087 /**
1088 * A specialized version of `_.every` for arrays without support for callback
1089 * shorthands and `this` binding.
1090 *
1091 * @private
1092 * @param {Array} array The array to iterate over.
1093 * @param {Function} predicate The function invoked per iteration.
1094 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1095 * else `false`.
1096 */
1097 function arrayEvery(array, predicate) {
1098 var index = -1, length = array.length;
1099 while (++index < length) {
1100 if (!predicate(array[index], index, array)) {
1101 return false;
1102 }
1103 }
1104 return true;
1105 }
1106 /**
1107 * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
1108 * with one argument: (value).
1109 *
1110 * @private
1111 * @param {Array} array The array to iterate over.
1112 * @param {Function} iteratee The function invoked per iteration.
1113 * @param {Function} comparator The function used to compare values.
1114 * @param {*} exValue The initial extremum value.
1115 * @returns {*} Returns the extremum value.
1116 */
1117 function arrayExtremum(array, iteratee, comparator, exValue) {
1118 var index = -1, length = array.length, computed = exValue, result = computed;
1119 while (++index < length) {
1120 var value = array[index], current = +iteratee(value);
1121 if (comparator(current, computed)) {
1122 computed = current;
1123 result = value;
1124 }
1125 }
1126 return result;
1127 }
1128 /**
1129 * A specialized version of `_.filter` for arrays without support for callback
1130 * shorthands and `this` binding.
1131 *
1132 * @private
1133 * @param {Array} array The array to iterate over.
1134 * @param {Function} predicate The function invoked per iteration.
1135 * @returns {Array} Returns the new filtered array.
1136 */
1137 function arrayFilter(array, predicate) {
1138 var index = -1, length = array.length, resIndex = -1, result = [];
1139 while (++index < length) {
1140 var value = array[index];
1141 if (predicate(value, index, array)) {
1142 result[++resIndex] = value;
1143 }
1144 }
1145 return result;
1146 }
1147 /**
1148 * A specialized version of `_.map` for arrays without support for callback
1149 * shorthands and `this` binding.
1150 *
1151 * @private
1152 * @param {Array} array The array to iterate over.
1153 * @param {Function} iteratee The function invoked per iteration.
1154 * @returns {Array} Returns the new mapped array.
1155 */
1156 function arrayMap(array, iteratee) {
1157 var index = -1, length = array.length, result = Array(length);
1158 while (++index < length) {
1159 result[index] = iteratee(array[index], index, array);
1160 }
1161 return result;
1162 }
1163 /**
1164 * Appends the elements of `values` to `array`.
1165 *
1166 * @private
1167 * @param {Array} array The array to modify.
1168 * @param {Array} values The values to append.
1169 * @returns {Array} Returns `array`.
1170 */
1171 function arrayPush(array, values) {
1172 var index = -1, length = values.length, offset = array.length;
1173 while (++index < length) {
1174 array[offset + index] = values[index];
1175 }
1176 return array;
1177 }
1178 /**
1179 * A specialized version of `_.reduce` for arrays without support for callback
1180 * shorthands and `this` binding.
1181 *
1182 * @private
1183 * @param {Array} array The array to iterate over.
1184 * @param {Function} iteratee The function invoked per iteration.
1185 * @param {*} [accumulator] The initial value.
1186 * @param {boolean} [initFromArray] Specify using the first element of `array`
1187 * as the initial value.
1188 * @returns {*} Returns the accumulated value.
1189 */
1190 function arrayReduce(array, iteratee, accumulator, initFromArray) {
1191 var index = -1, length = array.length;
1192 if (initFromArray && length) {
1193 accumulator = array[++index];
1194 }
1195 while (++index < length) {
1196 accumulator = iteratee(accumulator, array[index], index, array);
1197 }
1198 return accumulator;
1199 }
1200 /**
1201 * A specialized version of `_.reduceRight` for arrays without support for
1202 * callback shorthands and `this` binding.
1203 *
1204 * @private
1205 * @param {Array} array The array to iterate over.
1206 * @param {Function} iteratee The function invoked per iteration.
1207 * @param {*} [accumulator] The initial value.
1208 * @param {boolean} [initFromArray] Specify using the last element of `array`
1209 * as the initial value.
1210 * @returns {*} Returns the accumulated value.
1211 */
1212 function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
1213 var length = array.length;
1214 if (initFromArray && length) {
1215 accumulator = array[--length];
1216 }
1217 while (length--) {
1218 accumulator = iteratee(accumulator, array[length], length, array);
1219 }
1220 return accumulator;
1221 }
1222 /**
1223 * A specialized version of `_.some` for arrays without support for callback
1224 * shorthands and `this` binding.
1225 *
1226 * @private
1227 * @param {Array} array The array to iterate over.
1228 * @param {Function} predicate The function invoked per iteration.
1229 * @returns {boolean} Returns `true` if any element passes the predicate check,
1230 * else `false`.
1231 */
1232 function arraySome(array, predicate) {
1233 var index = -1, length = array.length;
1234 while (++index < length) {
1235 if (predicate(array[index], index, array)) {
1236 return true;
1237 }
1238 }
1239 return false;
1240 }
1241 /**
1242 * A specialized version of `_.sum` for arrays without support for callback
1243 * shorthands and `this` binding..
1244 *
1245 * @private
1246 * @param {Array} array The array to iterate over.
1247 * @param {Function} iteratee The function invoked per iteration.
1248 * @returns {number} Returns the sum.
1249 */
1250 function arraySum(array, iteratee) {
1251 var length = array.length, result = 0;
1252 while (length--) {
1253 result += +iteratee(array[length]) || 0;
1254 }
1255 return result;
1256 }
1257 /**
1258 * Used by `_.defaults` to customize its `_.assign` use.
1259 *
1260 * @private
1261 * @param {*} objectValue The destination object property value.
1262 * @param {*} sourceValue The source object property value.
1263 * @returns {*} Returns the value to assign to the destination object.
1264 */
1265 function assignDefaults(objectValue, sourceValue) {
1266 return objectValue === undefined ? sourceValue : objectValue;
1267 }
1268 /**
1269 * Used by `_.template` to customize its `_.assign` use.
1270 *
1271 * **Note:** This function is like `assignDefaults` except that it ignores
1272 * inherited property values when checking if a property is `undefined`.
1273 *
1274 * @private
1275 * @param {*} objectValue The destination object property value.
1276 * @param {*} sourceValue The source object property value.
1277 * @param {string} key The key associated with the object and source values.
1278 * @param {Object} object The destination object.
1279 * @returns {*} Returns the value to assign to the destination object.
1280 */
1281 function assignOwnDefaults(objectValue, sourceValue, key, object) {
1282 return objectValue === undefined || !hasOwnProperty.call(object, key) ? sourceValue : objectValue;
1283 }
1284 /**
1285 * A specialized version of `_.assign` for customizing assigned values without
1286 * support for argument juggling, multiple sources, and `this` binding `customizer`
1287 * functions.
1288 *
1289 * @private
1290 * @param {Object} object The destination object.
1291 * @param {Object} source The source object.
1292 * @param {Function} customizer The function to customize assigned values.
1293 * @returns {Object} Returns `object`.
1294 */
1295 function assignWith(object, source, customizer) {
1296 var index = -1, props = keys(source), length = props.length;
1297 while (++index < length) {
1298 var key = props[index], value = object[key], result = customizer(value, source[key], key, object, source);
1299 if ((result === result ? result !== value : value === value) || value === undefined && !(key in object)) {
1300 object[key] = result;
1301 }
1302 }
1303 return object;
1304 }
1305 /**
1306 * The base implementation of `_.assign` without support for argument juggling,
1307 * multiple sources, and `customizer` functions.
1308 *
1309 * @private
1310 * @param {Object} object The destination object.
1311 * @param {Object} source The source object.
1312 * @returns {Object} Returns `object`.
1313 */
1314 function baseAssign(object, source) {
1315 return source == null ? object : baseCopy(source, keys(source), object);
1316 }
1317 /**
1318 * The base implementation of `_.at` without support for string collections
1319 * and individual key arguments.
1320 *
1321 * @private
1322 * @param {Array|Object} collection The collection to iterate over.
1323 * @param {number[]|string[]} props The property names or indexes of elements to pick.
1324 * @returns {Array} Returns the new array of picked elements.
1325 */
1326 function baseAt(collection, props) {
1327 var index = -1, isNil = collection == null, isArr = !isNil && isArrayLike(collection), length = isArr ? collection.length : 0, propsLength = props.length, result = Array(propsLength);
1328 while (++index < propsLength) {
1329 var key = props[index];
1330 if (isArr) {
1331 result[index] = isIndex(key, length) ? collection[key] : undefined;
1332 } else {
1333 result[index] = isNil ? undefined : collection[key];
1334 }
1335 }
1336 return result;
1337 }
1338 /**
1339 * Copies properties of `source` to `object`.
1340 *
1341 * @private
1342 * @param {Object} source The object to copy properties from.
1343 * @param {Array} props The property names to copy.
1344 * @param {Object} [object={}] The object to copy properties to.
1345 * @returns {Object} Returns `object`.
1346 */
1347 function baseCopy(source, props, object) {
1348 object || (object = {});
1349 var index = -1, length = props.length;
1350 while (++index < length) {
1351 var key = props[index];
1352 object[key] = source[key];
1353 }
1354 return object;
1355 }
1356 /**
1357 * The base implementation of `_.callback` which supports specifying the
1358 * number of arguments to provide to `func`.
1359 *
1360 * @private
1361 * @param {*} [func=_.identity] The value to convert to a callback.
1362 * @param {*} [thisArg] The `this` binding of `func`.
1363 * @param {number} [argCount] The number of arguments to provide to `func`.
1364 * @returns {Function} Returns the callback.
1365 */
1366 function baseCallback(func, thisArg, argCount) {
1367 var type = typeof func;
1368 if (type == 'function') {
1369 return thisArg === undefined ? func : bindCallback(func, thisArg, argCount);
1370 }
1371 if (func == null) {
1372 return identity;
1373 }
1374 if (type == 'object') {
1375 return baseMatches(func);
1376 }
1377 return thisArg === undefined ? property(func) : baseMatchesProperty(func, thisArg);
1378 }
1379 /**
1380 * The base implementation of `_.clone` without support for argument juggling
1381 * and `this` binding `customizer` functions.
1382 *
1383 * @private
1384 * @param {*} value The value to clone.
1385 * @param {boolean} [isDeep] Specify a deep clone.
1386 * @param {Function} [customizer] The function to customize cloning values.
1387 * @param {string} [key] The key of `value`.
1388 * @param {Object} [object] The object `value` belongs to.
1389 * @param {Array} [stackA=[]] Tracks traversed source objects.
1390 * @param {Array} [stackB=[]] Associates clones with source counterparts.
1391 * @returns {*} Returns the cloned value.
1392 */
1393 function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
1394 var result;
1395 if (customizer) {
1396 result = object ? customizer(value, key, object) : customizer(value);
1397 }
1398 if (result !== undefined) {
1399 return result;
1400 }
1401 if (!isObject(value)) {
1402 return value;
1403 }
1404 var isArr = isArray(value);
1405 if (isArr) {
1406 result = initCloneArray(value);
1407 if (!isDeep) {
1408 return arrayCopy(value, result);
1409 }
1410 } else {
1411 var tag = objToString.call(value), isFunc = tag == funcTag;
1412 if (tag == objectTag || tag == argsTag || isFunc && !object) {
1413 result = initCloneObject(isFunc ? {} : value);
1414 if (!isDeep) {
1415 return baseAssign(result, value);
1416 }
1417 } else {
1418 return cloneableTags[tag] ? initCloneByTag(value, tag, isDeep) : object ? value : {};
1419 }
1420 }
1421 // Check for circular references and return its corresponding clone.
1422 stackA || (stackA = []);
1423 stackB || (stackB = []);
1424 var length = stackA.length;
1425 while (length--) {
1426 if (stackA[length] == value) {
1427 return stackB[length];
1428 }
1429 }
1430 // Add the source value to the stack of traversed objects and associate it with its clone.
1431 stackA.push(value);
1432 stackB.push(result);
1433 // Recursively populate clone (susceptible to call stack limits).
1434 (isArr ? arrayEach : baseForOwn)(value, function (subValue, key) {
1435 result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
1436 });
1437 return result;
1438 }
1439 /**
1440 * The base implementation of `_.create` without support for assigning
1441 * properties to the created object.
1442 *
1443 * @private
1444 * @param {Object} prototype The object to inherit from.
1445 * @returns {Object} Returns the new object.
1446 */
1447 var baseCreate = function () {
1448 function object() {
1449 }
1450 return function (prototype) {
1451 if (isObject(prototype)) {
1452 object.prototype = prototype;
1453 var result = new object();
1454 object.prototype = undefined;
1455 }
1456 return result || {};
1457 };
1458 }();
1459 /**
1460 * The base implementation of `_.delay` and `_.defer` which accepts an index
1461 * of where to slice the arguments to provide to `func`.
1462 *
1463 * @private
1464 * @param {Function} func The function to delay.
1465 * @param {number} wait The number of milliseconds to delay invocation.
1466 * @param {Object} args The arguments provide to `func`.
1467 * @returns {number} Returns the timer id.
1468 */
1469 function baseDelay(func, wait, args) {
1470 if (typeof func != 'function') {
1471 throw new TypeError(FUNC_ERROR_TEXT);
1472 }
1473 return setTimeout(function () {
1474 func.apply(undefined, args);
1475 }, wait);
1476 }
1477 /**
1478 * The base implementation of `_.difference` which accepts a single array
1479 * of values to exclude.
1480 *
1481 * @private
1482 * @param {Array} array The array to inspect.
1483 * @param {Array} values The values to exclude.
1484 * @returns {Array} Returns the new array of filtered values.
1485 */
1486 function baseDifference(array, values) {
1487 var length = array ? array.length : 0, result = [];
1488 if (!length) {
1489 return result;
1490 }
1491 var index = -1, indexOf = getIndexOf(), isCommon = indexOf === baseIndexOf, cache = isCommon && values.length >= LARGE_ARRAY_SIZE ? createCache(values) : null, valuesLength = values.length;
1492 if (cache) {
1493 indexOf = cacheIndexOf;
1494 isCommon = false;
1495 values = cache;
1496 }
1497 outer:
1498 while (++index < length) {
1499 var value = array[index];
1500 if (isCommon && value === value) {
1501 var valuesIndex = valuesLength;
1502 while (valuesIndex--) {
1503 if (values[valuesIndex] === value) {
1504 continue outer;
1505 }
1506 }
1507 result.push(value);
1508 } else if (indexOf(values, value, 0) < 0) {
1509 result.push(value);
1510 }
1511 }
1512 return result;
1513 }
1514 /**
1515 * The base implementation of `_.forEach` without support for callback
1516 * shorthands and `this` binding.
1517 *
1518 * @private
1519 * @param {Array|Object|string} collection The collection to iterate over.
1520 * @param {Function} iteratee The function invoked per iteration.
1521 * @returns {Array|Object|string} Returns `collection`.
1522 */
1523 var baseEach = createBaseEach(baseForOwn);
1524 /**
1525 * The base implementation of `_.forEachRight` without support for callback
1526 * shorthands and `this` binding.
1527 *
1528 * @private
1529 * @param {Array|Object|string} collection The collection to iterate over.
1530 * @param {Function} iteratee The function invoked per iteration.
1531 * @returns {Array|Object|string} Returns `collection`.
1532 */
1533 var baseEachRight = createBaseEach(baseForOwnRight, true);
1534 /**
1535 * The base implementation of `_.every` without support for callback
1536 * shorthands and `this` binding.
1537 *
1538 * @private
1539 * @param {Array|Object|string} collection The collection to iterate over.
1540 * @param {Function} predicate The function invoked per iteration.
1541 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1542 * else `false`
1543 */
1544 function baseEvery(collection, predicate) {
1545 var result = true;
1546 baseEach(collection, function (value, index, collection) {
1547 result = !!predicate(value, index, collection);
1548 return result;
1549 });
1550 return result;
1551 }
1552 /**
1553 * Gets the extremum value of `collection` invoking `iteratee` for each value
1554 * in `collection` to generate the criterion by which the value is ranked.
1555 * The `iteratee` is invoked with three arguments: (value, index|key, collection).
1556 *
1557 * @private
1558 * @param {Array|Object|string} collection The collection to iterate over.
1559 * @param {Function} iteratee The function invoked per iteration.
1560 * @param {Function} comparator The function used to compare values.
1561 * @param {*} exValue The initial extremum value.
1562 * @returns {*} Returns the extremum value.
1563 */
1564 function baseExtremum(collection, iteratee, comparator, exValue) {
1565 var computed = exValue, result = computed;
1566 baseEach(collection, function (value, index, collection) {
1567 var current = +iteratee(value, index, collection);
1568 if (comparator(current, computed) || current === exValue && current === result) {
1569 computed = current;
1570 result = value;
1571 }
1572 });
1573 return result;
1574 }
1575 /**
1576 * The base implementation of `_.fill` without an iteratee call guard.
1577 *
1578 * @private
1579 * @param {Array} array The array to fill.
1580 * @param {*} value The value to fill `array` with.
1581 * @param {number} [start=0] The start position.
1582 * @param {number} [end=array.length] The end position.
1583 * @returns {Array} Returns `array`.
1584 */
1585 function baseFill(array, value, start, end) {
1586 var length = array.length;
1587 start = start == null ? 0 : +start || 0;
1588 if (start < 0) {
1589 start = -start > length ? 0 : length + start;
1590 }
1591 end = end === undefined || end > length ? length : +end || 0;
1592 if (end < 0) {
1593 end += length;
1594 }
1595 length = start > end ? 0 : end >>> 0;
1596 start >>>= 0;
1597 while (start < length) {
1598 array[start++] = value;
1599 }
1600 return array;
1601 }
1602 /**
1603 * The base implementation of `_.filter` without support for callback
1604 * shorthands and `this` binding.
1605 *
1606 * @private
1607 * @param {Array|Object|string} collection The collection to iterate over.
1608 * @param {Function} predicate The function invoked per iteration.
1609 * @returns {Array} Returns the new filtered array.
1610 */
1611 function baseFilter(collection, predicate) {
1612 var result = [];
1613 baseEach(collection, function (value, index, collection) {
1614 if (predicate(value, index, collection)) {
1615 result.push(value);
1616 }
1617 });
1618 return result;
1619 }
1620 /**
1621 * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
1622 * without support for callback shorthands and `this` binding, which iterates
1623 * over `collection` using the provided `eachFunc`.
1624 *
1625 * @private
1626 * @param {Array|Object|string} collection The collection to search.
1627 * @param {Function} predicate The function invoked per iteration.
1628 * @param {Function} eachFunc The function to iterate over `collection`.
1629 * @param {boolean} [retKey] Specify returning the key of the found element
1630 * instead of the element itself.
1631 * @returns {*} Returns the found element or its key, else `undefined`.
1632 */
1633 function baseFind(collection, predicate, eachFunc, retKey) {
1634 var result;
1635 eachFunc(collection, function (value, key, collection) {
1636 if (predicate(value, key, collection)) {
1637 result = retKey ? key : value;
1638 return false;
1639 }
1640 });
1641 return result;
1642 }
1643 /**
1644 * The base implementation of `_.flatten` with added support for restricting
1645 * flattening and specifying the start index.
1646 *
1647 * @private
1648 * @param {Array} array The array to flatten.
1649 * @param {boolean} [isDeep] Specify a deep flatten.
1650 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
1651 * @param {Array} [result=[]] The initial result value.
1652 * @returns {Array} Returns the new flattened array.
1653 */
1654 function baseFlatten(array, isDeep, isStrict, result) {
1655 result || (result = []);
1656 var index = -1, length = array.length;
1657 while (++index < length) {
1658 var value = array[index];
1659 if (isObjectLike(value) && isArrayLike(value) && (isStrict || isArray(value) || isArguments(value))) {
1660 if (isDeep) {
1661 // Recursively flatten arrays (susceptible to call stack limits).
1662 baseFlatten(value, isDeep, isStrict, result);
1663 } else {
1664 arrayPush(result, value);
1665 }
1666 } else if (!isStrict) {
1667 result[result.length] = value;
1668 }
1669 }
1670 return result;
1671 }
1672 /**
1673 * The base implementation of `baseForIn` and `baseForOwn` which iterates
1674 * over `object` properties returned by `keysFunc` invoking `iteratee` for
1675 * each property. Iteratee functions may exit iteration early by explicitly
1676 * returning `false`.
1677 *
1678 * @private
1679 * @param {Object} object The object to iterate over.
1680 * @param {Function} iteratee The function invoked per iteration.
1681 * @param {Function} keysFunc The function to get the keys of `object`.
1682 * @returns {Object} Returns `object`.
1683 */
1684 var baseFor = createBaseFor();
1685 /**
1686 * This function is like `baseFor` except that it iterates over properties
1687 * in the opposite order.
1688 *
1689 * @private
1690 * @param {Object} object The object to iterate over.
1691 * @param {Function} iteratee The function invoked per iteration.
1692 * @param {Function} keysFunc The function to get the keys of `object`.
1693 * @returns {Object} Returns `object`.
1694 */
1695 var baseForRight = createBaseFor(true);
1696 /**
1697 * The base implementation of `_.forIn` without support for callback
1698 * shorthands and `this` binding.
1699 *
1700 * @private
1701 * @param {Object} object The object to iterate over.
1702 * @param {Function} iteratee The function invoked per iteration.
1703 * @returns {Object} Returns `object`.
1704 */
1705 function baseForIn(object, iteratee) {
1706 return baseFor(object, iteratee, keysIn);
1707 }
1708 /**
1709 * The base implementation of `_.forOwn` without support for callback
1710 * shorthands and `this` binding.
1711 *
1712 * @private
1713 * @param {Object} object The object to iterate over.
1714 * @param {Function} iteratee The function invoked per iteration.
1715 * @returns {Object} Returns `object`.
1716 */
1717 function baseForOwn(object, iteratee) {
1718 return baseFor(object, iteratee, keys);
1719 }
1720 /**
1721 * The base implementation of `_.forOwnRight` without support for callback
1722 * shorthands and `this` binding.
1723 *
1724 * @private
1725 * @param {Object} object The object to iterate over.
1726 * @param {Function} iteratee The function invoked per iteration.
1727 * @returns {Object} Returns `object`.
1728 */
1729 function baseForOwnRight(object, iteratee) {
1730 return baseForRight(object, iteratee, keys);
1731 }
1732 /**
1733 * The base implementation of `_.functions` which creates an array of
1734 * `object` function property names filtered from those provided.
1735 *
1736 * @private
1737 * @param {Object} object The object to inspect.
1738 * @param {Array} props The property names to filter.
1739 * @returns {Array} Returns the new array of filtered property names.
1740 */
1741 function baseFunctions(object, props) {
1742 var index = -1, length = props.length, resIndex = -1, result = [];
1743 while (++index < length) {
1744 var key = props[index];
1745 if (isFunction(object[key])) {
1746 result[++resIndex] = key;
1747 }
1748 }
1749 return result;
1750 }
1751 /**
1752 * The base implementation of `get` without support for string paths
1753 * and default values.
1754 *
1755 * @private
1756 * @param {Object} object The object to query.
1757 * @param {Array} path The path of the property to get.
1758 * @param {string} [pathKey] The key representation of path.
1759 * @returns {*} Returns the resolved value.
1760 */
1761 function baseGet(object, path, pathKey) {
1762 if (object == null) {
1763 return;
1764 }
1765 if (pathKey !== undefined && pathKey in toObject(object)) {
1766 path = [pathKey];
1767 }
1768 var index = 0, length = path.length;
1769 while (object != null && index < length) {
1770 object = object[path[index++]];
1771 }
1772 return index && index == length ? object : undefined;
1773 }
1774 /**
1775 * The base implementation of `_.isEqual` without support for `this` binding
1776 * `customizer` functions.
1777 *
1778 * @private
1779 * @param {*} value The value to compare.
1780 * @param {*} other The other value to compare.
1781 * @param {Function} [customizer] The function to customize comparing values.
1782 * @param {boolean} [isLoose] Specify performing partial comparisons.
1783 * @param {Array} [stackA] Tracks traversed `value` objects.
1784 * @param {Array} [stackB] Tracks traversed `other` objects.
1785 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1786 */
1787 function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
1788 if (value === other) {
1789 return true;
1790 }
1791 if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
1792 return value !== value && other !== other;
1793 }
1794 return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
1795 }
1796 /**
1797 * A specialized version of `baseIsEqual` for arrays and objects which performs
1798 * deep comparisons and tracks traversed objects enabling objects with circular
1799 * references to be compared.
1800 *
1801 * @private
1802 * @param {Object} object The object to compare.
1803 * @param {Object} other The other object to compare.
1804 * @param {Function} equalFunc The function to determine equivalents of values.
1805 * @param {Function} [customizer] The function to customize comparing objects.
1806 * @param {boolean} [isLoose] Specify performing partial comparisons.
1807 * @param {Array} [stackA=[]] Tracks traversed `value` objects.
1808 * @param {Array} [stackB=[]] Tracks traversed `other` objects.
1809 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1810 */
1811 function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
1812 var objIsArr = isArray(object), othIsArr = isArray(other), objTag = arrayTag, othTag = arrayTag;
1813 if (!objIsArr) {
1814 objTag = objToString.call(object);
1815 if (objTag == argsTag) {
1816 objTag = objectTag;
1817 } else if (objTag != objectTag) {
1818 objIsArr = isTypedArray(object);
1819 }
1820 }
1821 if (!othIsArr) {
1822 othTag = objToString.call(other);
1823 if (othTag == argsTag) {
1824 othTag = objectTag;
1825 } else if (othTag != objectTag) {
1826 othIsArr = isTypedArray(other);
1827 }
1828 }
1829 var objIsObj = objTag == objectTag, othIsObj = othTag == objectTag, isSameTag = objTag == othTag;
1830 if (isSameTag && !(objIsArr || objIsObj)) {
1831 return equalByTag(object, other, objTag);
1832 }
1833 if (!isLoose) {
1834 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
1835 if (objIsWrapped || othIsWrapped) {
1836 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
1837 }
1838 }
1839 if (!isSameTag) {
1840 return false;
1841 }
1842 // Assume cyclic values are equal.
1843 // For more information on detecting circular references see https://es5.github.io/#JO.
1844 stackA || (stackA = []);
1845 stackB || (stackB = []);
1846 var length = stackA.length;
1847 while (length--) {
1848 if (stackA[length] == object) {
1849 return stackB[length] == other;
1850 }
1851 }
1852 // Add `object` and `other` to the stack of traversed objects.
1853 stackA.push(object);
1854 stackB.push(other);
1855 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
1856 stackA.pop();
1857 stackB.pop();
1858 return result;
1859 }
1860 /**
1861 * The base implementation of `_.isMatch` without support for callback
1862 * shorthands and `this` binding.
1863 *
1864 * @private
1865 * @param {Object} object The object to inspect.
1866 * @param {Array} matchData The propery names, values, and compare flags to match.
1867 * @param {Function} [customizer] The function to customize comparing objects.
1868 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
1869 */
1870 function baseIsMatch(object, matchData, customizer) {
1871 var index = matchData.length, length = index, noCustomizer = !customizer;
1872 if (object == null) {
1873 return !length;
1874 }
1875 object = toObject(object);
1876 while (index--) {
1877 var data = matchData[index];
1878 if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
1879 return false;
1880 }
1881 }
1882 while (++index < length) {
1883 data = matchData[index];
1884 var key = data[0], objValue = object[key], srcValue = data[1];
1885 if (noCustomizer && data[2]) {
1886 if (objValue === undefined && !(key in object)) {
1887 return false;
1888 }
1889 } else {
1890 var result = customizer ? customizer(objValue, srcValue, key) : undefined;
1891 if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
1892 return false;
1893 }
1894 }
1895 }
1896 return true;
1897 }
1898 /**
1899 * The base implementation of `_.map` without support for callback shorthands
1900 * and `this` binding.
1901 *
1902 * @private
1903 * @param {Array|Object|string} collection The collection to iterate over.
1904 * @param {Function} iteratee The function invoked per iteration.
1905 * @returns {Array} Returns the new mapped array.
1906 */
1907 function baseMap(collection, iteratee) {
1908 var index = -1, result = isArrayLike(collection) ? Array(collection.length) : [];
1909 baseEach(collection, function (value, key, collection) {
1910 result[++index] = iteratee(value, key, collection);
1911 });
1912 return result;
1913 }
1914 /**
1915 * The base implementation of `_.matches` which does not clone `source`.
1916 *
1917 * @private
1918 * @param {Object} source The object of property values to match.
1919 * @returns {Function} Returns the new function.
1920 */
1921 function baseMatches(source) {
1922 var matchData = getMatchData(source);
1923 if (matchData.length == 1 && matchData[0][2]) {
1924 var key = matchData[0][0], value = matchData[0][1];
1925 return function (object) {
1926 if (object == null) {
1927 return false;
1928 }
1929 return object[key] === value && (value !== undefined || key in toObject(object));
1930 };
1931 }
1932 return function (object) {
1933 return baseIsMatch(object, matchData);
1934 };
1935 }
1936 /**
1937 * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
1938 *
1939 * @private
1940 * @param {string} path The path of the property to get.
1941 * @param {*} srcValue The value to compare.
1942 * @returns {Function} Returns the new function.
1943 */
1944 function baseMatchesProperty(path, srcValue) {
1945 var isArr = isArray(path), isCommon = isKey(path) && isStrictComparable(srcValue), pathKey = path + '';
1946 path = toPath(path);
1947 return function (object) {
1948 if (object == null) {
1949 return false;
1950 }
1951 var key = pathKey;
1952 object = toObject(object);
1953 if ((isArr || !isCommon) && !(key in object)) {
1954 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
1955 if (object == null) {
1956 return false;
1957 }
1958 key = last(path);
1959 object = toObject(object);
1960 }
1961 return object[key] === srcValue ? srcValue !== undefined || key in object : baseIsEqual(srcValue, object[key], undefined, true);
1962 };
1963 }
1964 /**
1965 * The base implementation of `_.merge` without support for argument juggling,
1966 * multiple sources, and `this` binding `customizer` functions.
1967 *
1968 * @private
1969 * @param {Object} object The destination object.
1970 * @param {Object} source The source object.
1971 * @param {Function} [customizer] The function to customize merged values.
1972 * @param {Array} [stackA=[]] Tracks traversed source objects.
1973 * @param {Array} [stackB=[]] Associates values with source counterparts.
1974 * @returns {Object} Returns `object`.
1975 */
1976 function baseMerge(object, source, customizer, stackA, stackB) {
1977 if (!isObject(object)) {
1978 return object;
1979 }
1980 var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)), props = isSrcArr ? undefined : keys(source);
1981 arrayEach(props || source, function (srcValue, key) {
1982 if (props) {
1983 key = srcValue;
1984 srcValue = source[key];
1985 }
1986 if (isObjectLike(srcValue)) {
1987 stackA || (stackA = []);
1988 stackB || (stackB = []);
1989 baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
1990 } else {
1991 var value = object[key], result = customizer ? customizer(value, srcValue, key, object, source) : undefined, isCommon = result === undefined;
1992 if (isCommon) {
1993 result = srcValue;
1994 }
1995 if ((result !== undefined || isSrcArr && !(key in object)) && (isCommon || (result === result ? result !== value : value === value))) {
1996 object[key] = result;
1997 }
1998 }
1999 });
2000 return object;
2001 }
2002 /**
2003 * A specialized version of `baseMerge` for arrays and objects which performs
2004 * deep merges and tracks traversed objects enabling objects with circular
2005 * references to be merged.
2006 *
2007 * @private
2008 * @param {Object} object The destination object.
2009 * @param {Object} source The source object.
2010 * @param {string} key The key of the value to merge.
2011 * @param {Function} mergeFunc The function to merge values.
2012 * @param {Function} [customizer] The function to customize merged values.
2013 * @param {Array} [stackA=[]] Tracks traversed source objects.
2014 * @param {Array} [stackB=[]] Associates values with source counterparts.
2015 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2016 */
2017 function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
2018 var length = stackA.length, srcValue = source[key];
2019 while (length--) {
2020 if (stackA[length] == srcValue) {
2021 object[key] = stackB[length];
2022 return;
2023 }
2024 }
2025 var value = object[key], result = customizer ? customizer(value, srcValue, key, object, source) : undefined, isCommon = result === undefined;
2026 if (isCommon) {
2027 result = srcValue;
2028 if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
2029 result = isArray(value) ? value : isArrayLike(value) ? arrayCopy(value) : [];
2030 } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
2031 result = isArguments(value) ? toPlainObject(value) : isPlainObject(value) ? value : {};
2032 } else {
2033 isCommon = false;
2034 }
2035 }
2036 // Add the source value to the stack of traversed objects and associate
2037 // it with its merged value.
2038 stackA.push(srcValue);
2039 stackB.push(result);
2040 if (isCommon) {
2041 // Recursively merge objects and arrays (susceptible to call stack limits).
2042 object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
2043 } else if (result === result ? result !== value : value === value) {
2044 object[key] = result;
2045 }
2046 }
2047 /**
2048 * The base implementation of `_.property` without support for deep paths.
2049 *
2050 * @private
2051 * @param {string} key The key of the property to get.
2052 * @returns {Function} Returns the new function.
2053 */
2054 function baseProperty(key) {
2055 return function (object) {
2056 return object == null ? undefined : object[key];
2057 };
2058 }
2059 /**
2060 * A specialized version of `baseProperty` which supports deep paths.
2061 *
2062 * @private
2063 * @param {Array|string} path The path of the property to get.
2064 * @returns {Function} Returns the new function.
2065 */
2066 function basePropertyDeep(path) {
2067 var pathKey = path + '';
2068 path = toPath(path);
2069 return function (object) {
2070 return baseGet(object, path, pathKey);
2071 };
2072 }
2073 /**
2074 * The base implementation of `_.pullAt` without support for individual
2075 * index arguments and capturing the removed elements.
2076 *
2077 * @private
2078 * @param {Array} array The array to modify.
2079 * @param {number[]} indexes The indexes of elements to remove.
2080 * @returns {Array} Returns `array`.
2081 */
2082 function basePullAt(array, indexes) {
2083 var length = array ? indexes.length : 0;
2084 while (length--) {
2085 var index = indexes[length];
2086 if (index != previous && isIndex(index)) {
2087 var previous = index;
2088 splice.call(array, index, 1);
2089 }
2090 }
2091 return array;
2092 }
2093 /**
2094 * The base implementation of `_.random` without support for argument juggling
2095 * and returning floating-point numbers.
2096 *
2097 * @private
2098 * @param {number} min The minimum possible value.
2099 * @param {number} max The maximum possible value.
2100 * @returns {number} Returns the random number.
2101 */
2102 function baseRandom(min, max) {
2103 return min + nativeFloor(nativeRandom() * (max - min + 1));
2104 }
2105 /**
2106 * The base implementation of `_.reduce` and `_.reduceRight` without support
2107 * for callback shorthands and `this` binding, which iterates over `collection`
2108 * using the provided `eachFunc`.
2109 *
2110 * @private
2111 * @param {Array|Object|string} collection The collection to iterate over.
2112 * @param {Function} iteratee The function invoked per iteration.
2113 * @param {*} accumulator The initial value.
2114 * @param {boolean} initFromCollection Specify using the first or last element
2115 * of `collection` as the initial value.
2116 * @param {Function} eachFunc The function to iterate over `collection`.
2117 * @returns {*} Returns the accumulated value.
2118 */
2119 function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
2120 eachFunc(collection, function (value, index, collection) {
2121 accumulator = initFromCollection ? (initFromCollection = false, value) : iteratee(accumulator, value, index, collection);
2122 });
2123 return accumulator;
2124 }
2125 /**
2126 * The base implementation of `setData` without support for hot loop detection.
2127 *
2128 * @private
2129 * @param {Function} func The function to associate metadata with.
2130 * @param {*} data The metadata.
2131 * @returns {Function} Returns `func`.
2132 */
2133 var baseSetData = !metaMap ? identity : function (func, data) {
2134 metaMap.set(func, data);
2135 return func;
2136 };
2137 /**
2138 * The base implementation of `_.slice` without an iteratee call guard.
2139 *
2140 * @private
2141 * @param {Array} array The array to slice.
2142 * @param {number} [start=0] The start position.
2143 * @param {number} [end=array.length] The end position.
2144 * @returns {Array} Returns the slice of `array`.
2145 */
2146 function baseSlice(array, start, end) {
2147 var index = -1, length = array.length;
2148 start = start == null ? 0 : +start || 0;
2149 if (start < 0) {
2150 start = -start > length ? 0 : length + start;
2151 }
2152 end = end === undefined || end > length ? length : +end || 0;
2153 if (end < 0) {
2154 end += length;
2155 }
2156 length = start > end ? 0 : end - start >>> 0;
2157 start >>>= 0;
2158 var result = Array(length);
2159 while (++index < length) {
2160 result[index] = array[index + start];
2161 }
2162 return result;
2163 }
2164 /**
2165 * The base implementation of `_.some` without support for callback shorthands
2166 * and `this` binding.
2167 *
2168 * @private
2169 * @param {Array|Object|string} collection The collection to iterate over.
2170 * @param {Function} predicate The function invoked per iteration.
2171 * @returns {boolean} Returns `true` if any element passes the predicate check,
2172 * else `false`.
2173 */
2174 function baseSome(collection, predicate) {
2175 var result;
2176 baseEach(collection, function (value, index, collection) {
2177 result = predicate(value, index, collection);
2178 return !result;
2179 });
2180 return !!result;
2181 }
2182 /**
2183 * The base implementation of `_.sortBy` which uses `comparer` to define
2184 * the sort order of `array` and replaces criteria objects with their
2185 * corresponding values.
2186 *
2187 * @private
2188 * @param {Array} array The array to sort.
2189 * @param {Function} comparer The function to define sort order.
2190 * @returns {Array} Returns `array`.
2191 */
2192 function baseSortBy(array, comparer) {
2193 var length = array.length;
2194 array.sort(comparer);
2195 while (length--) {
2196 array[length] = array[length].value;
2197 }
2198 return array;
2199 }
2200 /**
2201 * The base implementation of `_.sortByOrder` without param guards.
2202 *
2203 * @private
2204 * @param {Array|Object|string} collection The collection to iterate over.
2205 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
2206 * @param {boolean[]} orders The sort orders of `iteratees`.
2207 * @returns {Array} Returns the new sorted array.
2208 */
2209 function baseSortByOrder(collection, iteratees, orders) {
2210 var callback = getCallback(), index = -1;
2211 iteratees = arrayMap(iteratees, function (iteratee) {
2212 return callback(iteratee);
2213 });
2214 var result = baseMap(collection, function (value) {
2215 var criteria = arrayMap(iteratees, function (iteratee) {
2216 return iteratee(value);
2217 });
2218 return {
2219 'criteria': criteria,
2220 'index': ++index,
2221 'value': value
2222 };
2223 });
2224 return baseSortBy(result, function (object, other) {
2225 return compareMultiple(object, other, orders);
2226 });
2227 }
2228 /**
2229 * The base implementation of `_.sum` without support for callback shorthands
2230 * and `this` binding.
2231 *
2232 * @private
2233 * @param {Array|Object|string} collection The collection to iterate over.
2234 * @param {Function} iteratee The function invoked per iteration.
2235 * @returns {number} Returns the sum.
2236 */
2237 function baseSum(collection, iteratee) {
2238 var result = 0;
2239 baseEach(collection, function (value, index, collection) {
2240 result += +iteratee(value, index, collection) || 0;
2241 });
2242 return result;
2243 }
2244 /**
2245 * The base implementation of `_.uniq` without support for callback shorthands
2246 * and `this` binding.
2247 *
2248 * @private
2249 * @param {Array} array The array to inspect.
2250 * @param {Function} [iteratee] The function invoked per iteration.
2251 * @returns {Array} Returns the new duplicate free array.
2252 */
2253 function baseUniq(array, iteratee) {
2254 var index = -1, indexOf = getIndexOf(), length = array.length, isCommon = indexOf === baseIndexOf, isLarge = isCommon && length >= LARGE_ARRAY_SIZE, seen = isLarge ? createCache() : null, result = [];
2255 if (seen) {
2256 indexOf = cacheIndexOf;
2257 isCommon = false;
2258 } else {
2259 isLarge = false;
2260 seen = iteratee ? [] : result;
2261 }
2262 outer:
2263 while (++index < length) {
2264 var value = array[index], computed = iteratee ? iteratee(value, index, array) : value;
2265 if (isCommon && value === value) {
2266 var seenIndex = seen.length;
2267 while (seenIndex--) {
2268 if (seen[seenIndex] === computed) {
2269 continue outer;
2270 }
2271 }
2272 if (iteratee) {
2273 seen.push(computed);
2274 }
2275 result.push(value);
2276 } else if (indexOf(seen, computed, 0) < 0) {
2277 if (iteratee || isLarge) {
2278 seen.push(computed);
2279 }
2280 result.push(value);
2281 }
2282 }
2283 return result;
2284 }
2285 /**
2286 * The base implementation of `_.values` and `_.valuesIn` which creates an
2287 * array of `object` property values corresponding to the property names
2288 * of `props`.
2289 *
2290 * @private
2291 * @param {Object} object The object to query.
2292 * @param {Array} props The property names to get values for.
2293 * @returns {Object} Returns the array of property values.
2294 */
2295 function baseValues(object, props) {
2296 var index = -1, length = props.length, result = Array(length);
2297 while (++index < length) {
2298 result[index] = object[props[index]];
2299 }
2300 return result;
2301 }
2302 /**
2303 * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
2304 * and `_.takeWhile` without support for callback shorthands and `this` binding.
2305 *
2306 * @private
2307 * @param {Array} array The array to query.
2308 * @param {Function} predicate The function invoked per iteration.
2309 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
2310 * @param {boolean} [fromRight] Specify iterating from right to left.
2311 * @returns {Array} Returns the slice of `array`.
2312 */
2313 function baseWhile(array, predicate, isDrop, fromRight) {
2314 var length = array.length, index = fromRight ? length : -1;
2315 while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {
2316 }
2317 return isDrop ? baseSlice(array, fromRight ? 0 : index, fromRight ? index + 1 : length) : baseSlice(array, fromRight ? index + 1 : 0, fromRight ? length : index);
2318 }
2319 /**
2320 * The base implementation of `wrapperValue` which returns the result of
2321 * performing a sequence of actions on the unwrapped `value`, where each
2322 * successive action is supplied the return value of the previous.
2323 *
2324 * @private
2325 * @param {*} value The unwrapped value.
2326 * @param {Array} actions Actions to peform to resolve the unwrapped value.
2327 * @returns {*} Returns the resolved value.
2328 */
2329 function baseWrapperValue(value, actions) {
2330 var result = value;
2331 if (result instanceof LazyWrapper) {
2332 result = result.value();
2333 }
2334 var index = -1, length = actions.length;
2335 while (++index < length) {
2336 var action = actions[index];
2337 result = action.func.apply(action.thisArg, arrayPush([result], action.args));
2338 }
2339 return result;
2340 }
2341 /**
2342 * Performs a binary search of `array` to determine the index at which `value`
2343 * should be inserted into `array` in order to maintain its sort order.
2344 *
2345 * @private
2346 * @param {Array} array The sorted array to inspect.
2347 * @param {*} value The value to evaluate.
2348 * @param {boolean} [retHighest] Specify returning the highest qualified index.
2349 * @returns {number} Returns the index at which `value` should be inserted
2350 * into `array`.
2351 */
2352 function binaryIndex(array, value, retHighest) {
2353 var low = 0, high = array ? array.length : low;
2354 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
2355 while (low < high) {
2356 var mid = low + high >>> 1, computed = array[mid];
2357 if ((retHighest ? computed <= value : computed < value) && computed !== null) {
2358 low = mid + 1;
2359 } else {
2360 high = mid;
2361 }
2362 }
2363 return high;
2364 }
2365 return binaryIndexBy(array, value, identity, retHighest);
2366 }
2367 /**
2368 * This function is like `binaryIndex` except that it invokes `iteratee` for
2369 * `value` and each element of `array` to compute their sort ranking. The
2370 * iteratee is invoked with one argument; (value).
2371 *
2372 * @private
2373 * @param {Array} array The sorted array to inspect.
2374 * @param {*} value The value to evaluate.
2375 * @param {Function} iteratee The function invoked per iteration.
2376 * @param {boolean} [retHighest] Specify returning the highest qualified index.
2377 * @returns {number} Returns the index at which `value` should be inserted
2378 * into `array`.
2379 */
2380 function binaryIndexBy(array, value, iteratee, retHighest) {
2381 value = iteratee(value);
2382 var low = 0, high = array ? array.length : 0, valIsNaN = value !== value, valIsNull = value === null, valIsUndef = value === undefined;
2383 while (low < high) {
2384 var mid = nativeFloor((low + high) / 2), computed = iteratee(array[mid]), isDef = computed !== undefined, isReflexive = computed === computed;
2385 if (valIsNaN) {
2386 var setLow = isReflexive || retHighest;
2387 } else if (valIsNull) {
2388 setLow = isReflexive && isDef && (retHighest || computed != null);
2389 } else if (valIsUndef) {
2390 setLow = isReflexive && (retHighest || isDef);
2391 } else if (computed == null) {
2392 setLow = false;
2393 } else {
2394 setLow = retHighest ? computed <= value : computed < value;
2395 }
2396 if (setLow) {
2397 low = mid + 1;
2398 } else {
2399 high = mid;
2400 }
2401 }
2402 return nativeMin(high, MAX_ARRAY_INDEX);
2403 }
2404 /**
2405 * A specialized version of `baseCallback` which only supports `this` binding
2406 * and specifying the number of arguments to provide to `func`.
2407 *
2408 * @private
2409 * @param {Function} func The function to bind.
2410 * @param {*} thisArg The `this` binding of `func`.
2411 * @param {number} [argCount] The number of arguments to provide to `func`.
2412 * @returns {Function} Returns the callback.
2413 */
2414 function bindCallback(func, thisArg, argCount) {
2415 if (typeof func != 'function') {
2416 return identity;
2417 }
2418 if (thisArg === undefined) {
2419 return func;
2420 }
2421 switch (argCount) {
2422 case 1:
2423 return function (value) {
2424 return func.call(thisArg, value);
2425 };
2426 case 3:
2427 return function (value, index, collection) {
2428 return func.call(thisArg, value, index, collection);
2429 };
2430 case 4:
2431 return function (accumulator, value, index, collection) {
2432 return func.call(thisArg, accumulator, value, index, collection);
2433 };
2434 case 5:
2435 return function (value, other, key, object, source) {
2436 return func.call(thisArg, value, other, key, object, source);
2437 };
2438 }
2439 return function () {
2440 return func.apply(thisArg, arguments);
2441 };
2442 }
2443 /**
2444 * Creates a clone of the given array buffer.
2445 *
2446 * @private
2447 * @param {ArrayBuffer} buffer The array buffer to clone.
2448 * @returns {ArrayBuffer} Returns the cloned array buffer.
2449 */
2450 function bufferClone(buffer) {
2451 var result = new ArrayBuffer(buffer.byteLength), view = new Uint8Array(result);
2452 view.set(new Uint8Array(buffer));
2453 return result;
2454 }
2455 /**
2456 * Creates an array that is the composition of partially applied arguments,
2457 * placeholders, and provided arguments into a single array of arguments.
2458 *
2459 * @private
2460 * @param {Array|Object} args The provided arguments.
2461 * @param {Array} partials The arguments to prepend to those provided.
2462 * @param {Array} holders The `partials` placeholder indexes.
2463 * @returns {Array} Returns the new array of composed arguments.
2464 */
2465 function composeArgs(args, partials, holders) {
2466 var holdersLength = holders.length, argsIndex = -1, argsLength = nativeMax(args.length - holdersLength, 0), leftIndex = -1, leftLength = partials.length, result = Array(leftLength + argsLength);
2467 while (++leftIndex < leftLength) {
2468 result[leftIndex] = partials[leftIndex];
2469 }
2470 while (++argsIndex < holdersLength) {
2471 result[holders[argsIndex]] = args[argsIndex];
2472 }
2473 while (argsLength--) {
2474 result[leftIndex++] = args[argsIndex++];
2475 }
2476 return result;
2477 }
2478 /**
2479 * This function is like `composeArgs` except that the arguments composition
2480 * is tailored for `_.partialRight`.
2481 *
2482 * @private
2483 * @param {Array|Object} args The provided arguments.
2484 * @param {Array} partials The arguments to append to those provided.
2485 * @param {Array} holders The `partials` placeholder indexes.
2486 * @returns {Array} Returns the new array of composed arguments.
2487 */
2488 function composeArgsRight(args, partials, holders) {
2489 var holdersIndex = -1, holdersLength = holders.length, argsIndex = -1, argsLength = nativeMax(args.length - holdersLength, 0), rightIndex = -1, rightLength = partials.length, result = Array(argsLength + rightLength);
2490 while (++argsIndex < argsLength) {
2491 result[argsIndex] = args[argsIndex];
2492 }
2493 var offset = argsIndex;
2494 while (++rightIndex < rightLength) {
2495 result[offset + rightIndex] = partials[rightIndex];
2496 }
2497 while (++holdersIndex < holdersLength) {
2498 result[offset + holders[holdersIndex]] = args[argsIndex++];
2499 }
2500 return result;
2501 }
2502 /**
2503 * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
2504 *
2505 * @private
2506 * @param {Function} setter The function to set keys and values of the accumulator object.
2507 * @param {Function} [initializer] The function to initialize the accumulator object.
2508 * @returns {Function} Returns the new aggregator function.
2509 */
2510 function createAggregator(setter, initializer) {
2511 return function (collection, iteratee, thisArg) {
2512 var result = initializer ? initializer() : {};
2513 iteratee = getCallback(iteratee, thisArg, 3);
2514 if (isArray(collection)) {
2515 var index = -1, length = collection.length;
2516 while (++index < length) {
2517 var value = collection[index];
2518 setter(result, value, iteratee(value, index, collection), collection);
2519 }
2520 } else {
2521 baseEach(collection, function (value, key, collection) {
2522 setter(result, value, iteratee(value, key, collection), collection);
2523 });
2524 }
2525 return result;
2526 };
2527 }
2528 /**
2529 * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
2530 *
2531 * @private
2532 * @param {Function} assigner The function to assign values.
2533 * @returns {Function} Returns the new assigner function.
2534 */
2535 function createAssigner(assigner) {
2536 return restParam(function (object, sources) {
2537 var index = -1, length = object == null ? 0 : sources.length, customizer = length > 2 ? sources[length - 2] : undefined, guard = length > 2 ? sources[2] : undefined, thisArg = length > 1 ? sources[length - 1] : undefined;
2538 if (typeof customizer == 'function') {
2539 customizer = bindCallback(customizer, thisArg, 5);
2540 length -= 2;
2541 } else {
2542 customizer = typeof thisArg == 'function' ? thisArg : undefined;
2543 length -= customizer ? 1 : 0;
2544 }
2545 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
2546 customizer = length < 3 ? undefined : customizer;
2547 length = 1;
2548 }
2549 while (++index < length) {
2550 var source = sources[index];
2551 if (source) {
2552 assigner(object, source, customizer);
2553 }
2554 }
2555 return object;
2556 });
2557 }
2558 /**
2559 * Creates a `baseEach` or `baseEachRight` function.
2560 *
2561 * @private
2562 * @param {Function} eachFunc The function to iterate over a collection.
2563 * @param {boolean} [fromRight] Specify iterating from right to left.
2564 * @returns {Function} Returns the new base function.
2565 */
2566 function createBaseEach(eachFunc, fromRight) {
2567 return function (collection, iteratee) {
2568 var length = collection ? getLength(collection) : 0;
2569 if (!isLength(length)) {
2570 return eachFunc(collection, iteratee);
2571 }
2572 var index = fromRight ? length : -1, iterable = toObject(collection);
2573 while (fromRight ? index-- : ++index < length) {
2574 if (iteratee(iterable[index], index, iterable) === false) {
2575 break;
2576 }
2577 }
2578 return collection;
2579 };
2580 }
2581 /**
2582 * Creates a base function for `_.forIn` or `_.forInRight`.
2583 *
2584 * @private
2585 * @param {boolean} [fromRight] Specify iterating from right to left.
2586 * @returns {Function} Returns the new base function.
2587 */
2588 function createBaseFor(fromRight) {
2589 return function (object, iteratee, keysFunc) {
2590 var iterable = toObject(object), props = keysFunc(object), length = props.length, index = fromRight ? length : -1;
2591 while (fromRight ? index-- : ++index < length) {
2592 var key = props[index];
2593 if (iteratee(iterable[key], key, iterable) === false) {
2594 break;
2595 }
2596 }
2597 return object;
2598 };
2599 }
2600 /**
2601 * Creates a function that wraps `func` and invokes it with the `this`
2602 * binding of `thisArg`.
2603 *
2604 * @private
2605 * @param {Function} func The function to bind.
2606 * @param {*} [thisArg] The `this` binding of `func`.
2607 * @returns {Function} Returns the new bound function.
2608 */
2609 function createBindWrapper(func, thisArg) {
2610 var Ctor = createCtorWrapper(func);
2611 function wrapper() {
2612 var fn = this && this !== root && this instanceof wrapper ? Ctor : func;
2613 return fn.apply(thisArg, arguments);
2614 }
2615 return wrapper;
2616 }
2617 /**
2618 * Creates a `Set` cache object to optimize linear searches of large arrays.
2619 *
2620 * @private
2621 * @param {Array} [values] The values to cache.
2622 * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
2623 */
2624 function createCache(values) {
2625 return nativeCreate && Set ? new SetCache(values) : null;
2626 }
2627 /**
2628 * Creates a function that produces compound words out of the words in a
2629 * given string.
2630 *
2631 * @private
2632 * @param {Function} callback The function to combine each word.
2633 * @returns {Function} Returns the new compounder function.
2634 */
2635 function createCompounder(callback) {
2636 return function (string) {
2637 var index = -1, array = words(deburr(string)), length = array.length, result = '';
2638 while (++index < length) {
2639 result = callback(result, array[index], index);
2640 }
2641 return result;
2642 };
2643 }
2644 /**
2645 * Creates a function that produces an instance of `Ctor` regardless of
2646 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
2647 *
2648 * @private
2649 * @param {Function} Ctor The constructor to wrap.
2650 * @returns {Function} Returns the new wrapped function.
2651 */
2652 function createCtorWrapper(Ctor) {
2653 return function () {
2654 // Use a `switch` statement to work with class constructors.
2655 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
2656 // for more details.
2657 var args = arguments;
2658 switch (args.length) {
2659 case 0:
2660 return new Ctor();
2661 case 1:
2662 return new Ctor(args[0]);
2663 case 2:
2664 return new Ctor(args[0], args[1]);
2665 case 3:
2666 return new Ctor(args[0], args[1], args[2]);
2667 case 4:
2668 return new Ctor(args[0], args[1], args[2], args[3]);
2669 case 5:
2670 return new Ctor(args[0], args[1], args[2], args[3], args[4]);
2671 case 6:
2672 return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
2673 case 7:
2674 return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
2675 }
2676 var thisBinding = baseCreate(Ctor.prototype), result = Ctor.apply(thisBinding, args);
2677 // Mimic the constructor's `return` behavior.
2678 // See https://es5.github.io/#x13.2.2 for more details.
2679 return isObject(result) ? result : thisBinding;
2680 };
2681 }
2682 /**
2683 * Creates a `_.curry` or `_.curryRight` function.
2684 *
2685 * @private
2686 * @param {boolean} flag The curry bit flag.
2687 * @returns {Function} Returns the new curry function.
2688 */
2689 function createCurry(flag) {
2690 function curryFunc(func, arity, guard) {
2691 if (guard && isIterateeCall(func, arity, guard)) {
2692 arity = undefined;
2693 }
2694 var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
2695 result.placeholder = curryFunc.placeholder;
2696 return result;
2697 }
2698 return curryFunc;
2699 }
2700 /**
2701 * Creates a `_.defaults` or `_.defaultsDeep` function.
2702 *
2703 * @private
2704 * @param {Function} assigner The function to assign values.
2705 * @param {Function} customizer The function to customize assigned values.
2706 * @returns {Function} Returns the new defaults function.
2707 */
2708 function createDefaults(assigner, customizer) {
2709 return restParam(function (args) {
2710 var object = args[0];
2711 if (object == null) {
2712 return object;
2713 }
2714 args.push(customizer);
2715 return assigner.apply(undefined, args);
2716 });
2717 }
2718 /**
2719 * Creates a `_.max` or `_.min` function.
2720 *
2721 * @private
2722 * @param {Function} comparator The function used to compare values.
2723 * @param {*} exValue The initial extremum value.
2724 * @returns {Function} Returns the new extremum function.
2725 */
2726 function createExtremum(comparator, exValue) {
2727 return function (collection, iteratee, thisArg) {
2728 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
2729 iteratee = undefined;
2730 }
2731 iteratee = getCallback(iteratee, thisArg, 3);
2732 if (iteratee.length == 1) {
2733 collection = isArray(collection) ? collection : toIterable(collection);
2734 var result = arrayExtremum(collection, iteratee, comparator, exValue);
2735 if (!(collection.length && result === exValue)) {
2736 return result;
2737 }
2738 }
2739 return baseExtremum(collection, iteratee, comparator, exValue);
2740 };
2741 }
2742 /**
2743 * Creates a `_.find` or `_.findLast` function.
2744 *
2745 * @private
2746 * @param {Function} eachFunc The function to iterate over a collection.
2747 * @param {boolean} [fromRight] Specify iterating from right to left.
2748 * @returns {Function} Returns the new find function.
2749 */
2750 function createFind(eachFunc, fromRight) {
2751 return function (collection, predicate, thisArg) {
2752 predicate = getCallback(predicate, thisArg, 3);
2753 if (isArray(collection)) {
2754 var index = baseFindIndex(collection, predicate, fromRight);
2755 return index > -1 ? collection[index] : undefined;
2756 }
2757 return baseFind(collection, predicate, eachFunc);
2758 };
2759 }
2760 /**
2761 * Creates a `_.findIndex` or `_.findLastIndex` function.
2762 *
2763 * @private
2764 * @param {boolean} [fromRight] Specify iterating from right to left.
2765 * @returns {Function} Returns the new find function.
2766 */
2767 function createFindIndex(fromRight) {
2768 return function (array, predicate, thisArg) {
2769 if (!(array && array.length)) {
2770 return -1;
2771 }
2772 predicate = getCallback(predicate, thisArg, 3);
2773 return baseFindIndex(array, predicate, fromRight);
2774 };
2775 }
2776 /**
2777 * Creates a `_.findKey` or `_.findLastKey` function.
2778 *
2779 * @private
2780 * @param {Function} objectFunc The function to iterate over an object.
2781 * @returns {Function} Returns the new find function.
2782 */
2783 function createFindKey(objectFunc) {
2784 return function (object, predicate, thisArg) {
2785 predicate = getCallback(predicate, thisArg, 3);
2786 return baseFind(object, predicate, objectFunc, true);
2787 };
2788 }
2789 /**
2790 * Creates a `_.flow` or `_.flowRight` function.
2791 *
2792 * @private
2793 * @param {boolean} [fromRight] Specify iterating from right to left.
2794 * @returns {Function} Returns the new flow function.
2795 */
2796 function createFlow(fromRight) {
2797 return function () {
2798 var wrapper, length = arguments.length, index = fromRight ? length : -1, leftIndex = 0, funcs = Array(length);
2799 while (fromRight ? index-- : ++index < length) {
2800 var func = funcs[leftIndex++] = arguments[index];
2801 if (typeof func != 'function') {
2802 throw new TypeError(FUNC_ERROR_TEXT);
2803 }
2804 if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
2805 wrapper = new LodashWrapper([], true);
2806 }
2807 }
2808 index = wrapper ? -1 : length;
2809 while (++index < length) {
2810 func = funcs[index];
2811 var funcName = getFuncName(func), data = funcName == 'wrapper' ? getData(func) : undefined;
2812 if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
2813 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
2814 } else {
2815 wrapper = func.length == 1 && isLaziable(func) ? wrapper[funcName]() : wrapper.thru(func);
2816 }
2817 }
2818 return function () {
2819 var args = arguments, value = args[0];
2820 if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
2821 return wrapper.plant(value).value();
2822 }
2823 var index = 0, result = length ? funcs[index].apply(this, args) : value;
2824 while (++index < length) {
2825 result = funcs[index].call(this, result);
2826 }
2827 return result;
2828 };
2829 };
2830 }
2831 /**
2832 * Creates a function for `_.forEach` or `_.forEachRight`.
2833 *
2834 * @private
2835 * @param {Function} arrayFunc The function to iterate over an array.
2836 * @param {Function} eachFunc The function to iterate over a collection.
2837 * @returns {Function} Returns the new each function.
2838 */
2839 function createForEach(arrayFunc, eachFunc) {
2840 return function (collection, iteratee, thisArg) {
2841 return typeof iteratee == 'function' && thisArg === undefined && isArray(collection) ? arrayFunc(collection, iteratee) : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
2842 };
2843 }
2844 /**
2845 * Creates a function for `_.forIn` or `_.forInRight`.
2846 *
2847 * @private
2848 * @param {Function} objectFunc The function to iterate over an object.
2849 * @returns {Function} Returns the new each function.
2850 */
2851 function createForIn(objectFunc) {
2852 return function (object, iteratee, thisArg) {
2853 if (typeof iteratee != 'function' || thisArg !== undefined) {
2854 iteratee = bindCallback(iteratee, thisArg, 3);
2855 }
2856 return objectFunc(object, iteratee, keysIn);
2857 };
2858 }
2859 /**
2860 * Creates a function for `_.forOwn` or `_.forOwnRight`.
2861 *
2862 * @private
2863 * @param {Function} objectFunc The function to iterate over an object.
2864 * @returns {Function} Returns the new each function.
2865 */
2866 function createForOwn(objectFunc) {
2867 return function (object, iteratee, thisArg) {
2868 if (typeof iteratee != 'function' || thisArg !== undefined) {
2869 iteratee = bindCallback(iteratee, thisArg, 3);
2870 }
2871 return objectFunc(object, iteratee);
2872 };
2873 }
2874 /**
2875 * Creates a function for `_.mapKeys` or `_.mapValues`.
2876 *
2877 * @private
2878 * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
2879 * @returns {Function} Returns the new map function.
2880 */
2881 function createObjectMapper(isMapKeys) {
2882 return function (object, iteratee, thisArg) {
2883 var result = {};
2884 iteratee = getCallback(iteratee, thisArg, 3);
2885 baseForOwn(object, function (value, key, object) {
2886 var mapped = iteratee(value, key, object);
2887 key = isMapKeys ? mapped : key;
2888 value = isMapKeys ? value : mapped;
2889 result[key] = value;
2890 });
2891 return result;
2892 };
2893 }
2894 /**
2895 * Creates a function for `_.padLeft` or `_.padRight`.
2896 *
2897 * @private
2898 * @param {boolean} [fromRight] Specify padding from the right.
2899 * @returns {Function} Returns the new pad function.
2900 */
2901 function createPadDir(fromRight) {
2902 return function (string, length, chars) {
2903 string = baseToString(string);
2904 return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
2905 };
2906 }
2907 /**
2908 * Creates a `_.partial` or `_.partialRight` function.
2909 *
2910 * @private
2911 * @param {boolean} flag The partial bit flag.
2912 * @returns {Function} Returns the new partial function.
2913 */
2914 function createPartial(flag) {
2915 var partialFunc = restParam(function (func, partials) {
2916 var holders = replaceHolders(partials, partialFunc.placeholder);
2917 return createWrapper(func, flag, undefined, partials, holders);
2918 });
2919 return partialFunc;
2920 }
2921 /**
2922 * Creates a function for `_.reduce` or `_.reduceRight`.
2923 *
2924 * @private
2925 * @param {Function} arrayFunc The function to iterate over an array.
2926 * @param {Function} eachFunc The function to iterate over a collection.
2927 * @returns {Function} Returns the new each function.
2928 */
2929 function createReduce(arrayFunc, eachFunc) {
2930 return function (collection, iteratee, accumulator, thisArg) {
2931 var initFromArray = arguments.length < 3;
2932 return typeof iteratee == 'function' && thisArg === undefined && isArray(collection) ? arrayFunc(collection, iteratee, accumulator, initFromArray) : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
2933 };
2934 }
2935 /**
2936 * Creates a function that wraps `func` and invokes it with optional `this`
2937 * binding of, partial application, and currying.
2938 *
2939 * @private
2940 * @param {Function|string} func The function or method name to reference.
2941 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
2942 * @param {*} [thisArg] The `this` binding of `func`.
2943 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
2944 * @param {Array} [holders] The `partials` placeholder indexes.
2945 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
2946 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
2947 * @param {Array} [argPos] The argument positions of the new function.
2948 * @param {number} [ary] The arity cap of `func`.
2949 * @param {number} [arity] The arity of `func`.
2950 * @returns {Function} Returns the new wrapped function.
2951 */
2952 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
2953 var isAry = bitmask & ARY_FLAG, isBind = bitmask & BIND_FLAG, isBindKey = bitmask & BIND_KEY_FLAG, isCurry = bitmask & CURRY_FLAG, isCurryBound = bitmask & CURRY_BOUND_FLAG, isCurryRight = bitmask & CURRY_RIGHT_FLAG, Ctor = isBindKey ? undefined : createCtorWrapper(func);
2954 function wrapper() {
2955 // Avoid `arguments` object use disqualifying optimizations by
2956 // converting it to an array before providing it to other functions.
2957 var length = arguments.length, index = length, args = Array(length);
2958 while (index--) {
2959 args[index] = arguments[index];
2960 }
2961 if (partials) {
2962 args = composeArgs(args, partials, holders);
2963 }
2964 if (partialsRight) {
2965 args = composeArgsRight(args, partialsRight, holdersRight);
2966 }
2967 if (isCurry || isCurryRight) {
2968 var placeholder = wrapper.placeholder, argsHolders = replaceHolders(args, placeholder);
2969 length -= argsHolders.length;
2970 if (length < arity) {
2971 var newArgPos = argPos ? arrayCopy(argPos) : undefined, newArity = nativeMax(arity - length, 0), newsHolders = isCurry ? argsHolders : undefined, newHoldersRight = isCurry ? undefined : argsHolders, newPartials = isCurry ? args : undefined, newPartialsRight = isCurry ? undefined : args;
2972 bitmask |= isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG;
2973 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
2974 if (!isCurryBound) {
2975 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
2976 }
2977 var newData = [
2978 func,
2979 bitmask,
2980 thisArg,
2981 newPartials,
2982 newsHolders,
2983 newPartialsRight,
2984 newHoldersRight,
2985 newArgPos,
2986 ary,
2987 newArity
2988 ], result = createHybridWrapper.apply(undefined, newData);
2989 if (isLaziable(func)) {
2990 setData(result, newData);
2991 }
2992 result.placeholder = placeholder;
2993 return result;
2994 }
2995 }
2996 var thisBinding = isBind ? thisArg : this, fn = isBindKey ? thisBinding[func] : func;
2997 if (argPos) {
2998 args = reorder(args, argPos);
2999 }
3000 if (isAry && ary < args.length) {
3001 args.length = ary;
3002 }
3003 if (this && this !== root && this instanceof wrapper) {
3004 fn = Ctor || createCtorWrapper(func);
3005 }
3006 return fn.apply(thisBinding, args);
3007 }
3008 return wrapper;
3009 }
3010 /**
3011 * Creates the padding required for `string` based on the given `length`.
3012 * The `chars` string is truncated if the number of characters exceeds `length`.
3013 *
3014 * @private
3015 * @param {string} string The string to create padding for.
3016 * @param {number} [length=0] The padding length.
3017 * @param {string} [chars=' '] The string used as padding.
3018 * @returns {string} Returns the pad for `string`.
3019 */
3020 function createPadding(string, length, chars) {
3021 var strLength = string.length;
3022 length = +length;
3023 if (strLength >= length || !nativeIsFinite(length)) {
3024 return '';
3025 }
3026 var padLength = length - strLength;
3027 chars = chars == null ? ' ' : chars + '';
3028 return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
3029 }
3030 /**
3031 * Creates a function that wraps `func` and invokes it with the optional `this`
3032 * binding of `thisArg` and the `partials` prepended to those provided to
3033 * the wrapper.
3034 *
3035 * @private
3036 * @param {Function} func The function to partially apply arguments to.
3037 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3038 * @param {*} thisArg The `this` binding of `func`.
3039 * @param {Array} partials The arguments to prepend to those provided to the new function.
3040 * @returns {Function} Returns the new bound function.
3041 */
3042 function createPartialWrapper(func, bitmask, thisArg, partials) {
3043 var isBind = bitmask & BIND_FLAG, Ctor = createCtorWrapper(func);
3044 function wrapper() {
3045 // Avoid `arguments` object use disqualifying optimizations by
3046 // converting it to an array before providing it `func`.
3047 var argsIndex = -1, argsLength = arguments.length, leftIndex = -1, leftLength = partials.length, args = Array(leftLength + argsLength);
3048 while (++leftIndex < leftLength) {
3049 args[leftIndex] = partials[leftIndex];
3050 }
3051 while (argsLength--) {
3052 args[leftIndex++] = arguments[++argsIndex];
3053 }
3054 var fn = this && this !== root && this instanceof wrapper ? Ctor : func;
3055 return fn.apply(isBind ? thisArg : this, args);
3056 }
3057 return wrapper;
3058 }
3059 /**
3060 * Creates a `_.ceil`, `_.floor`, or `_.round` function.
3061 *
3062 * @private
3063 * @param {string} methodName The name of the `Math` method to use when rounding.
3064 * @returns {Function} Returns the new round function.
3065 */
3066 function createRound(methodName) {
3067 var func = Math[methodName];
3068 return function (number, precision) {
3069 precision = precision === undefined ? 0 : +precision || 0;
3070 if (precision) {
3071 precision = pow(10, precision);
3072 return func(number * precision) / precision;
3073 }
3074 return func(number);
3075 };
3076 }
3077 /**
3078 * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
3079 *
3080 * @private
3081 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3082 * @returns {Function} Returns the new index function.
3083 */
3084 function createSortedIndex(retHighest) {
3085 return function (array, value, iteratee, thisArg) {
3086 var callback = getCallback(iteratee);
3087 return iteratee == null && callback === baseCallback ? binaryIndex(array, value, retHighest) : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
3088 };
3089 }
3090 /**
3091 * Creates a function that either curries or invokes `func` with optional
3092 * `this` binding and partially applied arguments.
3093 *
3094 * @private
3095 * @param {Function|string} func The function or method name to reference.
3096 * @param {number} bitmask The bitmask of flags.
3097 * The bitmask may be composed of the following flags:
3098 * 1 - `_.bind`
3099 * 2 - `_.bindKey`
3100 * 4 - `_.curry` or `_.curryRight` of a bound function
3101 * 8 - `_.curry`
3102 * 16 - `_.curryRight`
3103 * 32 - `_.partial`
3104 * 64 - `_.partialRight`
3105 * 128 - `_.rearg`
3106 * 256 - `_.ary`
3107 * @param {*} [thisArg] The `this` binding of `func`.
3108 * @param {Array} [partials] The arguments to be partially applied.
3109 * @param {Array} [holders] The `partials` placeholder indexes.
3110 * @param {Array} [argPos] The argument positions of the new function.
3111 * @param {number} [ary] The arity cap of `func`.
3112 * @param {number} [arity] The arity of `func`.
3113 * @returns {Function} Returns the new wrapped function.
3114 */
3115 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
3116 var isBindKey = bitmask & BIND_KEY_FLAG;
3117 if (!isBindKey && typeof func != 'function') {
3118 throw new TypeError(FUNC_ERROR_TEXT);
3119 }
3120 var length = partials ? partials.length : 0;
3121 if (!length) {
3122 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
3123 partials = holders = undefined;
3124 }
3125 length -= holders ? holders.length : 0;
3126 if (bitmask & PARTIAL_RIGHT_FLAG) {
3127 var partialsRight = partials, holdersRight = holders;
3128 partials = holders = undefined;
3129 }
3130 var data = isBindKey ? undefined : getData(func), newData = [
3131 func,
3132 bitmask,
3133 thisArg,
3134 partials,
3135 holders,
3136 partialsRight,
3137 holdersRight,
3138 argPos,
3139 ary,
3140 arity
3141 ];
3142 if (data) {
3143 mergeData(newData, data);
3144 bitmask = newData[1];
3145 arity = newData[9];
3146 }
3147 newData[9] = arity == null ? isBindKey ? 0 : func.length : nativeMax(arity - length, 0) || 0;
3148 if (bitmask == BIND_FLAG) {
3149 var result = createBindWrapper(newData[0], newData[2]);
3150 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
3151 result = createPartialWrapper.apply(undefined, newData);
3152 } else {
3153 result = createHybridWrapper.apply(undefined, newData);
3154 }
3155 var setter = data ? baseSetData : setData;
3156 return setter(result, newData);
3157 }
3158 /**
3159 * A specialized version of `baseIsEqualDeep` for arrays with support for
3160 * partial deep comparisons.
3161 *
3162 * @private
3163 * @param {Array} array The array to compare.
3164 * @param {Array} other The other array to compare.
3165 * @param {Function} equalFunc The function to determine equivalents of values.
3166 * @param {Function} [customizer] The function to customize comparing arrays.
3167 * @param {boolean} [isLoose] Specify performing partial comparisons.
3168 * @param {Array} [stackA] Tracks traversed `value` objects.
3169 * @param {Array} [stackB] Tracks traversed `other` objects.
3170 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
3171 */
3172 function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
3173 var index = -1, arrLength = array.length, othLength = other.length;
3174 if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
3175 return false;
3176 }
3177 // Ignore non-index properties.
3178 while (++index < arrLength) {
3179 var arrValue = array[index], othValue = other[index], result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
3180 if (result !== undefined) {
3181 if (result) {
3182 continue;
3183 }
3184 return false;
3185 }
3186 // Recursively compare arrays (susceptible to call stack limits).
3187 if (isLoose) {
3188 if (!arraySome(other, function (othValue) {
3189 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
3190 })) {
3191 return false;
3192 }
3193 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
3194 return false;
3195 }
3196 }
3197 return true;
3198 }
3199 /**
3200 * A specialized version of `baseIsEqualDeep` for comparing objects of
3201 * the same `toStringTag`.
3202 *
3203 * **Note:** This function only supports comparing values with tags of
3204 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
3205 *
3206 * @private
3207 * @param {Object} object The object to compare.
3208 * @param {Object} other The other object to compare.
3209 * @param {string} tag The `toStringTag` of the objects to compare.
3210 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3211 */
3212 function equalByTag(object, other, tag) {
3213 switch (tag) {
3214 case boolTag:
3215 case dateTag:
3216 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
3217 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
3218 return +object == +other;
3219 case errorTag:
3220 return object.name == other.name && object.message == other.message;
3221 case numberTag:
3222 // Treat `NaN` vs. `NaN` as equal.
3223 return object != +object ? other != +other : object == +other;
3224 case regexpTag:
3225 case stringTag:
3226 // Coerce regexes to strings and treat strings primitives and string
3227 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
3228 return object == other + '';
3229 }
3230 return false;
3231 }
3232 /**
3233 * A specialized version of `baseIsEqualDeep` for objects with support for
3234 * partial deep comparisons.
3235 *
3236 * @private
3237 * @param {Object} object The object to compare.
3238 * @param {Object} other The other object to compare.
3239 * @param {Function} equalFunc The function to determine equivalents of values.
3240 * @param {Function} [customizer] The function to customize comparing values.
3241 * @param {boolean} [isLoose] Specify performing partial comparisons.
3242 * @param {Array} [stackA] Tracks traversed `value` objects.
3243 * @param {Array} [stackB] Tracks traversed `other` objects.
3244 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3245 */
3246 function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
3247 var objProps = keys(object), objLength = objProps.length, othProps = keys(other), othLength = othProps.length;
3248 if (objLength != othLength && !isLoose) {
3249 return false;
3250 }
3251 var index = objLength;
3252 while (index--) {
3253 var key = objProps[index];
3254 if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
3255 return false;
3256 }
3257 }
3258 var skipCtor = isLoose;
3259 while (++index < objLength) {
3260 key = objProps[index];
3261 var objValue = object[key], othValue = other[key], result = customizer ? customizer(isLoose ? othValue : objValue, isLoose ? objValue : othValue, key) : undefined;
3262 // Recursively compare objects (susceptible to call stack limits).
3263 if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
3264 return false;
3265 }
3266 skipCtor || (skipCtor = key == 'constructor');
3267 }
3268 if (!skipCtor) {
3269 var objCtor = object.constructor, othCtor = other.constructor;
3270 // Non `Object` object instances with different constructors are not equal.
3271 if (objCtor != othCtor && ('constructor' in object && 'constructor' in other) && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
3272 return false;
3273 }
3274 }
3275 return true;
3276 }
3277 /**
3278 * Gets the appropriate "callback" function. If the `_.callback` method is
3279 * customized this function returns the custom method, otherwise it returns
3280 * the `baseCallback` function. If arguments are provided the chosen function
3281 * is invoked with them and its result is returned.
3282 *
3283 * @private
3284 * @returns {Function} Returns the chosen function or its result.
3285 */
3286 function getCallback(func, thisArg, argCount) {
3287 var result = lodash.callback || callback;
3288 result = result === callback ? baseCallback : result;
3289 return argCount ? result(func, thisArg, argCount) : result;
3290 }
3291 /**
3292 * Gets metadata for `func`.
3293 *
3294 * @private
3295 * @param {Function} func The function to query.
3296 * @returns {*} Returns the metadata for `func`.
3297 */
3298 var getData = !metaMap ? noop : function (func) {
3299 return metaMap.get(func);
3300 };
3301 /**
3302 * Gets the name of `func`.
3303 *
3304 * @private
3305 * @param {Function} func The function to query.
3306 * @returns {string} Returns the function name.
3307 */
3308 function getFuncName(func) {
3309 var result = func.name + '', array = realNames[result], length = array ? array.length : 0;
3310 while (length--) {
3311 var data = array[length], otherFunc = data.func;
3312 if (otherFunc == null || otherFunc == func) {
3313 return data.name;
3314 }
3315 }
3316 return result;
3317 }
3318 /**
3319 * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
3320 * customized this function returns the custom method, otherwise it returns
3321 * the `baseIndexOf` function. If arguments are provided the chosen function
3322 * is invoked with them and its result is returned.
3323 *
3324 * @private
3325 * @returns {Function|number} Returns the chosen function or its result.
3326 */
3327 function getIndexOf(collection, target, fromIndex) {
3328 var result = lodash.indexOf || indexOf;
3329 result = result === indexOf ? baseIndexOf : result;
3330 return collection ? result(collection, target, fromIndex) : result;
3331 }
3332 /**
3333 * Gets the "length" property value of `object`.
3334 *
3335 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
3336 * that affects Safari on at least iOS 8.1-8.3 ARM64.
3337 *
3338 * @private
3339 * @param {Object} object The object to query.
3340 * @returns {*} Returns the "length" value.
3341 */
3342 var getLength = baseProperty('length');
3343 /**
3344 * Gets the propery names, values, and compare flags of `object`.
3345 *
3346 * @private
3347 * @param {Object} object The object to query.
3348 * @returns {Array} Returns the match data of `object`.
3349 */
3350 function getMatchData(object) {
3351 var result = pairs(object), length = result.length;
3352 while (length--) {
3353 result[length][2] = isStrictComparable(result[length][1]);
3354 }
3355 return result;
3356 }
3357 /**
3358 * Gets the native function at `key` of `object`.
3359 *
3360 * @private
3361 * @param {Object} object The object to query.
3362 * @param {string} key The key of the method to get.
3363 * @returns {*} Returns the function if it's native, else `undefined`.
3364 */
3365 function getNative(object, key) {
3366 var value = object == null ? undefined : object[key];
3367 return isNative(value) ? value : undefined;
3368 }
3369 /**
3370 * Gets the view, applying any `transforms` to the `start` and `end` positions.
3371 *
3372 * @private
3373 * @param {number} start The start of the view.
3374 * @param {number} end The end of the view.
3375 * @param {Array} transforms The transformations to apply to the view.
3376 * @returns {Object} Returns an object containing the `start` and `end`
3377 * positions of the view.
3378 */
3379 function getView(start, end, transforms) {
3380 var index = -1, length = transforms.length;
3381 while (++index < length) {
3382 var data = transforms[index], size = data.size;
3383 switch (data.type) {
3384 case 'drop':
3385 start += size;
3386 break;
3387 case 'dropRight':
3388 end -= size;
3389 break;
3390 case 'take':
3391 end = nativeMin(end, start + size);
3392 break;
3393 case 'takeRight':
3394 start = nativeMax(start, end - size);
3395 break;
3396 }
3397 }
3398 return {
3399 'start': start,
3400 'end': end
3401 };
3402 }
3403 /**
3404 * Initializes an array clone.
3405 *
3406 * @private
3407 * @param {Array} array The array to clone.
3408 * @returns {Array} Returns the initialized clone.
3409 */
3410 function initCloneArray(array) {
3411 var length = array.length, result = new array.constructor(length);
3412 // Add array properties assigned by `RegExp#exec`.
3413 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
3414 result.index = array.index;
3415 result.input = array.input;
3416 }
3417 return result;
3418 }
3419 /**
3420 * Initializes an object clone.
3421 *
3422 * @private
3423 * @param {Object} object The object to clone.
3424 * @returns {Object} Returns the initialized clone.
3425 */
3426 function initCloneObject(object) {
3427 var Ctor = object.constructor;
3428 if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
3429 Ctor = Object;
3430 }
3431 return new Ctor();
3432 }
3433 /**
3434 * Initializes an object clone based on its `toStringTag`.
3435 *
3436 * **Note:** This function only supports cloning values with tags of
3437 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
3438 *
3439 * @private
3440 * @param {Object} object The object to clone.
3441 * @param {string} tag The `toStringTag` of the object to clone.
3442 * @param {boolean} [isDeep] Specify a deep clone.
3443 * @returns {Object} Returns the initialized clone.
3444 */
3445 function initCloneByTag(object, tag, isDeep) {
3446 var Ctor = object.constructor;
3447 switch (tag) {
3448 case arrayBufferTag:
3449 return bufferClone(object);
3450 case boolTag:
3451 case dateTag:
3452 return new Ctor(+object);
3453 case float32Tag:
3454 case float64Tag:
3455 case int8Tag:
3456 case int16Tag:
3457 case int32Tag:
3458 case uint8Tag:
3459 case uint8ClampedTag:
3460 case uint16Tag:
3461 case uint32Tag:
3462 var buffer = object.buffer;
3463 return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
3464 case numberTag:
3465 case stringTag:
3466 return new Ctor(object);
3467 case regexpTag:
3468 var result = new Ctor(object.source, reFlags.exec(object));
3469 result.lastIndex = object.lastIndex;
3470 }
3471 return result;
3472 }
3473 /**
3474 * Invokes the method at `path` on `object`.
3475 *
3476 * @private
3477 * @param {Object} object The object to query.
3478 * @param {Array|string} path The path of the method to invoke.
3479 * @param {Array} args The arguments to invoke the method with.
3480 * @returns {*} Returns the result of the invoked method.
3481 */
3482 function invokePath(object, path, args) {
3483 if (object != null && !isKey(path, object)) {
3484 path = toPath(path);
3485 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
3486 path = last(path);
3487 }
3488 var func = object == null ? object : object[path];
3489 return func == null ? undefined : func.apply(object, args);
3490 }
3491 /**
3492 * Checks if `value` is array-like.
3493 *
3494 * @private
3495 * @param {*} value The value to check.
3496 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
3497 */
3498 function isArrayLike(value) {
3499 return value != null && isLength(getLength(value));
3500 }
3501 /**
3502 * Checks if `value` is a valid array-like index.
3503 *
3504 * @private
3505 * @param {*} value The value to check.
3506 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
3507 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
3508 */
3509 function isIndex(value, length) {
3510 value = typeof value == 'number' || reIsUint.test(value) ? +value : -1;
3511 length = length == null ? MAX_SAFE_INTEGER : length;
3512 return value > -1 && value % 1 == 0 && value < length;
3513 }
3514 /**
3515 * Checks if the provided arguments are from an iteratee call.
3516 *
3517 * @private
3518 * @param {*} value The potential iteratee value argument.
3519 * @param {*} index The potential iteratee index or key argument.
3520 * @param {*} object The potential iteratee object argument.
3521 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
3522 */
3523 function isIterateeCall(value, index, object) {
3524 if (!isObject(object)) {
3525 return false;
3526 }
3527 var type = typeof index;
3528 if (type == 'number' ? isArrayLike(object) && isIndex(index, object.length) : type == 'string' && index in object) {
3529 var other = object[index];
3530 return value === value ? value === other : other !== other;
3531 }
3532 return false;
3533 }
3534 /**
3535 * Checks if `value` is a property name and not a property path.
3536 *
3537 * @private
3538 * @param {*} value The value to check.
3539 * @param {Object} [object] The object to query keys on.
3540 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
3541 */
3542 function isKey(value, object) {
3543 var type = typeof value;
3544 if (type == 'string' && reIsPlainProp.test(value) || type == 'number') {
3545 return true;
3546 }
3547 if (isArray(value)) {
3548 return false;
3549 }
3550 var result = !reIsDeepProp.test(value);
3551 return result || object != null && value in toObject(object);
3552 }
3553 /**
3554 * Checks if `func` has a lazy counterpart.
3555 *
3556 * @private
3557 * @param {Function} func The function to check.
3558 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
3559 */
3560 function isLaziable(func) {
3561 var funcName = getFuncName(func), other = lodash[funcName];
3562 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
3563 return false;
3564 }
3565 if (func === other) {
3566 return true;
3567 }
3568 var data = getData(other);
3569 return !!data && func === data[0];
3570 }
3571 /**
3572 * Checks if `value` is a valid array-like length.
3573 *
3574 * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
3575 *
3576 * @private
3577 * @param {*} value The value to check.
3578 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
3579 */
3580 function isLength(value) {
3581 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
3582 }
3583 /**
3584 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
3585 *
3586 * @private
3587 * @param {*} value The value to check.
3588 * @returns {boolean} Returns `true` if `value` if suitable for strict
3589 * equality comparisons, else `false`.
3590 */
3591 function isStrictComparable(value) {
3592 return value === value && !isObject(value);
3593 }
3594 /**
3595 * Merges the function metadata of `source` into `data`.
3596 *
3597 * Merging metadata reduces the number of wrappers required to invoke a function.
3598 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
3599 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
3600 * augment function arguments, making the order in which they are executed important,
3601 * preventing the merging of metadata. However, we make an exception for a safe
3602 * common case where curried functions have `_.ary` and or `_.rearg` applied.
3603 *
3604 * @private
3605 * @param {Array} data The destination metadata.
3606 * @param {Array} source The source metadata.
3607 * @returns {Array} Returns `data`.
3608 */
3609 function mergeData(data, source) {
3610 var bitmask = data[1], srcBitmask = source[1], newBitmask = bitmask | srcBitmask, isCommon = newBitmask < ARY_FLAG;
3611 var isCombo = srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG || srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8] || srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG;
3612 // Exit early if metadata can't be merged.
3613 if (!(isCommon || isCombo)) {
3614 return data;
3615 }
3616 // Use source `thisArg` if available.
3617 if (srcBitmask & BIND_FLAG) {
3618 data[2] = source[2];
3619 // Set when currying a bound function.
3620 newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
3621 }
3622 // Compose partial arguments.
3623 var value = source[3];
3624 if (value) {
3625 var partials = data[3];
3626 data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
3627 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
3628 }
3629 // Compose partial right arguments.
3630 value = source[5];
3631 if (value) {
3632 partials = data[5];
3633 data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
3634 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
3635 }
3636 // Use source `argPos` if available.
3637 value = source[7];
3638 if (value) {
3639 data[7] = arrayCopy(value);
3640 }
3641 // Use source `ary` if it's smaller.
3642 if (srcBitmask & ARY_FLAG) {
3643 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
3644 }
3645 // Use source `arity` if one is not provided.
3646 if (data[9] == null) {
3647 data[9] = source[9];
3648 }
3649 // Use source `func` and merge bitmasks.
3650 data[0] = source[0];
3651 data[1] = newBitmask;
3652 return data;
3653 }
3654 /**
3655 * Used by `_.defaultsDeep` to customize its `_.merge` use.
3656 *
3657 * @private
3658 * @param {*} objectValue The destination object property value.
3659 * @param {*} sourceValue The source object property value.
3660 * @returns {*} Returns the value to assign to the destination object.
3661 */
3662 function mergeDefaults(objectValue, sourceValue) {
3663 return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
3664 }
3665 /**
3666 * A specialized version of `_.pick` which picks `object` properties specified
3667 * by `props`.
3668 *
3669 * @private
3670 * @param {Object} object The source object.
3671 * @param {string[]} props The property names to pick.
3672 * @returns {Object} Returns the new object.
3673 */
3674 function pickByArray(object, props) {
3675 object = toObject(object);
3676 var index = -1, length = props.length, result = {};
3677 while (++index < length) {
3678 var key = props[index];
3679 if (key in object) {
3680 result[key] = object[key];
3681 }
3682 }
3683 return result;
3684 }
3685 /**
3686 * A specialized version of `_.pick` which picks `object` properties `predicate`
3687 * returns truthy for.
3688 *
3689 * @private
3690 * @param {Object} object The source object.
3691 * @param {Function} predicate The function invoked per iteration.
3692 * @returns {Object} Returns the new object.
3693 */
3694 function pickByCallback(object, predicate) {
3695 var result = {};
3696 baseForIn(object, function (value, key, object) {
3697 if (predicate(value, key, object)) {
3698 result[key] = value;
3699 }
3700 });
3701 return result;
3702 }
3703 /**
3704 * Reorder `array` according to the specified indexes where the element at
3705 * the first index is assigned as the first element, the element at
3706 * the second index is assigned as the second element, and so on.
3707 *
3708 * @private
3709 * @param {Array} array The array to reorder.
3710 * @param {Array} indexes The arranged array indexes.
3711 * @returns {Array} Returns `array`.
3712 */
3713 function reorder(array, indexes) {
3714 var arrLength = array.length, length = nativeMin(indexes.length, arrLength), oldArray = arrayCopy(array);
3715 while (length--) {
3716 var index = indexes[length];
3717 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
3718 }
3719 return array;
3720 }
3721 /**
3722 * Sets metadata for `func`.
3723 *
3724 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
3725 * period of time, it will trip its breaker and transition to an identity function
3726 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
3727 * for more details.
3728 *
3729 * @private
3730 * @param {Function} func The function to associate metadata with.
3731 * @param {*} data The metadata.
3732 * @returns {Function} Returns `func`.
3733 */
3734 var setData = function () {
3735 var count = 0, lastCalled = 0;
3736 return function (key, value) {
3737 var stamp = now(), remaining = HOT_SPAN - (stamp - lastCalled);
3738 lastCalled = stamp;
3739 if (remaining > 0) {
3740 if (++count >= HOT_COUNT) {
3741 return key;
3742 }
3743 } else {
3744 count = 0;
3745 }
3746 return baseSetData(key, value);
3747 };
3748 }();
3749 /**
3750 * A fallback implementation of `Object.keys` which creates an array of the
3751 * own enumerable property names of `object`.
3752 *
3753 * @private
3754 * @param {Object} object The object to query.
3755 * @returns {Array} Returns the array of property names.
3756 */
3757 function shimKeys(object) {
3758 var props = keysIn(object), propsLength = props.length, length = propsLength && object.length;
3759 var allowIndexes = !!length && isLength(length) && (isArray(object) || isArguments(object));
3760 var index = -1, result = [];
3761 while (++index < propsLength) {
3762 var key = props[index];
3763 if (allowIndexes && isIndex(key, length) || hasOwnProperty.call(object, key)) {
3764 result.push(key);
3765 }
3766 }
3767 return result;
3768 }
3769 /**
3770 * Converts `value` to an array-like object if it's not one.
3771 *
3772 * @private
3773 * @param {*} value The value to process.
3774 * @returns {Array|Object} Returns the array-like object.
3775 */
3776 function toIterable(value) {
3777 if (value == null) {
3778 return [];
3779 }
3780 if (!isArrayLike(value)) {
3781 return values(value);
3782 }
3783 return isObject(value) ? value : Object(value);
3784 }
3785 /**
3786 * Converts `value` to an object if it's not one.
3787 *
3788 * @private
3789 * @param {*} value The value to process.
3790 * @returns {Object} Returns the object.
3791 */
3792 function toObject(value) {
3793 return isObject(value) ? value : Object(value);
3794 }
3795 /**
3796 * Converts `value` to property path array if it's not one.
3797 *
3798 * @private
3799 * @param {*} value The value to process.
3800 * @returns {Array} Returns the property path array.
3801 */
3802 function toPath(value) {
3803 if (isArray(value)) {
3804 return value;
3805 }
3806 var result = [];
3807 baseToString(value).replace(rePropName, function (match, number, quote, string) {
3808 result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
3809 });
3810 return result;
3811 }
3812 /**
3813 * Creates a clone of `wrapper`.
3814 *
3815 * @private
3816 * @param {Object} wrapper The wrapper to clone.
3817 * @returns {Object} Returns the cloned wrapper.
3818 */
3819 function wrapperClone(wrapper) {
3820 return wrapper instanceof LazyWrapper ? wrapper.clone() : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
3821 }
3822 /*------------------------------------------------------------------------*/
3823 /**
3824 * Creates an array of elements split into groups the length of `size`.
3825 * If `collection` can't be split evenly, the final chunk will be the remaining
3826 * elements.
3827 *
3828 * @static
3829 * @memberOf _
3830 * @category Array
3831 * @param {Array} array The array to process.
3832 * @param {number} [size=1] The length of each chunk.
3833 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
3834 * @returns {Array} Returns the new array containing chunks.
3835 * @example
3836 *
3837 * _.chunk(['a', 'b', 'c', 'd'], 2);
3838 * // => [['a', 'b'], ['c', 'd']]
3839 *
3840 * _.chunk(['a', 'b', 'c', 'd'], 3);
3841 * // => [['a', 'b', 'c'], ['d']]
3842 */
3843 function chunk(array, size, guard) {
3844 if (guard ? isIterateeCall(array, size, guard) : size == null) {
3845 size = 1;
3846 } else {
3847 size = nativeMax(nativeFloor(size) || 1, 1);
3848 }
3849 var index = 0, length = array ? array.length : 0, resIndex = -1, result = Array(nativeCeil(length / size));
3850 while (index < length) {
3851 result[++resIndex] = baseSlice(array, index, index += size);
3852 }
3853 return result;
3854 }
3855 /**
3856 * Creates an array with all falsey values removed. The values `false`, `null`,
3857 * `0`, `""`, `undefined`, and `NaN` are falsey.
3858 *
3859 * @static
3860 * @memberOf _
3861 * @category Array
3862 * @param {Array} array The array to compact.
3863 * @returns {Array} Returns the new array of filtered values.
3864 * @example
3865 *
3866 * _.compact([0, 1, false, 2, '', 3]);
3867 * // => [1, 2, 3]
3868 */
3869 function compact(array) {
3870 var index = -1, length = array ? array.length : 0, resIndex = -1, result = [];
3871 while (++index < length) {
3872 var value = array[index];
3873 if (value) {
3874 result[++resIndex] = value;
3875 }
3876 }
3877 return result;
3878 }
3879 /**
3880 * Creates an array of unique `array` values not included in the other
3881 * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
3882 * for equality comparisons.
3883 *
3884 * @static
3885 * @memberOf _
3886 * @category Array
3887 * @param {Array} array The array to inspect.
3888 * @param {...Array} [values] The arrays of values to exclude.
3889 * @returns {Array} Returns the new array of filtered values.
3890 * @example
3891 *
3892 * _.difference([1, 2, 3], [4, 2]);
3893 * // => [1, 3]
3894 */
3895 var difference = restParam(function (array, values) {
3896 return isObjectLike(array) && isArrayLike(array) ? baseDifference(array, baseFlatten(values, false, true)) : [];
3897 });
3898 /**
3899 * Creates a slice of `array` with `n` elements dropped from the beginning.
3900 *
3901 * @static
3902 * @memberOf _
3903 * @category Array
3904 * @param {Array} array The array to query.
3905 * @param {number} [n=1] The number of elements to drop.
3906 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
3907 * @returns {Array} Returns the slice of `array`.
3908 * @example
3909 *
3910 * _.drop([1, 2, 3]);
3911 * // => [2, 3]
3912 *
3913 * _.drop([1, 2, 3], 2);
3914 * // => [3]
3915 *
3916 * _.drop([1, 2, 3], 5);
3917 * // => []
3918 *
3919 * _.drop([1, 2, 3], 0);
3920 * // => [1, 2, 3]
3921 */
3922 function drop(array, n, guard) {
3923 var length = array ? array.length : 0;
3924 if (!length) {
3925 return [];
3926 }
3927 if (guard ? isIterateeCall(array, n, guard) : n == null) {
3928 n = 1;
3929 }
3930 return baseSlice(array, n < 0 ? 0 : n);
3931 }
3932 /**
3933 * Creates a slice of `array` with `n` elements dropped from the end.
3934 *
3935 * @static
3936 * @memberOf _
3937 * @category Array
3938 * @param {Array} array The array to query.
3939 * @param {number} [n=1] The number of elements to drop.
3940 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
3941 * @returns {Array} Returns the slice of `array`.
3942 * @example
3943 *
3944 * _.dropRight([1, 2, 3]);
3945 * // => [1, 2]
3946 *
3947 * _.dropRight([1, 2, 3], 2);
3948 * // => [1]
3949 *
3950 * _.dropRight([1, 2, 3], 5);
3951 * // => []
3952 *
3953 * _.dropRight([1, 2, 3], 0);
3954 * // => [1, 2, 3]
3955 */
3956 function dropRight(array, n, guard) {
3957 var length = array ? array.length : 0;
3958 if (!length) {
3959 return [];
3960 }
3961 if (guard ? isIterateeCall(array, n, guard) : n == null) {
3962 n = 1;
3963 }
3964 n = length - (+n || 0);
3965 return baseSlice(array, 0, n < 0 ? 0 : n);
3966 }
3967 /**
3968 * Creates a slice of `array` excluding elements dropped from the end.
3969 * Elements are dropped until `predicate` returns falsey. The predicate is
3970 * bound to `thisArg` and invoked with three arguments: (value, index, array).
3971 *
3972 * If a property name is provided for `predicate` the created `_.property`
3973 * style callback returns the property value of the given element.
3974 *
3975 * If a value is also provided for `thisArg` the created `_.matchesProperty`
3976 * style callback returns `true` for elements that have a matching property
3977 * value, else `false`.
3978 *
3979 * If an object is provided for `predicate` the created `_.matches` style
3980 * callback returns `true` for elements that match the properties of the given
3981 * object, else `false`.
3982 *
3983 * @static
3984 * @memberOf _
3985 * @category Array
3986 * @param {Array} array The array to query.
3987 * @param {Function|Object|string} [predicate=_.identity] The function invoked
3988 * per iteration.
3989 * @param {*} [thisArg] The `this` binding of `predicate`.
3990 * @returns {Array} Returns the slice of `array`.
3991 * @example
3992 *
3993 * _.dropRightWhile([1, 2, 3], function(n) {
3994 * return n > 1;
3995 * });
3996 * // => [1]
3997 *
3998 * var users = [
3999 * { 'user': 'barney', 'active': true },
4000 * { 'user': 'fred', 'active': false },
4001 * { 'user': 'pebbles', 'active': false }
4002 * ];
4003 *
4004 * // using the `_.matches` callback shorthand
4005 * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
4006 * // => ['barney', 'fred']
4007 *
4008 * // using the `_.matchesProperty` callback shorthand
4009 * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
4010 * // => ['barney']
4011 *
4012 * // using the `_.property` callback shorthand
4013 * _.pluck(_.dropRightWhile(users, 'active'), 'user');
4014 * // => ['barney', 'fred', 'pebbles']
4015 */
4016 function dropRightWhile(array, predicate, thisArg) {
4017 return array && array.length ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true) : [];
4018 }
4019 /**
4020 * Creates a slice of `array` excluding elements dropped from the beginning.
4021 * Elements are dropped until `predicate` returns falsey. The predicate is
4022 * bound to `thisArg` and invoked with three arguments: (value, index, array).
4023 *
4024 * If a property name is provided for `predicate` the created `_.property`
4025 * style callback returns the property value of the given element.
4026 *
4027 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4028 * style callback returns `true` for elements that have a matching property
4029 * value, else `false`.
4030 *
4031 * If an object is provided for `predicate` the created `_.matches` style
4032 * callback returns `true` for elements that have the properties of the given
4033 * object, else `false`.
4034 *
4035 * @static
4036 * @memberOf _
4037 * @category Array
4038 * @param {Array} array The array to query.
4039 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4040 * per iteration.
4041 * @param {*} [thisArg] The `this` binding of `predicate`.
4042 * @returns {Array} Returns the slice of `array`.
4043 * @example
4044 *
4045 * _.dropWhile([1, 2, 3], function(n) {
4046 * return n < 3;
4047 * });
4048 * // => [3]
4049 *
4050 * var users = [
4051 * { 'user': 'barney', 'active': false },
4052 * { 'user': 'fred', 'active': false },
4053 * { 'user': 'pebbles', 'active': true }
4054 * ];
4055 *
4056 * // using the `_.matches` callback shorthand
4057 * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
4058 * // => ['fred', 'pebbles']
4059 *
4060 * // using the `_.matchesProperty` callback shorthand
4061 * _.pluck(_.dropWhile(users, 'active', false), 'user');
4062 * // => ['pebbles']
4063 *
4064 * // using the `_.property` callback shorthand
4065 * _.pluck(_.dropWhile(users, 'active'), 'user');
4066 * // => ['barney', 'fred', 'pebbles']
4067 */
4068 function dropWhile(array, predicate, thisArg) {
4069 return array && array.length ? baseWhile(array, getCallback(predicate, thisArg, 3), true) : [];
4070 }
4071 /**
4072 * Fills elements of `array` with `value` from `start` up to, but not
4073 * including, `end`.
4074 *
4075 * **Note:** This method mutates `array`.
4076 *
4077 * @static
4078 * @memberOf _
4079 * @category Array
4080 * @param {Array} array The array to fill.
4081 * @param {*} value The value to fill `array` with.
4082 * @param {number} [start=0] The start position.
4083 * @param {number} [end=array.length] The end position.
4084 * @returns {Array} Returns `array`.
4085 * @example
4086 *
4087 * var array = [1, 2, 3];
4088 *
4089 * _.fill(array, 'a');
4090 * console.log(array);
4091 * // => ['a', 'a', 'a']
4092 *
4093 * _.fill(Array(3), 2);
4094 * // => [2, 2, 2]
4095 *
4096 * _.fill([4, 6, 8], '*', 1, 2);
4097 * // => [4, '*', 8]
4098 */
4099 function fill(array, value, start, end) {
4100 var length = array ? array.length : 0;
4101 if (!length) {
4102 return [];
4103 }
4104 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
4105 start = 0;
4106 end = length;
4107 }
4108 return baseFill(array, value, start, end);
4109 }
4110 /**
4111 * This method is like `_.find` except that it returns the index of the first
4112 * element `predicate` returns truthy for instead of the element itself.
4113 *
4114 * If a property name is provided for `predicate` the created `_.property`
4115 * style callback returns the property value of the given element.
4116 *
4117 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4118 * style callback returns `true` for elements that have a matching property
4119 * value, else `false`.
4120 *
4121 * If an object is provided for `predicate` the created `_.matches` style
4122 * callback returns `true` for elements that have the properties of the given
4123 * object, else `false`.
4124 *
4125 * @static
4126 * @memberOf _
4127 * @category Array
4128 * @param {Array} array The array to search.
4129 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4130 * per iteration.
4131 * @param {*} [thisArg] The `this` binding of `predicate`.
4132 * @returns {number} Returns the index of the found element, else `-1`.
4133 * @example
4134 *
4135 * var users = [
4136 * { 'user': 'barney', 'active': false },
4137 * { 'user': 'fred', 'active': false },
4138 * { 'user': 'pebbles', 'active': true }
4139 * ];
4140 *
4141 * _.findIndex(users, function(chr) {
4142 * return chr.user == 'barney';
4143 * });
4144 * // => 0
4145 *
4146 * // using the `_.matches` callback shorthand
4147 * _.findIndex(users, { 'user': 'fred', 'active': false });
4148 * // => 1
4149 *
4150 * // using the `_.matchesProperty` callback shorthand
4151 * _.findIndex(users, 'active', false);
4152 * // => 0
4153 *
4154 * // using the `_.property` callback shorthand
4155 * _.findIndex(users, 'active');
4156 * // => 2
4157 */
4158 var findIndex = createFindIndex();
4159 /**
4160 * This method is like `_.findIndex` except that it iterates over elements
4161 * of `collection` from right to left.
4162 *
4163 * If a property name is provided for `predicate` the created `_.property`
4164 * style callback returns the property value of the given element.
4165 *
4166 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4167 * style callback returns `true` for elements that have a matching property
4168 * value, else `false`.
4169 *
4170 * If an object is provided for `predicate` the created `_.matches` style
4171 * callback returns `true` for elements that have the properties of the given
4172 * object, else `false`.
4173 *
4174 * @static
4175 * @memberOf _
4176 * @category Array
4177 * @param {Array} array The array to search.
4178 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4179 * per iteration.
4180 * @param {*} [thisArg] The `this` binding of `predicate`.
4181 * @returns {number} Returns the index of the found element, else `-1`.
4182 * @example
4183 *
4184 * var users = [
4185 * { 'user': 'barney', 'active': true },
4186 * { 'user': 'fred', 'active': false },
4187 * { 'user': 'pebbles', 'active': false }
4188 * ];
4189 *
4190 * _.findLastIndex(users, function(chr) {
4191 * return chr.user == 'pebbles';
4192 * });
4193 * // => 2
4194 *
4195 * // using the `_.matches` callback shorthand
4196 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
4197 * // => 0
4198 *
4199 * // using the `_.matchesProperty` callback shorthand
4200 * _.findLastIndex(users, 'active', false);
4201 * // => 2
4202 *
4203 * // using the `_.property` callback shorthand
4204 * _.findLastIndex(users, 'active');
4205 * // => 0
4206 */
4207 var findLastIndex = createFindIndex(true);
4208 /**
4209 * Gets the first element of `array`.
4210 *
4211 * @static
4212 * @memberOf _
4213 * @alias head
4214 * @category Array
4215 * @param {Array} array The array to query.
4216 * @returns {*} Returns the first element of `array`.
4217 * @example
4218 *
4219 * _.first([1, 2, 3]);
4220 * // => 1
4221 *
4222 * _.first([]);
4223 * // => undefined
4224 */
4225 function first(array) {
4226 return array ? array[0] : undefined;
4227 }
4228 /**
4229 * Flattens a nested array. If `isDeep` is `true` the array is recursively
4230 * flattened, otherwise it's only flattened a single level.
4231 *
4232 * @static
4233 * @memberOf _
4234 * @category Array
4235 * @param {Array} array The array to flatten.
4236 * @param {boolean} [isDeep] Specify a deep flatten.
4237 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4238 * @returns {Array} Returns the new flattened array.
4239 * @example
4240 *
4241 * _.flatten([1, [2, 3, [4]]]);
4242 * // => [1, 2, 3, [4]]
4243 *
4244 * // using `isDeep`
4245 * _.flatten([1, [2, 3, [4]]], true);
4246 * // => [1, 2, 3, 4]
4247 */
4248 function flatten(array, isDeep, guard) {
4249 var length = array ? array.length : 0;
4250 if (guard && isIterateeCall(array, isDeep, guard)) {
4251 isDeep = false;
4252 }
4253 return length ? baseFlatten(array, isDeep) : [];
4254 }
4255 /**
4256 * Recursively flattens a nested array.
4257 *
4258 * @static
4259 * @memberOf _
4260 * @category Array
4261 * @param {Array} array The array to recursively flatten.
4262 * @returns {Array} Returns the new flattened array.
4263 * @example
4264 *
4265 * _.flattenDeep([1, [2, 3, [4]]]);
4266 * // => [1, 2, 3, 4]
4267 */
4268 function flattenDeep(array) {
4269 var length = array ? array.length : 0;
4270 return length ? baseFlatten(array, true) : [];
4271 }
4272 /**
4273 * Gets the index at which the first occurrence of `value` is found in `array`
4274 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4275 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
4276 * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
4277 * performs a faster binary search.
4278 *
4279 * @static
4280 * @memberOf _
4281 * @category Array
4282 * @param {Array} array The array to search.
4283 * @param {*} value The value to search for.
4284 * @param {boolean|number} [fromIndex=0] The index to search from or `true`
4285 * to perform a binary search on a sorted array.
4286 * @returns {number} Returns the index of the matched value, else `-1`.
4287 * @example
4288 *
4289 * _.indexOf([1, 2, 1, 2], 2);
4290 * // => 1
4291 *
4292 * // using `fromIndex`
4293 * _.indexOf([1, 2, 1, 2], 2, 2);
4294 * // => 3
4295 *
4296 * // performing a binary search
4297 * _.indexOf([1, 1, 2, 2], 2, true);
4298 * // => 2
4299 */
4300 function indexOf(array, value, fromIndex) {
4301 var length = array ? array.length : 0;
4302 if (!length) {
4303 return -1;
4304 }
4305 if (typeof fromIndex == 'number') {
4306 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
4307 } else if (fromIndex) {
4308 var index = binaryIndex(array, value);
4309 if (index < length && (value === value ? value === array[index] : array[index] !== array[index])) {
4310 return index;
4311 }
4312 return -1;
4313 }
4314 return baseIndexOf(array, value, fromIndex || 0);
4315 }
4316 /**
4317 * Gets all but the last element of `array`.
4318 *
4319 * @static
4320 * @memberOf _
4321 * @category Array
4322 * @param {Array} array The array to query.
4323 * @returns {Array} Returns the slice of `array`.
4324 * @example
4325 *
4326 * _.initial([1, 2, 3]);
4327 * // => [1, 2]
4328 */
4329 function initial(array) {
4330 return dropRight(array, 1);
4331 }
4332 /**
4333 * Creates an array of unique values that are included in all of the provided
4334 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4335 * for equality comparisons.
4336 *
4337 * @static
4338 * @memberOf _
4339 * @category Array
4340 * @param {...Array} [arrays] The arrays to inspect.
4341 * @returns {Array} Returns the new array of shared values.
4342 * @example
4343 * _.intersection([1, 2], [4, 2], [2, 1]);
4344 * // => [2]
4345 */
4346 var intersection = restParam(function (arrays) {
4347 var othLength = arrays.length, othIndex = othLength, caches = Array(length), indexOf = getIndexOf(), isCommon = indexOf === baseIndexOf, result = [];
4348 while (othIndex--) {
4349 var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
4350 caches[othIndex] = isCommon && value.length >= 120 ? createCache(othIndex && value) : null;
4351 }
4352 var array = arrays[0], index = -1, length = array ? array.length : 0, seen = caches[0];
4353 outer:
4354 while (++index < length) {
4355 value = array[index];
4356 if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
4357 var othIndex = othLength;
4358 while (--othIndex) {
4359 var cache = caches[othIndex];
4360 if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
4361 continue outer;
4362 }
4363 }
4364 if (seen) {
4365 seen.push(value);
4366 }
4367 result.push(value);
4368 }
4369 }
4370 return result;
4371 });
4372 /**
4373 * Gets the last element of `array`.
4374 *
4375 * @static
4376 * @memberOf _
4377 * @category Array
4378 * @param {Array} array The array to query.
4379 * @returns {*} Returns the last element of `array`.
4380 * @example
4381 *
4382 * _.last([1, 2, 3]);
4383 * // => 3
4384 */
4385 function last(array) {
4386 var length = array ? array.length : 0;
4387 return length ? array[length - 1] : undefined;
4388 }
4389 /**
4390 * This method is like `_.indexOf` except that it iterates over elements of
4391 * `array` from right to left.
4392 *
4393 * @static
4394 * @memberOf _
4395 * @category Array
4396 * @param {Array} array The array to search.
4397 * @param {*} value The value to search for.
4398 * @param {boolean|number} [fromIndex=array.length-1] The index to search from
4399 * or `true` to perform a binary search on a sorted array.
4400 * @returns {number} Returns the index of the matched value, else `-1`.
4401 * @example
4402 *
4403 * _.lastIndexOf([1, 2, 1, 2], 2);
4404 * // => 3
4405 *
4406 * // using `fromIndex`
4407 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
4408 * // => 1
4409 *
4410 * // performing a binary search
4411 * _.lastIndexOf([1, 1, 2, 2], 2, true);
4412 * // => 3
4413 */
4414 function lastIndexOf(array, value, fromIndex) {
4415 var length = array ? array.length : 0;
4416 if (!length) {
4417 return -1;
4418 }
4419 var index = length;
4420 if (typeof fromIndex == 'number') {
4421 index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
4422 } else if (fromIndex) {
4423 index = binaryIndex(array, value, true) - 1;
4424 var other = array[index];
4425 if (value === value ? value === other : other !== other) {
4426 return index;
4427 }
4428 return -1;
4429 }
4430 if (value !== value) {
4431 return indexOfNaN(array, index, true);
4432 }
4433 while (index--) {
4434 if (array[index] === value) {
4435 return index;
4436 }
4437 }
4438 return -1;
4439 }
4440 /**
4441 * Removes all provided values from `array` using
4442 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4443 * for equality comparisons.
4444 *
4445 * **Note:** Unlike `_.without`, this method mutates `array`.
4446 *
4447 * @static
4448 * @memberOf _
4449 * @category Array
4450 * @param {Array} array The array to modify.
4451 * @param {...*} [values] The values to remove.
4452 * @returns {Array} Returns `array`.
4453 * @example
4454 *
4455 * var array = [1, 2, 3, 1, 2, 3];
4456 *
4457 * _.pull(array, 2, 3);
4458 * console.log(array);
4459 * // => [1, 1]
4460 */
4461 function pull() {
4462 var args = arguments, array = args[0];
4463 if (!(array && array.length)) {
4464 return array;
4465 }
4466 var index = 0, indexOf = getIndexOf(), length = args.length;
4467 while (++index < length) {
4468 var fromIndex = 0, value = args[index];
4469 while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
4470 splice.call(array, fromIndex, 1);
4471 }
4472 }
4473 return array;
4474 }
4475 /**
4476 * Removes elements from `array` corresponding to the given indexes and returns
4477 * an array of the removed elements. Indexes may be specified as an array of
4478 * indexes or as individual arguments.
4479 *
4480 * **Note:** Unlike `_.at`, this method mutates `array`.
4481 *
4482 * @static
4483 * @memberOf _
4484 * @category Array
4485 * @param {Array} array The array to modify.
4486 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
4487 * specified as individual indexes or arrays of indexes.
4488 * @returns {Array} Returns the new array of removed elements.
4489 * @example
4490 *
4491 * var array = [5, 10, 15, 20];
4492 * var evens = _.pullAt(array, 1, 3);
4493 *
4494 * console.log(array);
4495 * // => [5, 15]
4496 *
4497 * console.log(evens);
4498 * // => [10, 20]
4499 */
4500 var pullAt = restParam(function (array, indexes) {
4501 indexes = baseFlatten(indexes);
4502 var result = baseAt(array, indexes);
4503 basePullAt(array, indexes.sort(baseCompareAscending));
4504 return result;
4505 });
4506 /**
4507 * Removes all elements from `array` that `predicate` returns truthy for
4508 * and returns an array of the removed elements. The predicate is bound to
4509 * `thisArg` and invoked with three arguments: (value, index, array).
4510 *
4511 * If a property name is provided for `predicate` the created `_.property`
4512 * style callback returns the property value of the given element.
4513 *
4514 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4515 * style callback returns `true` for elements that have a matching property
4516 * value, else `false`.
4517 *
4518 * If an object is provided for `predicate` the created `_.matches` style
4519 * callback returns `true` for elements that have the properties of the given
4520 * object, else `false`.
4521 *
4522 * **Note:** Unlike `_.filter`, this method mutates `array`.
4523 *
4524 * @static
4525 * @memberOf _
4526 * @category Array
4527 * @param {Array} array The array to modify.
4528 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4529 * per iteration.
4530 * @param {*} [thisArg] The `this` binding of `predicate`.
4531 * @returns {Array} Returns the new array of removed elements.
4532 * @example
4533 *
4534 * var array = [1, 2, 3, 4];
4535 * var evens = _.remove(array, function(n) {
4536 * return n % 2 == 0;
4537 * });
4538 *
4539 * console.log(array);
4540 * // => [1, 3]
4541 *
4542 * console.log(evens);
4543 * // => [2, 4]
4544 */
4545 function remove(array, predicate, thisArg) {
4546 var result = [];
4547 if (!(array && array.length)) {
4548 return result;
4549 }
4550 var index = -1, indexes = [], length = array.length;
4551 predicate = getCallback(predicate, thisArg, 3);
4552 while (++index < length) {
4553 var value = array[index];
4554 if (predicate(value, index, array)) {
4555 result.push(value);
4556 indexes.push(index);
4557 }
4558 }
4559 basePullAt(array, indexes);
4560 return result;
4561 }
4562 /**
4563 * Gets all but the first element of `array`.
4564 *
4565 * @static
4566 * @memberOf _
4567 * @alias tail
4568 * @category Array
4569 * @param {Array} array The array to query.
4570 * @returns {Array} Returns the slice of `array`.
4571 * @example
4572 *
4573 * _.rest([1, 2, 3]);
4574 * // => [2, 3]
4575 */
4576 function rest(array) {
4577 return drop(array, 1);
4578 }
4579 /**
4580 * Creates a slice of `array` from `start` up to, but not including, `end`.
4581 *
4582 * **Note:** This method is used instead of `Array#slice` to support node
4583 * lists in IE < 9 and to ensure dense arrays are returned.
4584 *
4585 * @static
4586 * @memberOf _
4587 * @category Array
4588 * @param {Array} array The array to slice.
4589 * @param {number} [start=0] The start position.
4590 * @param {number} [end=array.length] The end position.
4591 * @returns {Array} Returns the slice of `array`.
4592 */
4593 function slice(array, start, end) {
4594 var length = array ? array.length : 0;
4595 if (!length) {
4596 return [];
4597 }
4598 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
4599 start = 0;
4600 end = length;
4601 }
4602 return baseSlice(array, start, end);
4603 }
4604 /**
4605 * Uses a binary search to determine the lowest index at which `value` should
4606 * be inserted into `array` in order to maintain its sort order. If an iteratee
4607 * function is provided it's invoked for `value` and each element of `array`
4608 * to compute their sort ranking. The iteratee is bound to `thisArg` and
4609 * invoked with one argument; (value).
4610 *
4611 * If a property name is provided for `iteratee` the created `_.property`
4612 * style callback returns the property value of the given element.
4613 *
4614 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4615 * style callback returns `true` for elements that have a matching property
4616 * value, else `false`.
4617 *
4618 * If an object is provided for `iteratee` the created `_.matches` style
4619 * callback returns `true` for elements that have the properties of the given
4620 * object, else `false`.
4621 *
4622 * @static
4623 * @memberOf _
4624 * @category Array
4625 * @param {Array} array The sorted array to inspect.
4626 * @param {*} value The value to evaluate.
4627 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
4628 * per iteration.
4629 * @param {*} [thisArg] The `this` binding of `iteratee`.
4630 * @returns {number} Returns the index at which `value` should be inserted
4631 * into `array`.
4632 * @example
4633 *
4634 * _.sortedIndex([30, 50], 40);
4635 * // => 1
4636 *
4637 * _.sortedIndex([4, 4, 5, 5], 5);
4638 * // => 2
4639 *
4640 * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
4641 *
4642 * // using an iteratee function
4643 * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
4644 * return this.data[word];
4645 * }, dict);
4646 * // => 1
4647 *
4648 * // using the `_.property` callback shorthand
4649 * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
4650 * // => 1
4651 */
4652 var sortedIndex = createSortedIndex();
4653 /**
4654 * This method is like `_.sortedIndex` except that it returns the highest
4655 * index at which `value` should be inserted into `array` in order to
4656 * maintain its sort order.
4657 *
4658 * @static
4659 * @memberOf _
4660 * @category Array
4661 * @param {Array} array The sorted array to inspect.
4662 * @param {*} value The value to evaluate.
4663 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
4664 * per iteration.
4665 * @param {*} [thisArg] The `this` binding of `iteratee`.
4666 * @returns {number} Returns the index at which `value` should be inserted
4667 * into `array`.
4668 * @example
4669 *
4670 * _.sortedLastIndex([4, 4, 5, 5], 5);
4671 * // => 4
4672 */
4673 var sortedLastIndex = createSortedIndex(true);
4674 /**
4675 * Creates a slice of `array` with `n` elements taken from the beginning.
4676 *
4677 * @static
4678 * @memberOf _
4679 * @category Array
4680 * @param {Array} array The array to query.
4681 * @param {number} [n=1] The number of elements to take.
4682 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4683 * @returns {Array} Returns the slice of `array`.
4684 * @example
4685 *
4686 * _.take([1, 2, 3]);
4687 * // => [1]
4688 *
4689 * _.take([1, 2, 3], 2);
4690 * // => [1, 2]
4691 *
4692 * _.take([1, 2, 3], 5);
4693 * // => [1, 2, 3]
4694 *
4695 * _.take([1, 2, 3], 0);
4696 * // => []
4697 */
4698 function take(array, n, guard) {
4699 var length = array ? array.length : 0;
4700 if (!length) {
4701 return [];
4702 }
4703 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4704 n = 1;
4705 }
4706 return baseSlice(array, 0, n < 0 ? 0 : n);
4707 }
4708 /**
4709 * Creates a slice of `array` with `n` elements taken from the end.
4710 *
4711 * @static
4712 * @memberOf _
4713 * @category Array
4714 * @param {Array} array The array to query.
4715 * @param {number} [n=1] The number of elements to take.
4716 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4717 * @returns {Array} Returns the slice of `array`.
4718 * @example
4719 *
4720 * _.takeRight([1, 2, 3]);
4721 * // => [3]
4722 *
4723 * _.takeRight([1, 2, 3], 2);
4724 * // => [2, 3]
4725 *
4726 * _.takeRight([1, 2, 3], 5);
4727 * // => [1, 2, 3]
4728 *
4729 * _.takeRight([1, 2, 3], 0);
4730 * // => []
4731 */
4732 function takeRight(array, n, guard) {
4733 var length = array ? array.length : 0;
4734 if (!length) {
4735 return [];
4736 }
4737 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4738 n = 1;
4739 }
4740 n = length - (+n || 0);
4741 return baseSlice(array, n < 0 ? 0 : n);
4742 }
4743 /**
4744 * Creates a slice of `array` with elements taken from the end. Elements are
4745 * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
4746 * and invoked with three arguments: (value, index, array).
4747 *
4748 * If a property name is provided for `predicate` the created `_.property`
4749 * style callback returns the property value of the given element.
4750 *
4751 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4752 * style callback returns `true` for elements that have a matching property
4753 * value, else `false`.
4754 *
4755 * If an object is provided for `predicate` the created `_.matches` style
4756 * callback returns `true` for elements that have the properties of the given
4757 * object, else `false`.
4758 *
4759 * @static
4760 * @memberOf _
4761 * @category Array
4762 * @param {Array} array The array to query.
4763 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4764 * per iteration.
4765 * @param {*} [thisArg] The `this` binding of `predicate`.
4766 * @returns {Array} Returns the slice of `array`.
4767 * @example
4768 *
4769 * _.takeRightWhile([1, 2, 3], function(n) {
4770 * return n > 1;
4771 * });
4772 * // => [2, 3]
4773 *
4774 * var users = [
4775 * { 'user': 'barney', 'active': true },
4776 * { 'user': 'fred', 'active': false },
4777 * { 'user': 'pebbles', 'active': false }
4778 * ];
4779 *
4780 * // using the `_.matches` callback shorthand
4781 * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
4782 * // => ['pebbles']
4783 *
4784 * // using the `_.matchesProperty` callback shorthand
4785 * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
4786 * // => ['fred', 'pebbles']
4787 *
4788 * // using the `_.property` callback shorthand
4789 * _.pluck(_.takeRightWhile(users, 'active'), 'user');
4790 * // => []
4791 */
4792 function takeRightWhile(array, predicate, thisArg) {
4793 return array && array.length ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true) : [];
4794 }
4795 /**
4796 * Creates a slice of `array` with elements taken from the beginning. Elements
4797 * are taken until `predicate` returns falsey. The predicate is bound to
4798 * `thisArg` and invoked with three arguments: (value, index, array).
4799 *
4800 * If a property name is provided for `predicate` the created `_.property`
4801 * style callback returns the property value of the given element.
4802 *
4803 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4804 * style callback returns `true` for elements that have a matching property
4805 * value, else `false`.
4806 *
4807 * If an object is provided for `predicate` the created `_.matches` style
4808 * callback returns `true` for elements that have the properties of the given
4809 * object, else `false`.
4810 *
4811 * @static
4812 * @memberOf _
4813 * @category Array
4814 * @param {Array} array The array to query.
4815 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4816 * per iteration.
4817 * @param {*} [thisArg] The `this` binding of `predicate`.
4818 * @returns {Array} Returns the slice of `array`.
4819 * @example
4820 *
4821 * _.takeWhile([1, 2, 3], function(n) {
4822 * return n < 3;
4823 * });
4824 * // => [1, 2]
4825 *
4826 * var users = [
4827 * { 'user': 'barney', 'active': false },
4828 * { 'user': 'fred', 'active': false},
4829 * { 'user': 'pebbles', 'active': true }
4830 * ];
4831 *
4832 * // using the `_.matches` callback shorthand
4833 * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
4834 * // => ['barney']
4835 *
4836 * // using the `_.matchesProperty` callback shorthand
4837 * _.pluck(_.takeWhile(users, 'active', false), 'user');
4838 * // => ['barney', 'fred']
4839 *
4840 * // using the `_.property` callback shorthand
4841 * _.pluck(_.takeWhile(users, 'active'), 'user');
4842 * // => []
4843 */
4844 function takeWhile(array, predicate, thisArg) {
4845 return array && array.length ? baseWhile(array, getCallback(predicate, thisArg, 3)) : [];
4846 }
4847 /**
4848 * Creates an array of unique values, in order, from all of the provided arrays
4849 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4850 * for equality comparisons.
4851 *
4852 * @static
4853 * @memberOf _
4854 * @category Array
4855 * @param {...Array} [arrays] The arrays to inspect.
4856 * @returns {Array} Returns the new array of combined values.
4857 * @example
4858 *
4859 * _.union([1, 2], [4, 2], [2, 1]);
4860 * // => [1, 2, 4]
4861 */
4862 var union = restParam(function (arrays) {
4863 return baseUniq(baseFlatten(arrays, false, true));
4864 });
4865 /**
4866 * Creates a duplicate-free version of an array, using
4867 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4868 * for equality comparisons, in which only the first occurence of each element
4869 * is kept. Providing `true` for `isSorted` performs a faster search algorithm
4870 * for sorted arrays. If an iteratee function is provided it's invoked for
4871 * each element in the array to generate the criterion by which uniqueness
4872 * is computed. The `iteratee` is bound to `thisArg` and invoked with three
4873 * arguments: (value, index, array).
4874 *
4875 * If a property name is provided for `iteratee` the created `_.property`
4876 * style callback returns the property value of the given element.
4877 *
4878 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4879 * style callback returns `true` for elements that have a matching property
4880 * value, else `false`.
4881 *
4882 * If an object is provided for `iteratee` the created `_.matches` style
4883 * callback returns `true` for elements that have the properties of the given
4884 * object, else `false`.
4885 *
4886 * @static
4887 * @memberOf _
4888 * @alias unique
4889 * @category Array
4890 * @param {Array} array The array to inspect.
4891 * @param {boolean} [isSorted] Specify the array is sorted.
4892 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
4893 * @param {*} [thisArg] The `this` binding of `iteratee`.
4894 * @returns {Array} Returns the new duplicate-value-free array.
4895 * @example
4896 *
4897 * _.uniq([2, 1, 2]);
4898 * // => [2, 1]
4899 *
4900 * // using `isSorted`
4901 * _.uniq([1, 1, 2], true);
4902 * // => [1, 2]
4903 *
4904 * // using an iteratee function
4905 * _.uniq([1, 2.5, 1.5, 2], function(n) {
4906 * return this.floor(n);
4907 * }, Math);
4908 * // => [1, 2.5]
4909 *
4910 * // using the `_.property` callback shorthand
4911 * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
4912 * // => [{ 'x': 1 }, { 'x': 2 }]
4913 */
4914 function uniq(array, isSorted, iteratee, thisArg) {
4915 var length = array ? array.length : 0;
4916 if (!length) {
4917 return [];
4918 }
4919 if (isSorted != null && typeof isSorted != 'boolean') {
4920 thisArg = iteratee;
4921 iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
4922 isSorted = false;
4923 }
4924 var callback = getCallback();
4925 if (!(iteratee == null && callback === baseCallback)) {
4926 iteratee = callback(iteratee, thisArg, 3);
4927 }
4928 return isSorted && getIndexOf() === baseIndexOf ? sortedUniq(array, iteratee) : baseUniq(array, iteratee);
4929 }
4930 /**
4931 * This method is like `_.zip` except that it accepts an array of grouped
4932 * elements and creates an array regrouping the elements to their pre-zip
4933 * configuration.
4934 *
4935 * @static
4936 * @memberOf _
4937 * @category Array
4938 * @param {Array} array The array of grouped elements to process.
4939 * @returns {Array} Returns the new array of regrouped elements.
4940 * @example
4941 *
4942 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
4943 * // => [['fred', 30, true], ['barney', 40, false]]
4944 *
4945 * _.unzip(zipped);
4946 * // => [['fred', 'barney'], [30, 40], [true, false]]
4947 */
4948 function unzip(array) {
4949 if (!(array && array.length)) {
4950 return [];
4951 }
4952 var index = -1, length = 0;
4953 array = arrayFilter(array, function (group) {
4954 if (isArrayLike(group)) {
4955 length = nativeMax(group.length, length);
4956 return true;
4957 }
4958 });
4959 var result = Array(length);
4960 while (++index < length) {
4961 result[index] = arrayMap(array, baseProperty(index));
4962 }
4963 return result;
4964 }
4965 /**
4966 * This method is like `_.unzip` except that it accepts an iteratee to specify
4967 * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
4968 * and invoked with four arguments: (accumulator, value, index, group).
4969 *
4970 * @static
4971 * @memberOf _
4972 * @category Array
4973 * @param {Array} array The array of grouped elements to process.
4974 * @param {Function} [iteratee] The function to combine regrouped values.
4975 * @param {*} [thisArg] The `this` binding of `iteratee`.
4976 * @returns {Array} Returns the new array of regrouped elements.
4977 * @example
4978 *
4979 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
4980 * // => [[1, 10, 100], [2, 20, 200]]
4981 *
4982 * _.unzipWith(zipped, _.add);
4983 * // => [3, 30, 300]
4984 */
4985 function unzipWith(array, iteratee, thisArg) {
4986 var length = array ? array.length : 0;
4987 if (!length) {
4988 return [];
4989 }
4990 var result = unzip(array);
4991 if (iteratee == null) {
4992 return result;
4993 }
4994 iteratee = bindCallback(iteratee, thisArg, 4);
4995 return arrayMap(result, function (group) {
4996 return arrayReduce(group, iteratee, undefined, true);
4997 });
4998 }
4999 /**
5000 * Creates an array excluding all provided values using
5001 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5002 * for equality comparisons.
5003 *
5004 * @static
5005 * @memberOf _
5006 * @category Array
5007 * @param {Array} array The array to filter.
5008 * @param {...*} [values] The values to exclude.
5009 * @returns {Array} Returns the new array of filtered values.
5010 * @example
5011 *
5012 * _.without([1, 2, 1, 3], 1, 2);
5013 * // => [3]
5014 */
5015 var without = restParam(function (array, values) {
5016 return isArrayLike(array) ? baseDifference(array, values) : [];
5017 });
5018 /**
5019 * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
5020 * of the provided arrays.
5021 *
5022 * @static
5023 * @memberOf _
5024 * @category Array
5025 * @param {...Array} [arrays] The arrays to inspect.
5026 * @returns {Array} Returns the new array of values.
5027 * @example
5028 *
5029 * _.xor([1, 2], [4, 2]);
5030 * // => [1, 4]
5031 */
5032 function xor() {
5033 var index = -1, length = arguments.length;
5034 while (++index < length) {
5035 var array = arguments[index];
5036 if (isArrayLike(array)) {
5037 var result = result ? arrayPush(baseDifference(result, array), baseDifference(array, result)) : array;
5038 }
5039 }
5040 return result ? baseUniq(result) : [];
5041 }
5042 /**
5043 * Creates an array of grouped elements, the first of which contains the first
5044 * elements of the given arrays, the second of which contains the second elements
5045 * of the given arrays, and so on.
5046 *
5047 * @static
5048 * @memberOf _
5049 * @category Array
5050 * @param {...Array} [arrays] The arrays to process.
5051 * @returns {Array} Returns the new array of grouped elements.
5052 * @example
5053 *
5054 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
5055 * // => [['fred', 30, true], ['barney', 40, false]]
5056 */
5057 var zip = restParam(unzip);
5058 /**
5059 * The inverse of `_.pairs`; this method returns an object composed from arrays
5060 * of property names and values. Provide either a single two dimensional array,
5061 * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
5062 * and one of corresponding values.
5063 *
5064 * @static
5065 * @memberOf _
5066 * @alias object
5067 * @category Array
5068 * @param {Array} props The property names.
5069 * @param {Array} [values=[]] The property values.
5070 * @returns {Object} Returns the new object.
5071 * @example
5072 *
5073 * _.zipObject([['fred', 30], ['barney', 40]]);
5074 * // => { 'fred': 30, 'barney': 40 }
5075 *
5076 * _.zipObject(['fred', 'barney'], [30, 40]);
5077 * // => { 'fred': 30, 'barney': 40 }
5078 */
5079 function zipObject(props, values) {
5080 var index = -1, length = props ? props.length : 0, result = {};
5081 if (length && !values && !isArray(props[0])) {
5082 values = [];
5083 }
5084 while (++index < length) {
5085 var key = props[index];
5086 if (values) {
5087 result[key] = values[index];
5088 } else if (key) {
5089 result[key[0]] = key[1];
5090 }
5091 }
5092 return result;
5093 }
5094 /**
5095 * This method is like `_.zip` except that it accepts an iteratee to specify
5096 * how grouped values should be combined. The `iteratee` is bound to `thisArg`
5097 * and invoked with four arguments: (accumulator, value, index, group).
5098 *
5099 * @static
5100 * @memberOf _
5101 * @category Array
5102 * @param {...Array} [arrays] The arrays to process.
5103 * @param {Function} [iteratee] The function to combine grouped values.
5104 * @param {*} [thisArg] The `this` binding of `iteratee`.
5105 * @returns {Array} Returns the new array of grouped elements.
5106 * @example
5107 *
5108 * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
5109 * // => [111, 222]
5110 */
5111 var zipWith = restParam(function (arrays) {
5112 var length = arrays.length, iteratee = length > 2 ? arrays[length - 2] : undefined, thisArg = length > 1 ? arrays[length - 1] : undefined;
5113 if (length > 2 && typeof iteratee == 'function') {
5114 length -= 2;
5115 } else {
5116 iteratee = length > 1 && typeof thisArg == 'function' ? (--length, thisArg) : undefined;
5117 thisArg = undefined;
5118 }
5119 arrays.length = length;
5120 return unzipWith(arrays, iteratee, thisArg);
5121 });
5122 /*------------------------------------------------------------------------*/
5123 /**
5124 * Creates a `lodash` object that wraps `value` with explicit method
5125 * chaining enabled.
5126 *
5127 * @static
5128 * @memberOf _
5129 * @category Chain
5130 * @param {*} value The value to wrap.
5131 * @returns {Object} Returns the new `lodash` wrapper instance.
5132 * @example
5133 *
5134 * var users = [
5135 * { 'user': 'barney', 'age': 36 },
5136 * { 'user': 'fred', 'age': 40 },
5137 * { 'user': 'pebbles', 'age': 1 }
5138 * ];
5139 *
5140 * var youngest = _.chain(users)
5141 * .sortBy('age')
5142 * .map(function(chr) {
5143 * return chr.user + ' is ' + chr.age;
5144 * })
5145 * .first()
5146 * .value();
5147 * // => 'pebbles is 1'
5148 */
5149 function chain(value) {
5150 var result = lodash(value);
5151 result.__chain__ = true;
5152 return result;
5153 }
5154 /**
5155 * This method invokes `interceptor` and returns `value`. The interceptor is
5156 * bound to `thisArg` and invoked with one argument; (value). The purpose of
5157 * this method is to "tap into" a method chain in order to perform operations
5158 * on intermediate results within the chain.
5159 *
5160 * @static
5161 * @memberOf _
5162 * @category Chain
5163 * @param {*} value The value to provide to `interceptor`.
5164 * @param {Function} interceptor The function to invoke.
5165 * @param {*} [thisArg] The `this` binding of `interceptor`.
5166 * @returns {*} Returns `value`.
5167 * @example
5168 *
5169 * _([1, 2, 3])
5170 * .tap(function(array) {
5171 * array.pop();
5172 * })
5173 * .reverse()
5174 * .value();
5175 * // => [2, 1]
5176 */
5177 function tap(value, interceptor, thisArg) {
5178 interceptor.call(thisArg, value);
5179 return value;
5180 }
5181 /**
5182 * This method is like `_.tap` except that it returns the result of `interceptor`.
5183 *
5184 * @static
5185 * @memberOf _
5186 * @category Chain
5187 * @param {*} value The value to provide to `interceptor`.
5188 * @param {Function} interceptor The function to invoke.
5189 * @param {*} [thisArg] The `this` binding of `interceptor`.
5190 * @returns {*} Returns the result of `interceptor`.
5191 * @example
5192 *
5193 * _(' abc ')
5194 * .chain()
5195 * .trim()
5196 * .thru(function(value) {
5197 * return [value];
5198 * })
5199 * .value();
5200 * // => ['abc']
5201 */
5202 function thru(value, interceptor, thisArg) {
5203 return interceptor.call(thisArg, value);
5204 }
5205 /**
5206 * Enables explicit method chaining on the wrapper object.
5207 *
5208 * @name chain
5209 * @memberOf _
5210 * @category Chain
5211 * @returns {Object} Returns the new `lodash` wrapper instance.
5212 * @example
5213 *
5214 * var users = [
5215 * { 'user': 'barney', 'age': 36 },
5216 * { 'user': 'fred', 'age': 40 }
5217 * ];
5218 *
5219 * // without explicit chaining
5220 * _(users).first();
5221 * // => { 'user': 'barney', 'age': 36 }
5222 *
5223 * // with explicit chaining
5224 * _(users).chain()
5225 * .first()
5226 * .pick('user')
5227 * .value();
5228 * // => { 'user': 'barney' }
5229 */
5230 function wrapperChain() {
5231 return chain(this);
5232 }
5233 /**
5234 * Executes the chained sequence and returns the wrapped result.
5235 *
5236 * @name commit
5237 * @memberOf _
5238 * @category Chain
5239 * @returns {Object} Returns the new `lodash` wrapper instance.
5240 * @example
5241 *
5242 * var array = [1, 2];
5243 * var wrapped = _(array).push(3);
5244 *
5245 * console.log(array);
5246 * // => [1, 2]
5247 *
5248 * wrapped = wrapped.commit();
5249 * console.log(array);
5250 * // => [1, 2, 3]
5251 *
5252 * wrapped.last();
5253 * // => 3
5254 *
5255 * console.log(array);
5256 * // => [1, 2, 3]
5257 */
5258 function wrapperCommit() {
5259 return new LodashWrapper(this.value(), this.__chain__);
5260 }
5261 /**
5262 * Creates a new array joining a wrapped array with any additional arrays
5263 * and/or values.
5264 *
5265 * @name concat
5266 * @memberOf _
5267 * @category Chain
5268 * @param {...*} [values] The values to concatenate.
5269 * @returns {Array} Returns the new concatenated array.
5270 * @example
5271 *
5272 * var array = [1];
5273 * var wrapped = _(array).concat(2, [3], [[4]]);
5274 *
5275 * console.log(wrapped.value());
5276 * // => [1, 2, 3, [4]]
5277 *
5278 * console.log(array);
5279 * // => [1]
5280 */
5281 var wrapperConcat = restParam(function (values) {
5282 values = baseFlatten(values);
5283 return this.thru(function (array) {
5284 return arrayConcat(isArray(array) ? array : [toObject(array)], values);
5285 });
5286 });
5287 /**
5288 * Creates a clone of the chained sequence planting `value` as the wrapped value.
5289 *
5290 * @name plant
5291 * @memberOf _
5292 * @category Chain
5293 * @returns {Object} Returns the new `lodash` wrapper instance.
5294 * @example
5295 *
5296 * var array = [1, 2];
5297 * var wrapped = _(array).map(function(value) {
5298 * return Math.pow(value, 2);
5299 * });
5300 *
5301 * var other = [3, 4];
5302 * var otherWrapped = wrapped.plant(other);
5303 *
5304 * otherWrapped.value();
5305 * // => [9, 16]
5306 *
5307 * wrapped.value();
5308 * // => [1, 4]
5309 */
5310 function wrapperPlant(value) {
5311 var result, parent = this;
5312 while (parent instanceof baseLodash) {
5313 var clone = wrapperClone(parent);
5314 if (result) {
5315 previous.__wrapped__ = clone;
5316 } else {
5317 result = clone;
5318 }
5319 var previous = clone;
5320 parent = parent.__wrapped__;
5321 }
5322 previous.__wrapped__ = value;
5323 return result;
5324 }
5325 /**
5326 * Reverses the wrapped array so the first element becomes the last, the
5327 * second element becomes the second to last, and so on.
5328 *
5329 * **Note:** This method mutates the wrapped array.
5330 *
5331 * @name reverse
5332 * @memberOf _
5333 * @category Chain
5334 * @returns {Object} Returns the new reversed `lodash` wrapper instance.
5335 * @example
5336 *
5337 * var array = [1, 2, 3];
5338 *
5339 * _(array).reverse().value()
5340 * // => [3, 2, 1]
5341 *
5342 * console.log(array);
5343 * // => [3, 2, 1]
5344 */
5345 function wrapperReverse() {
5346 var value = this.__wrapped__;
5347 var interceptor = function (value) {
5348 return value.reverse();
5349 };
5350 if (value instanceof LazyWrapper) {
5351 var wrapped = value;
5352 if (this.__actions__.length) {
5353 wrapped = new LazyWrapper(this);
5354 }
5355 wrapped = wrapped.reverse();
5356 wrapped.__actions__.push({
5357 'func': thru,
5358 'args': [interceptor],
5359 'thisArg': undefined
5360 });
5361 return new LodashWrapper(wrapped, this.__chain__);
5362 }
5363 return this.thru(interceptor);
5364 }
5365 /**
5366 * Produces the result of coercing the unwrapped value to a string.
5367 *
5368 * @name toString
5369 * @memberOf _
5370 * @category Chain
5371 * @returns {string} Returns the coerced string value.
5372 * @example
5373 *
5374 * _([1, 2, 3]).toString();
5375 * // => '1,2,3'
5376 */
5377 function wrapperToString() {
5378 return this.value() + '';
5379 }
5380 /**
5381 * Executes the chained sequence to extract the unwrapped value.
5382 *
5383 * @name value
5384 * @memberOf _
5385 * @alias run, toJSON, valueOf
5386 * @category Chain
5387 * @returns {*} Returns the resolved unwrapped value.
5388 * @example
5389 *
5390 * _([1, 2, 3]).value();
5391 * // => [1, 2, 3]
5392 */
5393 function wrapperValue() {
5394 return baseWrapperValue(this.__wrapped__, this.__actions__);
5395 }
5396 /*------------------------------------------------------------------------*/
5397 /**
5398 * Creates an array of elements corresponding to the given keys, or indexes,
5399 * of `collection`. Keys may be specified as individual arguments or as arrays
5400 * of keys.
5401 *
5402 * @static
5403 * @memberOf _
5404 * @category Collection
5405 * @param {Array|Object|string} collection The collection to iterate over.
5406 * @param {...(number|number[]|string|string[])} [props] The property names
5407 * or indexes of elements to pick, specified individually or in arrays.
5408 * @returns {Array} Returns the new array of picked elements.
5409 * @example
5410 *
5411 * _.at(['a', 'b', 'c'], [0, 2]);
5412 * // => ['a', 'c']
5413 *
5414 * _.at(['barney', 'fred', 'pebbles'], 0, 2);
5415 * // => ['barney', 'pebbles']
5416 */
5417 var at = restParam(function (collection, props) {
5418 return baseAt(collection, baseFlatten(props));
5419 });
5420 /**
5421 * Creates an object composed of keys generated from the results of running
5422 * each element of `collection` through `iteratee`. The corresponding value
5423 * of each key is the number of times the key was returned by `iteratee`.
5424 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
5425 * (value, index|key, collection).
5426 *
5427 * If a property name is provided for `iteratee` the created `_.property`
5428 * style callback returns the property value of the given element.
5429 *
5430 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5431 * style callback returns `true` for elements that have a matching property
5432 * value, else `false`.
5433 *
5434 * If an object is provided for `iteratee` the created `_.matches` style
5435 * callback returns `true` for elements that have the properties of the given
5436 * object, else `false`.
5437 *
5438 * @static
5439 * @memberOf _
5440 * @category Collection
5441 * @param {Array|Object|string} collection The collection to iterate over.
5442 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5443 * per iteration.
5444 * @param {*} [thisArg] The `this` binding of `iteratee`.
5445 * @returns {Object} Returns the composed aggregate object.
5446 * @example
5447 *
5448 * _.countBy([4.3, 6.1, 6.4], function(n) {
5449 * return Math.floor(n);
5450 * });
5451 * // => { '4': 1, '6': 2 }
5452 *
5453 * _.countBy([4.3, 6.1, 6.4], function(n) {
5454 * return this.floor(n);
5455 * }, Math);
5456 * // => { '4': 1, '6': 2 }
5457 *
5458 * _.countBy(['one', 'two', 'three'], 'length');
5459 * // => { '3': 2, '5': 1 }
5460 */
5461 var countBy = createAggregator(function (result, value, key) {
5462 hasOwnProperty.call(result, key) ? ++result[key] : result[key] = 1;
5463 });
5464 /**
5465 * Checks if `predicate` returns truthy for **all** elements of `collection`.
5466 * The predicate is bound to `thisArg` and invoked with three arguments:
5467 * (value, index|key, collection).
5468 *
5469 * If a property name is provided for `predicate` the created `_.property`
5470 * style callback returns the property value of the given element.
5471 *
5472 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5473 * style callback returns `true` for elements that have a matching property
5474 * value, else `false`.
5475 *
5476 * If an object is provided for `predicate` the created `_.matches` style
5477 * callback returns `true` for elements that have the properties of the given
5478 * object, else `false`.
5479 *
5480 * @static
5481 * @memberOf _
5482 * @alias all
5483 * @category Collection
5484 * @param {Array|Object|string} collection The collection to iterate over.
5485 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5486 * per iteration.
5487 * @param {*} [thisArg] The `this` binding of `predicate`.
5488 * @returns {boolean} Returns `true` if all elements pass the predicate check,
5489 * else `false`.
5490 * @example
5491 *
5492 * _.every([true, 1, null, 'yes'], Boolean);
5493 * // => false
5494 *
5495 * var users = [
5496 * { 'user': 'barney', 'active': false },
5497 * { 'user': 'fred', 'active': false }
5498 * ];
5499 *
5500 * // using the `_.matches` callback shorthand
5501 * _.every(users, { 'user': 'barney', 'active': false });
5502 * // => false
5503 *
5504 * // using the `_.matchesProperty` callback shorthand
5505 * _.every(users, 'active', false);
5506 * // => true
5507 *
5508 * // using the `_.property` callback shorthand
5509 * _.every(users, 'active');
5510 * // => false
5511 */
5512 function every(collection, predicate, thisArg) {
5513 var func = isArray(collection) ? arrayEvery : baseEvery;
5514 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
5515 predicate = undefined;
5516 }
5517 if (typeof predicate != 'function' || thisArg !== undefined) {
5518 predicate = getCallback(predicate, thisArg, 3);
5519 }
5520 return func(collection, predicate);
5521 }
5522 /**
5523 * Iterates over elements of `collection`, returning an array of all elements
5524 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
5525 * invoked with three arguments: (value, index|key, collection).
5526 *
5527 * If a property name is provided for `predicate` the created `_.property`
5528 * style callback returns the property value of the given element.
5529 *
5530 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5531 * style callback returns `true` for elements that have a matching property
5532 * value, else `false`.
5533 *
5534 * If an object is provided for `predicate` the created `_.matches` style
5535 * callback returns `true` for elements that have the properties of the given
5536 * object, else `false`.
5537 *
5538 * @static
5539 * @memberOf _
5540 * @alias select
5541 * @category Collection
5542 * @param {Array|Object|string} collection The collection to iterate over.
5543 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5544 * per iteration.
5545 * @param {*} [thisArg] The `this` binding of `predicate`.
5546 * @returns {Array} Returns the new filtered array.
5547 * @example
5548 *
5549 * _.filter([4, 5, 6], function(n) {
5550 * return n % 2 == 0;
5551 * });
5552 * // => [4, 6]
5553 *
5554 * var users = [
5555 * { 'user': 'barney', 'age': 36, 'active': true },
5556 * { 'user': 'fred', 'age': 40, 'active': false }
5557 * ];
5558 *
5559 * // using the `_.matches` callback shorthand
5560 * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
5561 * // => ['barney']
5562 *
5563 * // using the `_.matchesProperty` callback shorthand
5564 * _.pluck(_.filter(users, 'active', false), 'user');
5565 * // => ['fred']
5566 *
5567 * // using the `_.property` callback shorthand
5568 * _.pluck(_.filter(users, 'active'), 'user');
5569 * // => ['barney']
5570 */
5571 function filter(collection, predicate, thisArg) {
5572 var func = isArray(collection) ? arrayFilter : baseFilter;
5573 predicate = getCallback(predicate, thisArg, 3);
5574 return func(collection, predicate);
5575 }
5576 /**
5577 * Iterates over elements of `collection`, returning the first element
5578 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
5579 * invoked with three arguments: (value, index|key, collection).
5580 *
5581 * If a property name is provided for `predicate` the created `_.property`
5582 * style callback returns the property value of the given element.
5583 *
5584 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5585 * style callback returns `true` for elements that have a matching property
5586 * value, else `false`.
5587 *
5588 * If an object is provided for `predicate` the created `_.matches` style
5589 * callback returns `true` for elements that have the properties of the given
5590 * object, else `false`.
5591 *
5592 * @static
5593 * @memberOf _
5594 * @alias detect
5595 * @category Collection
5596 * @param {Array|Object|string} collection The collection to search.
5597 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5598 * per iteration.
5599 * @param {*} [thisArg] The `this` binding of `predicate`.
5600 * @returns {*} Returns the matched element, else `undefined`.
5601 * @example
5602 *
5603 * var users = [
5604 * { 'user': 'barney', 'age': 36, 'active': true },
5605 * { 'user': 'fred', 'age': 40, 'active': false },
5606 * { 'user': 'pebbles', 'age': 1, 'active': true }
5607 * ];
5608 *
5609 * _.result(_.find(users, function(chr) {
5610 * return chr.age < 40;
5611 * }), 'user');
5612 * // => 'barney'
5613 *
5614 * // using the `_.matches` callback shorthand
5615 * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
5616 * // => 'pebbles'
5617 *
5618 * // using the `_.matchesProperty` callback shorthand
5619 * _.result(_.find(users, 'active', false), 'user');
5620 * // => 'fred'
5621 *
5622 * // using the `_.property` callback shorthand
5623 * _.result(_.find(users, 'active'), 'user');
5624 * // => 'barney'
5625 */
5626 var find = createFind(baseEach);
5627 /**
5628 * This method is like `_.find` except that it iterates over elements of
5629 * `collection` from right to left.
5630 *
5631 * @static
5632 * @memberOf _
5633 * @category Collection
5634 * @param {Array|Object|string} collection The collection to search.
5635 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5636 * per iteration.
5637 * @param {*} [thisArg] The `this` binding of `predicate`.
5638 * @returns {*} Returns the matched element, else `undefined`.
5639 * @example
5640 *
5641 * _.findLast([1, 2, 3, 4], function(n) {
5642 * return n % 2 == 1;
5643 * });
5644 * // => 3
5645 */
5646 var findLast = createFind(baseEachRight, true);
5647 /**
5648 * Performs a deep comparison between each element in `collection` and the
5649 * source object, returning the first element that has equivalent property
5650 * values.
5651 *
5652 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
5653 * numbers, `Object` objects, regexes, and strings. Objects are compared by
5654 * their own, not inherited, enumerable properties. For comparing a single
5655 * own or inherited property value see `_.matchesProperty`.
5656 *
5657 * @static
5658 * @memberOf _
5659 * @category Collection
5660 * @param {Array|Object|string} collection The collection to search.
5661 * @param {Object} source The object of property values to match.
5662 * @returns {*} Returns the matched element, else `undefined`.
5663 * @example
5664 *
5665 * var users = [
5666 * { 'user': 'barney', 'age': 36, 'active': true },
5667 * { 'user': 'fred', 'age': 40, 'active': false }
5668 * ];
5669 *
5670 * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
5671 * // => 'barney'
5672 *
5673 * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
5674 * // => 'fred'
5675 */
5676 function findWhere(collection, source) {
5677 return find(collection, baseMatches(source));
5678 }
5679 /**
5680 * Iterates over elements of `collection` invoking `iteratee` for each element.
5681 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
5682 * (value, index|key, collection). Iteratee functions may exit iteration early
5683 * by explicitly returning `false`.
5684 *
5685 * **Note:** As with other "Collections" methods, objects with a "length" property
5686 * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
5687 * may be used for object iteration.
5688 *
5689 * @static
5690 * @memberOf _
5691 * @alias each
5692 * @category Collection
5693 * @param {Array|Object|string} collection The collection to iterate over.
5694 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
5695 * @param {*} [thisArg] The `this` binding of `iteratee`.
5696 * @returns {Array|Object|string} Returns `collection`.
5697 * @example
5698 *
5699 * _([1, 2]).forEach(function(n) {
5700 * console.log(n);
5701 * }).value();
5702 * // => logs each value from left to right and returns the array
5703 *
5704 * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
5705 * console.log(n, key);
5706 * });
5707 * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
5708 */
5709 var forEach = createForEach(arrayEach, baseEach);
5710 /**
5711 * This method is like `_.forEach` except that it iterates over elements of
5712 * `collection` from right to left.
5713 *
5714 * @static
5715 * @memberOf _
5716 * @alias eachRight
5717 * @category Collection
5718 * @param {Array|Object|string} collection The collection to iterate over.
5719 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
5720 * @param {*} [thisArg] The `this` binding of `iteratee`.
5721 * @returns {Array|Object|string} Returns `collection`.
5722 * @example
5723 *
5724 * _([1, 2]).forEachRight(function(n) {
5725 * console.log(n);
5726 * }).value();
5727 * // => logs each value from right to left and returns the array
5728 */
5729 var forEachRight = createForEach(arrayEachRight, baseEachRight);
5730 /**
5731 * Creates an object composed of keys generated from the results of running
5732 * each element of `collection` through `iteratee`. The corresponding value
5733 * of each key is an array of the elements responsible for generating the key.
5734 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
5735 * (value, index|key, collection).
5736 *
5737 * If a property name is provided for `iteratee` the created `_.property`
5738 * style callback returns the property value of the given element.
5739 *
5740 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5741 * style callback returns `true` for elements that have a matching property
5742 * value, else `false`.
5743 *
5744 * If an object is provided for `iteratee` the created `_.matches` style
5745 * callback returns `true` for elements that have the properties of the given
5746 * object, else `false`.
5747 *
5748 * @static
5749 * @memberOf _
5750 * @category Collection
5751 * @param {Array|Object|string} collection The collection to iterate over.
5752 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5753 * per iteration.
5754 * @param {*} [thisArg] The `this` binding of `iteratee`.
5755 * @returns {Object} Returns the composed aggregate object.
5756 * @example
5757 *
5758 * _.groupBy([4.2, 6.1, 6.4], function(n) {
5759 * return Math.floor(n);
5760 * });
5761 * // => { '4': [4.2], '6': [6.1, 6.4] }
5762 *
5763 * _.groupBy([4.2, 6.1, 6.4], function(n) {
5764 * return this.floor(n);
5765 * }, Math);
5766 * // => { '4': [4.2], '6': [6.1, 6.4] }
5767 *
5768 * // using the `_.property` callback shorthand
5769 * _.groupBy(['one', 'two', 'three'], 'length');
5770 * // => { '3': ['one', 'two'], '5': ['three'] }
5771 */
5772 var groupBy = createAggregator(function (result, value, key) {
5773 if (hasOwnProperty.call(result, key)) {
5774 result[key].push(value);
5775 } else {
5776 result[key] = [value];
5777 }
5778 });
5779 /**
5780 * Checks if `target` is in `collection` using
5781 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5782 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
5783 * from the end of `collection`.
5784 *
5785 * @static
5786 * @memberOf _
5787 * @alias contains, include
5788 * @category Collection
5789 * @param {Array|Object|string} collection The collection to search.
5790 * @param {*} target The value to search for.
5791 * @param {number} [fromIndex=0] The index to search from.
5792 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
5793 * @returns {boolean} Returns `true` if a matching element is found, else `false`.
5794 * @example
5795 *
5796 * _.includes([1, 2, 3], 1);
5797 * // => true
5798 *
5799 * _.includes([1, 2, 3], 1, 2);
5800 * // => false
5801 *
5802 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
5803 * // => true
5804 *
5805 * _.includes('pebbles', 'eb');
5806 * // => true
5807 */
5808 function includes(collection, target, fromIndex, guard) {
5809 var length = collection ? getLength(collection) : 0;
5810 if (!isLength(length)) {
5811 collection = values(collection);
5812 length = collection.length;
5813 }
5814 if (typeof fromIndex != 'number' || guard && isIterateeCall(target, fromIndex, guard)) {
5815 fromIndex = 0;
5816 } else {
5817 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex || 0;
5818 }
5819 return typeof collection == 'string' || !isArray(collection) && isString(collection) ? fromIndex <= length && collection.indexOf(target, fromIndex) > -1 : !!length && getIndexOf(collection, target, fromIndex) > -1;
5820 }
5821 /**
5822 * Creates an object composed of keys generated from the results of running
5823 * each element of `collection` through `iteratee`. The corresponding value
5824 * of each key is the last element responsible for generating the key. The
5825 * iteratee function is bound to `thisArg` and invoked with three arguments:
5826 * (value, index|key, collection).
5827 *
5828 * If a property name is provided for `iteratee` the created `_.property`
5829 * style callback returns the property value of the given element.
5830 *
5831 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5832 * style callback returns `true` for elements that have a matching property
5833 * value, else `false`.
5834 *
5835 * If an object is provided for `iteratee` the created `_.matches` style
5836 * callback returns `true` for elements that have the properties of the given
5837 * object, else `false`.
5838 *
5839 * @static
5840 * @memberOf _
5841 * @category Collection
5842 * @param {Array|Object|string} collection The collection to iterate over.
5843 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5844 * per iteration.
5845 * @param {*} [thisArg] The `this` binding of `iteratee`.
5846 * @returns {Object} Returns the composed aggregate object.
5847 * @example
5848 *
5849 * var keyData = [
5850 * { 'dir': 'left', 'code': 97 },
5851 * { 'dir': 'right', 'code': 100 }
5852 * ];
5853 *
5854 * _.indexBy(keyData, 'dir');
5855 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
5856 *
5857 * _.indexBy(keyData, function(object) {
5858 * return String.fromCharCode(object.code);
5859 * });
5860 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
5861 *
5862 * _.indexBy(keyData, function(object) {
5863 * return this.fromCharCode(object.code);
5864 * }, String);
5865 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
5866 */
5867 var indexBy = createAggregator(function (result, value, key) {
5868 result[key] = value;
5869 });
5870 /**
5871 * Invokes the method at `path` of each element in `collection`, returning
5872 * an array of the results of each invoked method. Any additional arguments
5873 * are provided to each invoked method. If `methodName` is a function it's
5874 * invoked for, and `this` bound to, each element in `collection`.
5875 *
5876 * @static
5877 * @memberOf _
5878 * @category Collection
5879 * @param {Array|Object|string} collection The collection to iterate over.
5880 * @param {Array|Function|string} path The path of the method to invoke or
5881 * the function invoked per iteration.
5882 * @param {...*} [args] The arguments to invoke the method with.
5883 * @returns {Array} Returns the array of results.
5884 * @example
5885 *
5886 * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
5887 * // => [[1, 5, 7], [1, 2, 3]]
5888 *
5889 * _.invoke([123, 456], String.prototype.split, '');
5890 * // => [['1', '2', '3'], ['4', '5', '6']]
5891 */
5892 var invoke = restParam(function (collection, path, args) {
5893 var index = -1, isFunc = typeof path == 'function', isProp = isKey(path), result = isArrayLike(collection) ? Array(collection.length) : [];
5894 baseEach(collection, function (value) {
5895 var func = isFunc ? path : isProp && value != null ? value[path] : undefined;
5896 result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
5897 });
5898 return result;
5899 });
5900 /**
5901 * Creates an array of values by running each element in `collection` through
5902 * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
5903 * arguments: (value, index|key, collection).
5904 *
5905 * If a property name is provided for `iteratee` the created `_.property`
5906 * style callback returns the property value of the given element.
5907 *
5908 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5909 * style callback returns `true` for elements that have a matching property
5910 * value, else `false`.
5911 *
5912 * If an object is provided for `iteratee` the created `_.matches` style
5913 * callback returns `true` for elements that have the properties of the given
5914 * object, else `false`.
5915 *
5916 * Many lodash methods are guarded to work as iteratees for methods like
5917 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
5918 *
5919 * The guarded methods are:
5920 * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
5921 * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
5922 * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
5923 * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
5924 * `sum`, `uniq`, and `words`
5925 *
5926 * @static
5927 * @memberOf _
5928 * @alias collect
5929 * @category Collection
5930 * @param {Array|Object|string} collection The collection to iterate over.
5931 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5932 * per iteration.
5933 * @param {*} [thisArg] The `this` binding of `iteratee`.
5934 * @returns {Array} Returns the new mapped array.
5935 * @example
5936 *
5937 * function timesThree(n) {
5938 * return n * 3;
5939 * }
5940 *
5941 * _.map([1, 2], timesThree);
5942 * // => [3, 6]
5943 *
5944 * _.map({ 'a': 1, 'b': 2 }, timesThree);
5945 * // => [3, 6] (iteration order is not guaranteed)
5946 *
5947 * var users = [
5948 * { 'user': 'barney' },
5949 * { 'user': 'fred' }
5950 * ];
5951 *
5952 * // using the `_.property` callback shorthand
5953 * _.map(users, 'user');
5954 * // => ['barney', 'fred']
5955 */
5956 function map(collection, iteratee, thisArg) {
5957 var func = isArray(collection) ? arrayMap : baseMap;
5958 iteratee = getCallback(iteratee, thisArg, 3);
5959 return func(collection, iteratee);
5960 }
5961 /**
5962 * Creates an array of elements split into two groups, the first of which
5963 * contains elements `predicate` returns truthy for, while the second of which
5964 * contains elements `predicate` returns falsey for. The predicate is bound
5965 * to `thisArg` and invoked with three arguments: (value, index|key, collection).
5966 *
5967 * If a property name is provided for `predicate` the created `_.property`
5968 * style callback returns the property value of the given element.
5969 *
5970 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5971 * style callback returns `true` for elements that have a matching property
5972 * value, else `false`.
5973 *
5974 * If an object is provided for `predicate` the created `_.matches` style
5975 * callback returns `true` for elements that have the properties of the given
5976 * object, else `false`.
5977 *
5978 * @static
5979 * @memberOf _
5980 * @category Collection
5981 * @param {Array|Object|string} collection The collection to iterate over.
5982 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5983 * per iteration.
5984 * @param {*} [thisArg] The `this` binding of `predicate`.
5985 * @returns {Array} Returns the array of grouped elements.
5986 * @example
5987 *
5988 * _.partition([1, 2, 3], function(n) {
5989 * return n % 2;
5990 * });
5991 * // => [[1, 3], [2]]
5992 *
5993 * _.partition([1.2, 2.3, 3.4], function(n) {
5994 * return this.floor(n) % 2;
5995 * }, Math);
5996 * // => [[1.2, 3.4], [2.3]]
5997 *
5998 * var users = [
5999 * { 'user': 'barney', 'age': 36, 'active': false },
6000 * { 'user': 'fred', 'age': 40, 'active': true },
6001 * { 'user': 'pebbles', 'age': 1, 'active': false }
6002 * ];
6003 *
6004 * var mapper = function(array) {
6005 * return _.pluck(array, 'user');
6006 * };
6007 *
6008 * // using the `_.matches` callback shorthand
6009 * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
6010 * // => [['pebbles'], ['barney', 'fred']]
6011 *
6012 * // using the `_.matchesProperty` callback shorthand
6013 * _.map(_.partition(users, 'active', false), mapper);
6014 * // => [['barney', 'pebbles'], ['fred']]
6015 *
6016 * // using the `_.property` callback shorthand
6017 * _.map(_.partition(users, 'active'), mapper);
6018 * // => [['fred'], ['barney', 'pebbles']]
6019 */
6020 var partition = createAggregator(function (result, value, key) {
6021 result[key ? 0 : 1].push(value);
6022 }, function () {
6023 return [
6024 [],
6025 []
6026 ];
6027 });
6028 /**
6029 * Gets the property value of `path` from all elements in `collection`.
6030 *
6031 * @static
6032 * @memberOf _
6033 * @category Collection
6034 * @param {Array|Object|string} collection The collection to iterate over.
6035 * @param {Array|string} path The path of the property to pluck.
6036 * @returns {Array} Returns the property values.
6037 * @example
6038 *
6039 * var users = [
6040 * { 'user': 'barney', 'age': 36 },
6041 * { 'user': 'fred', 'age': 40 }
6042 * ];
6043 *
6044 * _.pluck(users, 'user');
6045 * // => ['barney', 'fred']
6046 *
6047 * var userIndex = _.indexBy(users, 'user');
6048 * _.pluck(userIndex, 'age');
6049 * // => [36, 40] (iteration order is not guaranteed)
6050 */
6051 function pluck(collection, path) {
6052 return map(collection, property(path));
6053 }
6054 /**
6055 * Reduces `collection` to a value which is the accumulated result of running
6056 * each element in `collection` through `iteratee`, where each successive
6057 * invocation is supplied the return value of the previous. If `accumulator`
6058 * is not provided the first element of `collection` is used as the initial
6059 * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
6060 * (accumulator, value, index|key, collection).
6061 *
6062 * Many lodash methods are guarded to work as iteratees for methods like
6063 * `_.reduce`, `_.reduceRight`, and `_.transform`.
6064 *
6065 * The guarded methods are:
6066 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
6067 * and `sortByOrder`
6068 *
6069 * @static
6070 * @memberOf _
6071 * @alias foldl, inject
6072 * @category Collection
6073 * @param {Array|Object|string} collection The collection to iterate over.
6074 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6075 * @param {*} [accumulator] The initial value.
6076 * @param {*} [thisArg] The `this` binding of `iteratee`.
6077 * @returns {*} Returns the accumulated value.
6078 * @example
6079 *
6080 * _.reduce([1, 2], function(total, n) {
6081 * return total + n;
6082 * });
6083 * // => 3
6084 *
6085 * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
6086 * result[key] = n * 3;
6087 * return result;
6088 * }, {});
6089 * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
6090 */
6091 var reduce = createReduce(arrayReduce, baseEach);
6092 /**
6093 * This method is like `_.reduce` except that it iterates over elements of
6094 * `collection` from right to left.
6095 *
6096 * @static
6097 * @memberOf _
6098 * @alias foldr
6099 * @category Collection
6100 * @param {Array|Object|string} collection The collection to iterate over.
6101 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6102 * @param {*} [accumulator] The initial value.
6103 * @param {*} [thisArg] The `this` binding of `iteratee`.
6104 * @returns {*} Returns the accumulated value.
6105 * @example
6106 *
6107 * var array = [[0, 1], [2, 3], [4, 5]];
6108 *
6109 * _.reduceRight(array, function(flattened, other) {
6110 * return flattened.concat(other);
6111 * }, []);
6112 * // => [4, 5, 2, 3, 0, 1]
6113 */
6114 var reduceRight = createReduce(arrayReduceRight, baseEachRight);
6115 /**
6116 * The opposite of `_.filter`; this method returns the elements of `collection`
6117 * that `predicate` does **not** return truthy for.
6118 *
6119 * @static
6120 * @memberOf _
6121 * @category Collection
6122 * @param {Array|Object|string} collection The collection to iterate over.
6123 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6124 * per iteration.
6125 * @param {*} [thisArg] The `this` binding of `predicate`.
6126 * @returns {Array} Returns the new filtered array.
6127 * @example
6128 *
6129 * _.reject([1, 2, 3, 4], function(n) {
6130 * return n % 2 == 0;
6131 * });
6132 * // => [1, 3]
6133 *
6134 * var users = [
6135 * { 'user': 'barney', 'age': 36, 'active': false },
6136 * { 'user': 'fred', 'age': 40, 'active': true }
6137 * ];
6138 *
6139 * // using the `_.matches` callback shorthand
6140 * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
6141 * // => ['barney']
6142 *
6143 * // using the `_.matchesProperty` callback shorthand
6144 * _.pluck(_.reject(users, 'active', false), 'user');
6145 * // => ['fred']
6146 *
6147 * // using the `_.property` callback shorthand
6148 * _.pluck(_.reject(users, 'active'), 'user');
6149 * // => ['barney']
6150 */
6151 function reject(collection, predicate, thisArg) {
6152 var func = isArray(collection) ? arrayFilter : baseFilter;
6153 predicate = getCallback(predicate, thisArg, 3);
6154 return func(collection, function (value, index, collection) {
6155 return !predicate(value, index, collection);
6156 });
6157 }
6158 /**
6159 * Gets a random element or `n` random elements from a collection.
6160 *
6161 * @static
6162 * @memberOf _
6163 * @category Collection
6164 * @param {Array|Object|string} collection The collection to sample.
6165 * @param {number} [n] The number of elements to sample.
6166 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6167 * @returns {*} Returns the random sample(s).
6168 * @example
6169 *
6170 * _.sample([1, 2, 3, 4]);
6171 * // => 2
6172 *
6173 * _.sample([1, 2, 3, 4], 2);
6174 * // => [3, 1]
6175 */
6176 function sample(collection, n, guard) {
6177 if (guard ? isIterateeCall(collection, n, guard) : n == null) {
6178 collection = toIterable(collection);
6179 var length = collection.length;
6180 return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
6181 }
6182 var index = -1, result = toArray(collection), length = result.length, lastIndex = length - 1;
6183 n = nativeMin(n < 0 ? 0 : +n || 0, length);
6184 while (++index < n) {
6185 var rand = baseRandom(index, lastIndex), value = result[rand];
6186 result[rand] = result[index];
6187 result[index] = value;
6188 }
6189 result.length = n;
6190 return result;
6191 }
6192 /**
6193 * Creates an array of shuffled values, using a version of the
6194 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
6195 *
6196 * @static
6197 * @memberOf _
6198 * @category Collection
6199 * @param {Array|Object|string} collection The collection to shuffle.
6200 * @returns {Array} Returns the new shuffled array.
6201 * @example
6202 *
6203 * _.shuffle([1, 2, 3, 4]);
6204 * // => [4, 1, 3, 2]
6205 */
6206 function shuffle(collection) {
6207 return sample(collection, POSITIVE_INFINITY);
6208 }
6209 /**
6210 * Gets the size of `collection` by returning its length for array-like
6211 * values or the number of own enumerable properties for objects.
6212 *
6213 * @static
6214 * @memberOf _
6215 * @category Collection
6216 * @param {Array|Object|string} collection The collection to inspect.
6217 * @returns {number} Returns the size of `collection`.
6218 * @example
6219 *
6220 * _.size([1, 2, 3]);
6221 * // => 3
6222 *
6223 * _.size({ 'a': 1, 'b': 2 });
6224 * // => 2
6225 *
6226 * _.size('pebbles');
6227 * // => 7
6228 */
6229 function size(collection) {
6230 var length = collection ? getLength(collection) : 0;
6231 return isLength(length) ? length : keys(collection).length;
6232 }
6233 /**
6234 * Checks if `predicate` returns truthy for **any** element of `collection`.
6235 * The function returns as soon as it finds a passing value and does not iterate
6236 * over the entire collection. The predicate is bound to `thisArg` and invoked
6237 * with three arguments: (value, index|key, collection).
6238 *
6239 * If a property name is provided for `predicate` the created `_.property`
6240 * style callback returns the property value of the given element.
6241 *
6242 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6243 * style callback returns `true` for elements that have a matching property
6244 * value, else `false`.
6245 *
6246 * If an object is provided for `predicate` the created `_.matches` style
6247 * callback returns `true` for elements that have the properties of the given
6248 * object, else `false`.
6249 *
6250 * @static
6251 * @memberOf _
6252 * @alias any
6253 * @category Collection
6254 * @param {Array|Object|string} collection The collection to iterate over.
6255 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6256 * per iteration.
6257 * @param {*} [thisArg] The `this` binding of `predicate`.
6258 * @returns {boolean} Returns `true` if any element passes the predicate check,
6259 * else `false`.
6260 * @example
6261 *
6262 * _.some([null, 0, 'yes', false], Boolean);
6263 * // => true
6264 *
6265 * var users = [
6266 * { 'user': 'barney', 'active': true },
6267 * { 'user': 'fred', 'active': false }
6268 * ];
6269 *
6270 * // using the `_.matches` callback shorthand
6271 * _.some(users, { 'user': 'barney', 'active': false });
6272 * // => false
6273 *
6274 * // using the `_.matchesProperty` callback shorthand
6275 * _.some(users, 'active', false);
6276 * // => true
6277 *
6278 * // using the `_.property` callback shorthand
6279 * _.some(users, 'active');
6280 * // => true
6281 */
6282 function some(collection, predicate, thisArg) {
6283 var func = isArray(collection) ? arraySome : baseSome;
6284 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
6285 predicate = undefined;
6286 }
6287 if (typeof predicate != 'function' || thisArg !== undefined) {
6288 predicate = getCallback(predicate, thisArg, 3);
6289 }
6290 return func(collection, predicate);
6291 }
6292 /**
6293 * Creates an array of elements, sorted in ascending order by the results of
6294 * running each element in a collection through `iteratee`. This method performs
6295 * a stable sort, that is, it preserves the original sort order of equal elements.
6296 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6297 * (value, index|key, collection).
6298 *
6299 * If a property name is provided for `iteratee` the created `_.property`
6300 * style callback returns the property value of the given element.
6301 *
6302 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6303 * style callback returns `true` for elements that have a matching property
6304 * value, else `false`.
6305 *
6306 * If an object is provided for `iteratee` the created `_.matches` style
6307 * callback returns `true` for elements that have the properties of the given
6308 * object, else `false`.
6309 *
6310 * @static
6311 * @memberOf _
6312 * @category Collection
6313 * @param {Array|Object|string} collection The collection to iterate over.
6314 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6315 * per iteration.
6316 * @param {*} [thisArg] The `this` binding of `iteratee`.
6317 * @returns {Array} Returns the new sorted array.
6318 * @example
6319 *
6320 * _.sortBy([1, 2, 3], function(n) {
6321 * return Math.sin(n);
6322 * });
6323 * // => [3, 1, 2]
6324 *
6325 * _.sortBy([1, 2, 3], function(n) {
6326 * return this.sin(n);
6327 * }, Math);
6328 * // => [3, 1, 2]
6329 *
6330 * var users = [
6331 * { 'user': 'fred' },
6332 * { 'user': 'pebbles' },
6333 * { 'user': 'barney' }
6334 * ];
6335 *
6336 * // using the `_.property` callback shorthand
6337 * _.pluck(_.sortBy(users, 'user'), 'user');
6338 * // => ['barney', 'fred', 'pebbles']
6339 */
6340 function sortBy(collection, iteratee, thisArg) {
6341 if (collection == null) {
6342 return [];
6343 }
6344 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
6345 iteratee = undefined;
6346 }
6347 var index = -1;
6348 iteratee = getCallback(iteratee, thisArg, 3);
6349 var result = baseMap(collection, function (value, key, collection) {
6350 return {
6351 'criteria': iteratee(value, key, collection),
6352 'index': ++index,
6353 'value': value
6354 };
6355 });
6356 return baseSortBy(result, compareAscending);
6357 }
6358 /**
6359 * This method is like `_.sortBy` except that it can sort by multiple iteratees
6360 * or property names.
6361 *
6362 * If a property name is provided for an iteratee the created `_.property`
6363 * style callback returns the property value of the given element.
6364 *
6365 * If an object is provided for an iteratee the created `_.matches` style
6366 * callback returns `true` for elements that have the properties of the given
6367 * object, else `false`.
6368 *
6369 * @static
6370 * @memberOf _
6371 * @category Collection
6372 * @param {Array|Object|string} collection The collection to iterate over.
6373 * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
6374 * The iteratees to sort by, specified as individual values or arrays of values.
6375 * @returns {Array} Returns the new sorted array.
6376 * @example
6377 *
6378 * var users = [
6379 * { 'user': 'fred', 'age': 48 },
6380 * { 'user': 'barney', 'age': 36 },
6381 * { 'user': 'fred', 'age': 42 },
6382 * { 'user': 'barney', 'age': 34 }
6383 * ];
6384 *
6385 * _.map(_.sortByAll(users, ['user', 'age']), _.values);
6386 * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
6387 *
6388 * _.map(_.sortByAll(users, 'user', function(chr) {
6389 * return Math.floor(chr.age / 10);
6390 * }), _.values);
6391 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
6392 */
6393 var sortByAll = restParam(function (collection, iteratees) {
6394 if (collection == null) {
6395 return [];
6396 }
6397 var guard = iteratees[2];
6398 if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
6399 iteratees.length = 1;
6400 }
6401 return baseSortByOrder(collection, baseFlatten(iteratees), []);
6402 });
6403 /**
6404 * This method is like `_.sortByAll` except that it allows specifying the
6405 * sort orders of the iteratees to sort by. If `orders` is unspecified, all
6406 * values are sorted in ascending order. Otherwise, a value is sorted in
6407 * ascending order if its corresponding order is "asc", and descending if "desc".
6408 *
6409 * If a property name is provided for an iteratee the created `_.property`
6410 * style callback returns the property value of the given element.
6411 *
6412 * If an object is provided for an iteratee the created `_.matches` style
6413 * callback returns `true` for elements that have the properties of the given
6414 * object, else `false`.
6415 *
6416 * @static
6417 * @memberOf _
6418 * @category Collection
6419 * @param {Array|Object|string} collection The collection to iterate over.
6420 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
6421 * @param {boolean[]} [orders] The sort orders of `iteratees`.
6422 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
6423 * @returns {Array} Returns the new sorted array.
6424 * @example
6425 *
6426 * var users = [
6427 * { 'user': 'fred', 'age': 48 },
6428 * { 'user': 'barney', 'age': 34 },
6429 * { 'user': 'fred', 'age': 42 },
6430 * { 'user': 'barney', 'age': 36 }
6431 * ];
6432 *
6433 * // sort by `user` in ascending order and by `age` in descending order
6434 * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
6435 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
6436 */
6437 function sortByOrder(collection, iteratees, orders, guard) {
6438 if (collection == null) {
6439 return [];
6440 }
6441 if (guard && isIterateeCall(iteratees, orders, guard)) {
6442 orders = undefined;
6443 }
6444 if (!isArray(iteratees)) {
6445 iteratees = iteratees == null ? [] : [iteratees];
6446 }
6447 if (!isArray(orders)) {
6448 orders = orders == null ? [] : [orders];
6449 }
6450 return baseSortByOrder(collection, iteratees, orders);
6451 }
6452 /**
6453 * Performs a deep comparison between each element in `collection` and the
6454 * source object, returning an array of all elements that have equivalent
6455 * property values.
6456 *
6457 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
6458 * numbers, `Object` objects, regexes, and strings. Objects are compared by
6459 * their own, not inherited, enumerable properties. For comparing a single
6460 * own or inherited property value see `_.matchesProperty`.
6461 *
6462 * @static
6463 * @memberOf _
6464 * @category Collection
6465 * @param {Array|Object|string} collection The collection to search.
6466 * @param {Object} source The object of property values to match.
6467 * @returns {Array} Returns the new filtered array.
6468 * @example
6469 *
6470 * var users = [
6471 * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
6472 * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
6473 * ];
6474 *
6475 * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
6476 * // => ['barney']
6477 *
6478 * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
6479 * // => ['fred']
6480 */
6481 function where(collection, source) {
6482 return filter(collection, baseMatches(source));
6483 }
6484 /*------------------------------------------------------------------------*/
6485 /**
6486 * Gets the number of milliseconds that have elapsed since the Unix epoch
6487 * (1 January 1970 00:00:00 UTC).
6488 *
6489 * @static
6490 * @memberOf _
6491 * @category Date
6492 * @example
6493 *
6494 * _.defer(function(stamp) {
6495 * console.log(_.now() - stamp);
6496 * }, _.now());
6497 * // => logs the number of milliseconds it took for the deferred function to be invoked
6498 */
6499 var now = nativeNow || function () {
6500 return new Date().getTime();
6501 };
6502 /*------------------------------------------------------------------------*/
6503 /**
6504 * The opposite of `_.before`; this method creates a function that invokes
6505 * `func` once it's called `n` or more times.
6506 *
6507 * @static
6508 * @memberOf _
6509 * @category Function
6510 * @param {number} n The number of calls before `func` is invoked.
6511 * @param {Function} func The function to restrict.
6512 * @returns {Function} Returns the new restricted function.
6513 * @example
6514 *
6515 * var saves = ['profile', 'settings'];
6516 *
6517 * var done = _.after(saves.length, function() {
6518 * console.log('done saving!');
6519 * });
6520 *
6521 * _.forEach(saves, function(type) {
6522 * asyncSave({ 'type': type, 'complete': done });
6523 * });
6524 * // => logs 'done saving!' after the two async saves have completed
6525 */
6526 function after(n, func) {
6527 if (typeof func != 'function') {
6528 if (typeof n == 'function') {
6529 var temp = n;
6530 n = func;
6531 func = temp;
6532 } else {
6533 throw new TypeError(FUNC_ERROR_TEXT);
6534 }
6535 }
6536 n = nativeIsFinite(n = +n) ? n : 0;
6537 return function () {
6538 if (--n < 1) {
6539 return func.apply(this, arguments);
6540 }
6541 };
6542 }
6543 /**
6544 * Creates a function that accepts up to `n` arguments ignoring any
6545 * additional arguments.
6546 *
6547 * @static
6548 * @memberOf _
6549 * @category Function
6550 * @param {Function} func The function to cap arguments for.
6551 * @param {number} [n=func.length] The arity cap.
6552 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6553 * @returns {Function} Returns the new function.
6554 * @example
6555 *
6556 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
6557 * // => [6, 8, 10]
6558 */
6559 function ary(func, n, guard) {
6560 if (guard && isIterateeCall(func, n, guard)) {
6561 n = undefined;
6562 }
6563 n = func && n == null ? func.length : nativeMax(+n || 0, 0);
6564 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
6565 }
6566 /**
6567 * Creates a function that invokes `func`, with the `this` binding and arguments
6568 * of the created function, while it's called less than `n` times. Subsequent
6569 * calls to the created function return the result of the last `func` invocation.
6570 *
6571 * @static
6572 * @memberOf _
6573 * @category Function
6574 * @param {number} n The number of calls at which `func` is no longer invoked.
6575 * @param {Function} func The function to restrict.
6576 * @returns {Function} Returns the new restricted function.
6577 * @example
6578 *
6579 * jQuery('#add').on('click', _.before(5, addContactToList));
6580 * // => allows adding up to 4 contacts to the list
6581 */
6582 function before(n, func) {
6583 var result;
6584 if (typeof func != 'function') {
6585 if (typeof n == 'function') {
6586 var temp = n;
6587 n = func;
6588 func = temp;
6589 } else {
6590 throw new TypeError(FUNC_ERROR_TEXT);
6591 }
6592 }
6593 return function () {
6594 if (--n > 0) {
6595 result = func.apply(this, arguments);
6596 }
6597 if (n <= 1) {
6598 func = undefined;
6599 }
6600 return result;
6601 };
6602 }
6603 /**
6604 * Creates a function that invokes `func` with the `this` binding of `thisArg`
6605 * and prepends any additional `_.bind` arguments to those provided to the
6606 * bound function.
6607 *
6608 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
6609 * may be used as a placeholder for partially applied arguments.
6610 *
6611 * **Note:** Unlike native `Function#bind` this method does not set the "length"
6612 * property of bound functions.
6613 *
6614 * @static
6615 * @memberOf _
6616 * @category Function
6617 * @param {Function} func The function to bind.
6618 * @param {*} thisArg The `this` binding of `func`.
6619 * @param {...*} [partials] The arguments to be partially applied.
6620 * @returns {Function} Returns the new bound function.
6621 * @example
6622 *
6623 * var greet = function(greeting, punctuation) {
6624 * return greeting + ' ' + this.user + punctuation;
6625 * };
6626 *
6627 * var object = { 'user': 'fred' };
6628 *
6629 * var bound = _.bind(greet, object, 'hi');
6630 * bound('!');
6631 * // => 'hi fred!'
6632 *
6633 * // using placeholders
6634 * var bound = _.bind(greet, object, _, '!');
6635 * bound('hi');
6636 * // => 'hi fred!'
6637 */
6638 var bind = restParam(function (func, thisArg, partials) {
6639 var bitmask = BIND_FLAG;
6640 if (partials.length) {
6641 var holders = replaceHolders(partials, bind.placeholder);
6642 bitmask |= PARTIAL_FLAG;
6643 }
6644 return createWrapper(func, bitmask, thisArg, partials, holders);
6645 });
6646 /**
6647 * Binds methods of an object to the object itself, overwriting the existing
6648 * method. Method names may be specified as individual arguments or as arrays
6649 * of method names. If no method names are provided all enumerable function
6650 * properties, own and inherited, of `object` are bound.
6651 *
6652 * **Note:** This method does not set the "length" property of bound functions.
6653 *
6654 * @static
6655 * @memberOf _
6656 * @category Function
6657 * @param {Object} object The object to bind and assign the bound methods to.
6658 * @param {...(string|string[])} [methodNames] The object method names to bind,
6659 * specified as individual method names or arrays of method names.
6660 * @returns {Object} Returns `object`.
6661 * @example
6662 *
6663 * var view = {
6664 * 'label': 'docs',
6665 * 'onClick': function() {
6666 * console.log('clicked ' + this.label);
6667 * }
6668 * };
6669 *
6670 * _.bindAll(view);
6671 * jQuery('#docs').on('click', view.onClick);
6672 * // => logs 'clicked docs' when the element is clicked
6673 */
6674 var bindAll = restParam(function (object, methodNames) {
6675 methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
6676 var index = -1, length = methodNames.length;
6677 while (++index < length) {
6678 var key = methodNames[index];
6679 object[key] = createWrapper(object[key], BIND_FLAG, object);
6680 }
6681 return object;
6682 });
6683 /**
6684 * Creates a function that invokes the method at `object[key]` and prepends
6685 * any additional `_.bindKey` arguments to those provided to the bound function.
6686 *
6687 * This method differs from `_.bind` by allowing bound functions to reference
6688 * methods that may be redefined or don't yet exist.
6689 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
6690 * for more details.
6691 *
6692 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
6693 * builds, may be used as a placeholder for partially applied arguments.
6694 *
6695 * @static
6696 * @memberOf _
6697 * @category Function
6698 * @param {Object} object The object the method belongs to.
6699 * @param {string} key The key of the method.
6700 * @param {...*} [partials] The arguments to be partially applied.
6701 * @returns {Function} Returns the new bound function.
6702 * @example
6703 *
6704 * var object = {
6705 * 'user': 'fred',
6706 * 'greet': function(greeting, punctuation) {
6707 * return greeting + ' ' + this.user + punctuation;
6708 * }
6709 * };
6710 *
6711 * var bound = _.bindKey(object, 'greet', 'hi');
6712 * bound('!');
6713 * // => 'hi fred!'
6714 *
6715 * object.greet = function(greeting, punctuation) {
6716 * return greeting + 'ya ' + this.user + punctuation;
6717 * };
6718 *
6719 * bound('!');
6720 * // => 'hiya fred!'
6721 *
6722 * // using placeholders
6723 * var bound = _.bindKey(object, 'greet', _, '!');
6724 * bound('hi');
6725 * // => 'hiya fred!'
6726 */
6727 var bindKey = restParam(function (object, key, partials) {
6728 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
6729 if (partials.length) {
6730 var holders = replaceHolders(partials, bindKey.placeholder);
6731 bitmask |= PARTIAL_FLAG;
6732 }
6733 return createWrapper(key, bitmask, object, partials, holders);
6734 });
6735 /**
6736 * Creates a function that accepts one or more arguments of `func` that when
6737 * called either invokes `func` returning its result, if all `func` arguments
6738 * have been provided, or returns a function that accepts one or more of the
6739 * remaining `func` arguments, and so on. The arity of `func` may be specified
6740 * if `func.length` is not sufficient.
6741 *
6742 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
6743 * may be used as a placeholder for provided arguments.
6744 *
6745 * **Note:** This method does not set the "length" property of curried functions.
6746 *
6747 * @static
6748 * @memberOf _
6749 * @category Function
6750 * @param {Function} func The function to curry.
6751 * @param {number} [arity=func.length] The arity of `func`.
6752 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6753 * @returns {Function} Returns the new curried function.
6754 * @example
6755 *
6756 * var abc = function(a, b, c) {
6757 * return [a, b, c];
6758 * };
6759 *
6760 * var curried = _.curry(abc);
6761 *
6762 * curried(1)(2)(3);
6763 * // => [1, 2, 3]
6764 *
6765 * curried(1, 2)(3);
6766 * // => [1, 2, 3]
6767 *
6768 * curried(1, 2, 3);
6769 * // => [1, 2, 3]
6770 *
6771 * // using placeholders
6772 * curried(1)(_, 3)(2);
6773 * // => [1, 2, 3]
6774 */
6775 var curry = createCurry(CURRY_FLAG);
6776 /**
6777 * This method is like `_.curry` except that arguments are applied to `func`
6778 * in the manner of `_.partialRight` instead of `_.partial`.
6779 *
6780 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
6781 * builds, may be used as a placeholder for provided arguments.
6782 *
6783 * **Note:** This method does not set the "length" property of curried functions.
6784 *
6785 * @static
6786 * @memberOf _
6787 * @category Function
6788 * @param {Function} func The function to curry.
6789 * @param {number} [arity=func.length] The arity of `func`.
6790 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6791 * @returns {Function} Returns the new curried function.
6792 * @example
6793 *
6794 * var abc = function(a, b, c) {
6795 * return [a, b, c];
6796 * };
6797 *
6798 * var curried = _.curryRight(abc);
6799 *
6800 * curried(3)(2)(1);
6801 * // => [1, 2, 3]
6802 *
6803 * curried(2, 3)(1);
6804 * // => [1, 2, 3]
6805 *
6806 * curried(1, 2, 3);
6807 * // => [1, 2, 3]
6808 *
6809 * // using placeholders
6810 * curried(3)(1, _)(2);
6811 * // => [1, 2, 3]
6812 */
6813 var curryRight = createCurry(CURRY_RIGHT_FLAG);
6814 /**
6815 * Creates a debounced function that delays invoking `func` until after `wait`
6816 * milliseconds have elapsed since the last time the debounced function was
6817 * invoked. The debounced function comes with a `cancel` method to cancel
6818 * delayed invocations. Provide an options object to indicate that `func`
6819 * should be invoked on the leading and/or trailing edge of the `wait` timeout.
6820 * Subsequent calls to the debounced function return the result of the last
6821 * `func` invocation.
6822 *
6823 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
6824 * on the trailing edge of the timeout only if the the debounced function is
6825 * invoked more than once during the `wait` timeout.
6826 *
6827 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
6828 * for details over the differences between `_.debounce` and `_.throttle`.
6829 *
6830 * @static
6831 * @memberOf _
6832 * @category Function
6833 * @param {Function} func The function to debounce.
6834 * @param {number} [wait=0] The number of milliseconds to delay.
6835 * @param {Object} [options] The options object.
6836 * @param {boolean} [options.leading=false] Specify invoking on the leading
6837 * edge of the timeout.
6838 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
6839 * delayed before it's invoked.
6840 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
6841 * edge of the timeout.
6842 * @returns {Function} Returns the new debounced function.
6843 * @example
6844 *
6845 * // avoid costly calculations while the window size is in flux
6846 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
6847 *
6848 * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
6849 * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
6850 * 'leading': true,
6851 * 'trailing': false
6852 * }));
6853 *
6854 * // ensure `batchLog` is invoked once after 1 second of debounced calls
6855 * var source = new EventSource('/stream');
6856 * jQuery(source).on('message', _.debounce(batchLog, 250, {
6857 * 'maxWait': 1000
6858 * }));
6859 *
6860 * // cancel a debounced call
6861 * var todoChanges = _.debounce(batchLog, 1000);
6862 * Object.observe(models.todo, todoChanges);
6863 *
6864 * Object.observe(models, function(changes) {
6865 * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
6866 * todoChanges.cancel();
6867 * }
6868 * }, ['delete']);
6869 *
6870 * // ...at some point `models.todo` is changed
6871 * models.todo.completed = true;
6872 *
6873 * // ...before 1 second has passed `models.todo` is deleted
6874 * // which cancels the debounced `todoChanges` call
6875 * delete models.todo;
6876 */
6877 function debounce(func, wait, options) {
6878 var args, maxTimeoutId, result, stamp, thisArg, timeoutId, trailingCall, lastCalled = 0, maxWait = false, trailing = true;
6879 if (typeof func != 'function') {
6880 throw new TypeError(FUNC_ERROR_TEXT);
6881 }
6882 wait = wait < 0 ? 0 : +wait || 0;
6883 if (options === true) {
6884 var leading = true;
6885 trailing = false;
6886 } else if (isObject(options)) {
6887 leading = !!options.leading;
6888 maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
6889 trailing = 'trailing' in options ? !!options.trailing : trailing;
6890 }
6891 function cancel() {
6892 if (timeoutId) {
6893 clearTimeout(timeoutId);
6894 }
6895 if (maxTimeoutId) {
6896 clearTimeout(maxTimeoutId);
6897 }
6898 lastCalled = 0;
6899 maxTimeoutId = timeoutId = trailingCall = undefined;
6900 }
6901 function complete(isCalled, id) {
6902 if (id) {
6903 clearTimeout(id);
6904 }
6905 maxTimeoutId = timeoutId = trailingCall = undefined;
6906 if (isCalled) {
6907 lastCalled = now();
6908 result = func.apply(thisArg, args);
6909 if (!timeoutId && !maxTimeoutId) {
6910 args = thisArg = undefined;
6911 }
6912 }
6913 }
6914 function delayed() {
6915 var remaining = wait - (now() - stamp);
6916 if (remaining <= 0 || remaining > wait) {
6917 complete(trailingCall, maxTimeoutId);
6918 } else {
6919 timeoutId = setTimeout(delayed, remaining);
6920 }
6921 }
6922 function maxDelayed() {
6923 complete(trailing, timeoutId);
6924 }
6925 function debounced() {
6926 args = arguments;
6927 stamp = now();
6928 thisArg = this;
6929 trailingCall = trailing && (timeoutId || !leading);
6930 if (maxWait === false) {
6931 var leadingCall = leading && !timeoutId;
6932 } else {
6933 if (!maxTimeoutId && !leading) {
6934 lastCalled = stamp;
6935 }
6936 var remaining = maxWait - (stamp - lastCalled), isCalled = remaining <= 0 || remaining > maxWait;
6937 if (isCalled) {
6938 if (maxTimeoutId) {
6939 maxTimeoutId = clearTimeout(maxTimeoutId);
6940 }
6941 lastCalled = stamp;
6942 result = func.apply(thisArg, args);
6943 } else if (!maxTimeoutId) {
6944 maxTimeoutId = setTimeout(maxDelayed, remaining);
6945 }
6946 }
6947 if (isCalled && timeoutId) {
6948 timeoutId = clearTimeout(timeoutId);
6949 } else if (!timeoutId && wait !== maxWait) {
6950 timeoutId = setTimeout(delayed, wait);
6951 }
6952 if (leadingCall) {
6953 isCalled = true;
6954 result = func.apply(thisArg, args);
6955 }
6956 if (isCalled && !timeoutId && !maxTimeoutId) {
6957 args = thisArg = undefined;
6958 }
6959 return result;
6960 }
6961 debounced.cancel = cancel;
6962 return debounced;
6963 }
6964 /**
6965 * Defers invoking the `func` until the current call stack has cleared. Any
6966 * additional arguments are provided to `func` when it's invoked.
6967 *
6968 * @static
6969 * @memberOf _
6970 * @category Function
6971 * @param {Function} func The function to defer.
6972 * @param {...*} [args] The arguments to invoke the function with.
6973 * @returns {number} Returns the timer id.
6974 * @example
6975 *
6976 * _.defer(function(text) {
6977 * console.log(text);
6978 * }, 'deferred');
6979 * // logs 'deferred' after one or more milliseconds
6980 */
6981 var defer = restParam(function (func, args) {
6982 return baseDelay(func, 1, args);
6983 });
6984 /**
6985 * Invokes `func` after `wait` milliseconds. Any additional arguments are
6986 * provided to `func` when it's invoked.
6987 *
6988 * @static
6989 * @memberOf _
6990 * @category Function
6991 * @param {Function} func The function to delay.
6992 * @param {number} wait The number of milliseconds to delay invocation.
6993 * @param {...*} [args] The arguments to invoke the function with.
6994 * @returns {number} Returns the timer id.
6995 * @example
6996 *
6997 * _.delay(function(text) {
6998 * console.log(text);
6999 * }, 1000, 'later');
7000 * // => logs 'later' after one second
7001 */
7002 var delay = restParam(function (func, wait, args) {
7003 return baseDelay(func, wait, args);
7004 });
7005 /**
7006 * Creates a function that returns the result of invoking the provided
7007 * functions with the `this` binding of the created function, where each
7008 * successive invocation is supplied the return value of the previous.
7009 *
7010 * @static
7011 * @memberOf _
7012 * @category Function
7013 * @param {...Function} [funcs] Functions to invoke.
7014 * @returns {Function} Returns the new function.
7015 * @example
7016 *
7017 * function square(n) {
7018 * return n * n;
7019 * }
7020 *
7021 * var addSquare = _.flow(_.add, square);
7022 * addSquare(1, 2);
7023 * // => 9
7024 */
7025 var flow = createFlow();
7026 /**
7027 * This method is like `_.flow` except that it creates a function that
7028 * invokes the provided functions from right to left.
7029 *
7030 * @static
7031 * @memberOf _
7032 * @alias backflow, compose
7033 * @category Function
7034 * @param {...Function} [funcs] Functions to invoke.
7035 * @returns {Function} Returns the new function.
7036 * @example
7037 *
7038 * function square(n) {
7039 * return n * n;
7040 * }
7041 *
7042 * var addSquare = _.flowRight(square, _.add);
7043 * addSquare(1, 2);
7044 * // => 9
7045 */
7046 var flowRight = createFlow(true);
7047 /**
7048 * Creates a function that memoizes the result of `func`. If `resolver` is
7049 * provided it determines the cache key for storing the result based on the
7050 * arguments provided to the memoized function. By default, the first argument
7051 * provided to the memoized function is coerced to a string and used as the
7052 * cache key. The `func` is invoked with the `this` binding of the memoized
7053 * function.
7054 *
7055 * **Note:** The cache is exposed as the `cache` property on the memoized
7056 * function. Its creation may be customized by replacing the `_.memoize.Cache`
7057 * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
7058 * method interface of `get`, `has`, and `set`.
7059 *
7060 * @static
7061 * @memberOf _
7062 * @category Function
7063 * @param {Function} func The function to have its output memoized.
7064 * @param {Function} [resolver] The function to resolve the cache key.
7065 * @returns {Function} Returns the new memoizing function.
7066 * @example
7067 *
7068 * var upperCase = _.memoize(function(string) {
7069 * return string.toUpperCase();
7070 * });
7071 *
7072 * upperCase('fred');
7073 * // => 'FRED'
7074 *
7075 * // modifying the result cache
7076 * upperCase.cache.set('fred', 'BARNEY');
7077 * upperCase('fred');
7078 * // => 'BARNEY'
7079 *
7080 * // replacing `_.memoize.Cache`
7081 * var object = { 'user': 'fred' };
7082 * var other = { 'user': 'barney' };
7083 * var identity = _.memoize(_.identity);
7084 *
7085 * identity(object);
7086 * // => { 'user': 'fred' }
7087 * identity(other);
7088 * // => { 'user': 'fred' }
7089 *
7090 * _.memoize.Cache = WeakMap;
7091 * var identity = _.memoize(_.identity);
7092 *
7093 * identity(object);
7094 * // => { 'user': 'fred' }
7095 * identity(other);
7096 * // => { 'user': 'barney' }
7097 */
7098 function memoize(func, resolver) {
7099 if (typeof func != 'function' || resolver && typeof resolver != 'function') {
7100 throw new TypeError(FUNC_ERROR_TEXT);
7101 }
7102 var memoized = function () {
7103 var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
7104 if (cache.has(key)) {
7105 return cache.get(key);
7106 }
7107 var result = func.apply(this, args);
7108 memoized.cache = cache.set(key, result);
7109 return result;
7110 };
7111 memoized.cache = new memoize.Cache();
7112 return memoized;
7113 }
7114 /**
7115 * Creates a function that runs each argument through a corresponding
7116 * transform function.
7117 *
7118 * @static
7119 * @memberOf _
7120 * @category Function
7121 * @param {Function} func The function to wrap.
7122 * @param {...(Function|Function[])} [transforms] The functions to transform
7123 * arguments, specified as individual functions or arrays of functions.
7124 * @returns {Function} Returns the new function.
7125 * @example
7126 *
7127 * function doubled(n) {
7128 * return n * 2;
7129 * }
7130 *
7131 * function square(n) {
7132 * return n * n;
7133 * }
7134 *
7135 * var modded = _.modArgs(function(x, y) {
7136 * return [x, y];
7137 * }, square, doubled);
7138 *
7139 * modded(1, 2);
7140 * // => [1, 4]
7141 *
7142 * modded(5, 10);
7143 * // => [25, 20]
7144 */
7145 var modArgs = restParam(function (func, transforms) {
7146 transforms = baseFlatten(transforms);
7147 if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
7148 throw new TypeError(FUNC_ERROR_TEXT);
7149 }
7150 var length = transforms.length;
7151 return restParam(function (args) {
7152 var index = nativeMin(args.length, length);
7153 while (index--) {
7154 args[index] = transforms[index](args[index]);
7155 }
7156 return func.apply(this, args);
7157 });
7158 });
7159 /**
7160 * Creates a function that negates the result of the predicate `func`. The
7161 * `func` predicate is invoked with the `this` binding and arguments of the
7162 * created function.
7163 *
7164 * @static
7165 * @memberOf _
7166 * @category Function
7167 * @param {Function} predicate The predicate to negate.
7168 * @returns {Function} Returns the new function.
7169 * @example
7170 *
7171 * function isEven(n) {
7172 * return n % 2 == 0;
7173 * }
7174 *
7175 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
7176 * // => [1, 3, 5]
7177 */
7178 function negate(predicate) {
7179 if (typeof predicate != 'function') {
7180 throw new TypeError(FUNC_ERROR_TEXT);
7181 }
7182 return function () {
7183 return !predicate.apply(this, arguments);
7184 };
7185 }
7186 /**
7187 * Creates a function that is restricted to invoking `func` once. Repeat calls
7188 * to the function return the value of the first call. The `func` is invoked
7189 * with the `this` binding and arguments of the created function.
7190 *
7191 * @static
7192 * @memberOf _
7193 * @category Function
7194 * @param {Function} func The function to restrict.
7195 * @returns {Function} Returns the new restricted function.
7196 * @example
7197 *
7198 * var initialize = _.once(createApplication);
7199 * initialize();
7200 * initialize();
7201 * // `initialize` invokes `createApplication` once
7202 */
7203 function once(func) {
7204 return before(2, func);
7205 }
7206 /**
7207 * Creates a function that invokes `func` with `partial` arguments prepended
7208 * to those provided to the new function. This method is like `_.bind` except
7209 * it does **not** alter the `this` binding.
7210 *
7211 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
7212 * builds, may be used as a placeholder for partially applied arguments.
7213 *
7214 * **Note:** This method does not set the "length" property of partially
7215 * applied functions.
7216 *
7217 * @static
7218 * @memberOf _
7219 * @category Function
7220 * @param {Function} func The function to partially apply arguments to.
7221 * @param {...*} [partials] The arguments to be partially applied.
7222 * @returns {Function} Returns the new partially applied function.
7223 * @example
7224 *
7225 * var greet = function(greeting, name) {
7226 * return greeting + ' ' + name;
7227 * };
7228 *
7229 * var sayHelloTo = _.partial(greet, 'hello');
7230 * sayHelloTo('fred');
7231 * // => 'hello fred'
7232 *
7233 * // using placeholders
7234 * var greetFred = _.partial(greet, _, 'fred');
7235 * greetFred('hi');
7236 * // => 'hi fred'
7237 */
7238 var partial = createPartial(PARTIAL_FLAG);
7239 /**
7240 * This method is like `_.partial` except that partially applied arguments
7241 * are appended to those provided to the new function.
7242 *
7243 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
7244 * builds, may be used as a placeholder for partially applied arguments.
7245 *
7246 * **Note:** This method does not set the "length" property of partially
7247 * applied functions.
7248 *
7249 * @static
7250 * @memberOf _
7251 * @category Function
7252 * @param {Function} func The function to partially apply arguments to.
7253 * @param {...*} [partials] The arguments to be partially applied.
7254 * @returns {Function} Returns the new partially applied function.
7255 * @example
7256 *
7257 * var greet = function(greeting, name) {
7258 * return greeting + ' ' + name;
7259 * };
7260 *
7261 * var greetFred = _.partialRight(greet, 'fred');
7262 * greetFred('hi');
7263 * // => 'hi fred'
7264 *
7265 * // using placeholders
7266 * var sayHelloTo = _.partialRight(greet, 'hello', _);
7267 * sayHelloTo('fred');
7268 * // => 'hello fred'
7269 */
7270 var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
7271 /**
7272 * Creates a function that invokes `func` with arguments arranged according
7273 * to the specified indexes where the argument value at the first index is
7274 * provided as the first argument, the argument value at the second index is
7275 * provided as the second argument, and so on.
7276 *
7277 * @static
7278 * @memberOf _
7279 * @category Function
7280 * @param {Function} func The function to rearrange arguments for.
7281 * @param {...(number|number[])} indexes The arranged argument indexes,
7282 * specified as individual indexes or arrays of indexes.
7283 * @returns {Function} Returns the new function.
7284 * @example
7285 *
7286 * var rearged = _.rearg(function(a, b, c) {
7287 * return [a, b, c];
7288 * }, 2, 0, 1);
7289 *
7290 * rearged('b', 'c', 'a')
7291 * // => ['a', 'b', 'c']
7292 *
7293 * var map = _.rearg(_.map, [1, 0]);
7294 * map(function(n) {
7295 * return n * 3;
7296 * }, [1, 2, 3]);
7297 * // => [3, 6, 9]
7298 */
7299 var rearg = restParam(function (func, indexes) {
7300 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
7301 });
7302 /**
7303 * Creates a function that invokes `func` with the `this` binding of the
7304 * created function and arguments from `start` and beyond provided as an array.
7305 *
7306 * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
7307 *
7308 * @static
7309 * @memberOf _
7310 * @category Function
7311 * @param {Function} func The function to apply a rest parameter to.
7312 * @param {number} [start=func.length-1] The start position of the rest parameter.
7313 * @returns {Function} Returns the new function.
7314 * @example
7315 *
7316 * var say = _.restParam(function(what, names) {
7317 * return what + ' ' + _.initial(names).join(', ') +
7318 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
7319 * });
7320 *
7321 * say('hello', 'fred', 'barney', 'pebbles');
7322 * // => 'hello fred, barney, & pebbles'
7323 */
7324 function restParam(func, start) {
7325 if (typeof func != 'function') {
7326 throw new TypeError(FUNC_ERROR_TEXT);
7327 }
7328 start = nativeMax(start === undefined ? func.length - 1 : +start || 0, 0);
7329 return function () {
7330 var args = arguments, index = -1, length = nativeMax(args.length - start, 0), rest = Array(length);
7331 while (++index < length) {
7332 rest[index] = args[start + index];
7333 }
7334 switch (start) {
7335 case 0:
7336 return func.call(this, rest);
7337 case 1:
7338 return func.call(this, args[0], rest);
7339 case 2:
7340 return func.call(this, args[0], args[1], rest);
7341 }
7342 var otherArgs = Array(start + 1);
7343 index = -1;
7344 while (++index < start) {
7345 otherArgs[index] = args[index];
7346 }
7347 otherArgs[start] = rest;
7348 return func.apply(this, otherArgs);
7349 };
7350 }
7351 /**
7352 * Creates a function that invokes `func` with the `this` binding of the created
7353 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
7354 *
7355 * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
7356 *
7357 * @static
7358 * @memberOf _
7359 * @category Function
7360 * @param {Function} func The function to spread arguments over.
7361 * @returns {Function} Returns the new function.
7362 * @example
7363 *
7364 * var say = _.spread(function(who, what) {
7365 * return who + ' says ' + what;
7366 * });
7367 *
7368 * say(['fred', 'hello']);
7369 * // => 'fred says hello'
7370 *
7371 * // with a Promise
7372 * var numbers = Promise.all([
7373 * Promise.resolve(40),
7374 * Promise.resolve(36)
7375 * ]);
7376 *
7377 * numbers.then(_.spread(function(x, y) {
7378 * return x + y;
7379 * }));
7380 * // => a Promise of 76
7381 */
7382 function spread(func) {
7383 if (typeof func != 'function') {
7384 throw new TypeError(FUNC_ERROR_TEXT);
7385 }
7386 return function (array) {
7387 return func.apply(this, array);
7388 };
7389 }
7390 /**
7391 * Creates a throttled function that only invokes `func` at most once per
7392 * every `wait` milliseconds. The throttled function comes with a `cancel`
7393 * method to cancel delayed invocations. Provide an options object to indicate
7394 * that `func` should be invoked on the leading and/or trailing edge of the
7395 * `wait` timeout. Subsequent calls to the throttled function return the
7396 * result of the last `func` call.
7397 *
7398 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
7399 * on the trailing edge of the timeout only if the the throttled function is
7400 * invoked more than once during the `wait` timeout.
7401 *
7402 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
7403 * for details over the differences between `_.throttle` and `_.debounce`.
7404 *
7405 * @static
7406 * @memberOf _
7407 * @category Function
7408 * @param {Function} func The function to throttle.
7409 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
7410 * @param {Object} [options] The options object.
7411 * @param {boolean} [options.leading=true] Specify invoking on the leading
7412 * edge of the timeout.
7413 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
7414 * edge of the timeout.
7415 * @returns {Function} Returns the new throttled function.
7416 * @example
7417 *
7418 * // avoid excessively updating the position while scrolling
7419 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
7420 *
7421 * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
7422 * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
7423 * 'trailing': false
7424 * }));
7425 *
7426 * // cancel a trailing throttled call
7427 * jQuery(window).on('popstate', throttled.cancel);
7428 */
7429 function throttle(func, wait, options) {
7430 var leading = true, trailing = true;
7431 if (typeof func != 'function') {
7432 throw new TypeError(FUNC_ERROR_TEXT);
7433 }
7434 if (options === false) {
7435 leading = false;
7436 } else if (isObject(options)) {
7437 leading = 'leading' in options ? !!options.leading : leading;
7438 trailing = 'trailing' in options ? !!options.trailing : trailing;
7439 }
7440 return debounce(func, wait, {
7441 'leading': leading,
7442 'maxWait': +wait,
7443 'trailing': trailing
7444 });
7445 }
7446 /**
7447 * Creates a function that provides `value` to the wrapper function as its
7448 * first argument. Any additional arguments provided to the function are
7449 * appended to those provided to the wrapper function. The wrapper is invoked
7450 * with the `this` binding of the created function.
7451 *
7452 * @static
7453 * @memberOf _
7454 * @category Function
7455 * @param {*} value The value to wrap.
7456 * @param {Function} wrapper The wrapper function.
7457 * @returns {Function} Returns the new function.
7458 * @example
7459 *
7460 * var p = _.wrap(_.escape, function(func, text) {
7461 * return '<p>' + func(text) + '</p>';
7462 * });
7463 *
7464 * p('fred, barney, & pebbles');
7465 * // => '<p>fred, barney, &amp; pebbles</p>'
7466 */
7467 function wrap(value, wrapper) {
7468 wrapper = wrapper == null ? identity : wrapper;
7469 return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
7470 }
7471 /*------------------------------------------------------------------------*/
7472 /**
7473 * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
7474 * otherwise they are assigned by reference. If `customizer` is provided it's
7475 * invoked to produce the cloned values. If `customizer` returns `undefined`
7476 * cloning is handled by the method instead. The `customizer` is bound to
7477 * `thisArg` and invoked with up to three argument; (value [, index|key, object]).
7478 *
7479 * **Note:** This method is loosely based on the
7480 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
7481 * The enumerable properties of `arguments` objects and objects created by
7482 * constructors other than `Object` are cloned to plain `Object` objects. An
7483 * empty object is returned for uncloneable values such as functions, DOM nodes,
7484 * Maps, Sets, and WeakMaps.
7485 *
7486 * @static
7487 * @memberOf _
7488 * @category Lang
7489 * @param {*} value The value to clone.
7490 * @param {boolean} [isDeep] Specify a deep clone.
7491 * @param {Function} [customizer] The function to customize cloning values.
7492 * @param {*} [thisArg] The `this` binding of `customizer`.
7493 * @returns {*} Returns the cloned value.
7494 * @example
7495 *
7496 * var users = [
7497 * { 'user': 'barney' },
7498 * { 'user': 'fred' }
7499 * ];
7500 *
7501 * var shallow = _.clone(users);
7502 * shallow[0] === users[0];
7503 * // => true
7504 *
7505 * var deep = _.clone(users, true);
7506 * deep[0] === users[0];
7507 * // => false
7508 *
7509 * // using a customizer callback
7510 * var el = _.clone(document.body, function(value) {
7511 * if (_.isElement(value)) {
7512 * return value.cloneNode(false);
7513 * }
7514 * });
7515 *
7516 * el === document.body
7517 * // => false
7518 * el.nodeName
7519 * // => BODY
7520 * el.childNodes.length;
7521 * // => 0
7522 */
7523 function clone(value, isDeep, customizer, thisArg) {
7524 if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
7525 isDeep = false;
7526 } else if (typeof isDeep == 'function') {
7527 thisArg = customizer;
7528 customizer = isDeep;
7529 isDeep = false;
7530 }
7531 return typeof customizer == 'function' ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 3)) : baseClone(value, isDeep);
7532 }
7533 /**
7534 * Creates a deep clone of `value`. If `customizer` is provided it's invoked
7535 * to produce the cloned values. If `customizer` returns `undefined` cloning
7536 * is handled by the method instead. The `customizer` is bound to `thisArg`
7537 * and invoked with up to three argument; (value [, index|key, object]).
7538 *
7539 * **Note:** This method is loosely based on the
7540 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
7541 * The enumerable properties of `arguments` objects and objects created by
7542 * constructors other than `Object` are cloned to plain `Object` objects. An
7543 * empty object is returned for uncloneable values such as functions, DOM nodes,
7544 * Maps, Sets, and WeakMaps.
7545 *
7546 * @static
7547 * @memberOf _
7548 * @category Lang
7549 * @param {*} value The value to deep clone.
7550 * @param {Function} [customizer] The function to customize cloning values.
7551 * @param {*} [thisArg] The `this` binding of `customizer`.
7552 * @returns {*} Returns the deep cloned value.
7553 * @example
7554 *
7555 * var users = [
7556 * { 'user': 'barney' },
7557 * { 'user': 'fred' }
7558 * ];
7559 *
7560 * var deep = _.cloneDeep(users);
7561 * deep[0] === users[0];
7562 * // => false
7563 *
7564 * // using a customizer callback
7565 * var el = _.cloneDeep(document.body, function(value) {
7566 * if (_.isElement(value)) {
7567 * return value.cloneNode(true);
7568 * }
7569 * });
7570 *
7571 * el === document.body
7572 * // => false
7573 * el.nodeName
7574 * // => BODY
7575 * el.childNodes.length;
7576 * // => 20
7577 */
7578 function cloneDeep(value, customizer, thisArg) {
7579 return typeof customizer == 'function' ? baseClone(value, true, bindCallback(customizer, thisArg, 3)) : baseClone(value, true);
7580 }
7581 /**
7582 * Checks if `value` is greater than `other`.
7583 *
7584 * @static
7585 * @memberOf _
7586 * @category Lang
7587 * @param {*} value The value to compare.
7588 * @param {*} other The other value to compare.
7589 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
7590 * @example
7591 *
7592 * _.gt(3, 1);
7593 * // => true
7594 *
7595 * _.gt(3, 3);
7596 * // => false
7597 *
7598 * _.gt(1, 3);
7599 * // => false
7600 */
7601 function gt(value, other) {
7602 return value > other;
7603 }
7604 /**
7605 * Checks if `value` is greater than or equal to `other`.
7606 *
7607 * @static
7608 * @memberOf _
7609 * @category Lang
7610 * @param {*} value The value to compare.
7611 * @param {*} other The other value to compare.
7612 * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
7613 * @example
7614 *
7615 * _.gte(3, 1);
7616 * // => true
7617 *
7618 * _.gte(3, 3);
7619 * // => true
7620 *
7621 * _.gte(1, 3);
7622 * // => false
7623 */
7624 function gte(value, other) {
7625 return value >= other;
7626 }
7627 /**
7628 * Checks if `value` is classified as an `arguments` object.
7629 *
7630 * @static
7631 * @memberOf _
7632 * @category Lang
7633 * @param {*} value The value to check.
7634 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7635 * @example
7636 *
7637 * _.isArguments(function() { return arguments; }());
7638 * // => true
7639 *
7640 * _.isArguments([1, 2, 3]);
7641 * // => false
7642 */
7643 function isArguments(value) {
7644 return isObjectLike(value) && isArrayLike(value) && hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
7645 }
7646 /**
7647 * Checks if `value` is classified as an `Array` object.
7648 *
7649 * @static
7650 * @memberOf _
7651 * @category Lang
7652 * @param {*} value The value to check.
7653 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7654 * @example
7655 *
7656 * _.isArray([1, 2, 3]);
7657 * // => true
7658 *
7659 * _.isArray(function() { return arguments; }());
7660 * // => false
7661 */
7662 var isArray = nativeIsArray || function (value) {
7663 return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
7664 };
7665 /**
7666 * Checks if `value` is classified as a boolean primitive or object.
7667 *
7668 * @static
7669 * @memberOf _
7670 * @category Lang
7671 * @param {*} value The value to check.
7672 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7673 * @example
7674 *
7675 * _.isBoolean(false);
7676 * // => true
7677 *
7678 * _.isBoolean(null);
7679 * // => false
7680 */
7681 function isBoolean(value) {
7682 return value === true || value === false || isObjectLike(value) && objToString.call(value) == boolTag;
7683 }
7684 /**
7685 * Checks if `value` is classified as a `Date` object.
7686 *
7687 * @static
7688 * @memberOf _
7689 * @category Lang
7690 * @param {*} value The value to check.
7691 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7692 * @example
7693 *
7694 * _.isDate(new Date);
7695 * // => true
7696 *
7697 * _.isDate('Mon April 23 2012');
7698 * // => false
7699 */
7700 function isDate(value) {
7701 return isObjectLike(value) && objToString.call(value) == dateTag;
7702 }
7703 /**
7704 * Checks if `value` is a DOM element.
7705 *
7706 * @static
7707 * @memberOf _
7708 * @category Lang
7709 * @param {*} value The value to check.
7710 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
7711 * @example
7712 *
7713 * _.isElement(document.body);
7714 * // => true
7715 *
7716 * _.isElement('<body>');
7717 * // => false
7718 */
7719 function isElement(value) {
7720 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
7721 }
7722 /**
7723 * Checks if `value` is empty. A value is considered empty unless it's an
7724 * `arguments` object, array, string, or jQuery-like collection with a length
7725 * greater than `0` or an object with own enumerable properties.
7726 *
7727 * @static
7728 * @memberOf _
7729 * @category Lang
7730 * @param {Array|Object|string} value The value to inspect.
7731 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
7732 * @example
7733 *
7734 * _.isEmpty(null);
7735 * // => true
7736 *
7737 * _.isEmpty(true);
7738 * // => true
7739 *
7740 * _.isEmpty(1);
7741 * // => true
7742 *
7743 * _.isEmpty([1, 2, 3]);
7744 * // => false
7745 *
7746 * _.isEmpty({ 'a': 1 });
7747 * // => false
7748 */
7749 function isEmpty(value) {
7750 if (value == null) {
7751 return true;
7752 }
7753 if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) || isObjectLike(value) && isFunction(value.splice))) {
7754 return !value.length;
7755 }
7756 return !keys(value).length;
7757 }
7758 /**
7759 * Performs a deep comparison between two values to determine if they are
7760 * equivalent. If `customizer` is provided it's invoked to compare values.
7761 * If `customizer` returns `undefined` comparisons are handled by the method
7762 * instead. The `customizer` is bound to `thisArg` and invoked with up to
7763 * three arguments: (value, other [, index|key]).
7764 *
7765 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
7766 * numbers, `Object` objects, regexes, and strings. Objects are compared by
7767 * their own, not inherited, enumerable properties. Functions and DOM nodes
7768 * are **not** supported. Provide a customizer function to extend support
7769 * for comparing other values.
7770 *
7771 * @static
7772 * @memberOf _
7773 * @alias eq
7774 * @category Lang
7775 * @param {*} value The value to compare.
7776 * @param {*} other The other value to compare.
7777 * @param {Function} [customizer] The function to customize value comparisons.
7778 * @param {*} [thisArg] The `this` binding of `customizer`.
7779 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
7780 * @example
7781 *
7782 * var object = { 'user': 'fred' };
7783 * var other = { 'user': 'fred' };
7784 *
7785 * object == other;
7786 * // => false
7787 *
7788 * _.isEqual(object, other);
7789 * // => true
7790 *
7791 * // using a customizer callback
7792 * var array = ['hello', 'goodbye'];
7793 * var other = ['hi', 'goodbye'];
7794 *
7795 * _.isEqual(array, other, function(value, other) {
7796 * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
7797 * return true;
7798 * }
7799 * });
7800 * // => true
7801 */
7802 function isEqual(value, other, customizer, thisArg) {
7803 customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
7804 var result = customizer ? customizer(value, other) : undefined;
7805 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
7806 }
7807 /**
7808 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
7809 * `SyntaxError`, `TypeError`, or `URIError` object.
7810 *
7811 * @static
7812 * @memberOf _
7813 * @category Lang
7814 * @param {*} value The value to check.
7815 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
7816 * @example
7817 *
7818 * _.isError(new Error);
7819 * // => true
7820 *
7821 * _.isError(Error);
7822 * // => false
7823 */
7824 function isError(value) {
7825 return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
7826 }
7827 /**
7828 * Checks if `value` is a finite primitive number.
7829 *
7830 * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
7831 *
7832 * @static
7833 * @memberOf _
7834 * @category Lang
7835 * @param {*} value The value to check.
7836 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
7837 * @example
7838 *
7839 * _.isFinite(10);
7840 * // => true
7841 *
7842 * _.isFinite('10');
7843 * // => false
7844 *
7845 * _.isFinite(true);
7846 * // => false
7847 *
7848 * _.isFinite(Object(10));
7849 * // => false
7850 *
7851 * _.isFinite(Infinity);
7852 * // => false
7853 */
7854 function isFinite(value) {
7855 return typeof value == 'number' && nativeIsFinite(value);
7856 }
7857 /**
7858 * Checks if `value` is classified as a `Function` object.
7859 *
7860 * @static
7861 * @memberOf _
7862 * @category Lang
7863 * @param {*} value The value to check.
7864 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
7865 * @example
7866 *
7867 * _.isFunction(_);
7868 * // => true
7869 *
7870 * _.isFunction(/abc/);
7871 * // => false
7872 */
7873 function isFunction(value) {
7874 // The use of `Object#toString` avoids issues with the `typeof` operator
7875 // in older versions of Chrome and Safari which return 'function' for regexes
7876 // and Safari 8 which returns 'object' for typed array constructors.
7877 return isObject(value) && objToString.call(value) == funcTag;
7878 }
7879 /**
7880 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
7881 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
7882 *
7883 * @static
7884 * @memberOf _
7885 * @category Lang
7886 * @param {*} value The value to check.
7887 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
7888 * @example
7889 *
7890 * _.isObject({});
7891 * // => true
7892 *
7893 * _.isObject([1, 2, 3]);
7894 * // => true
7895 *
7896 * _.isObject(1);
7897 * // => false
7898 */
7899 function isObject(value) {
7900 // Avoid a V8 JIT bug in Chrome 19-20.
7901 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
7902 var type = typeof value;
7903 return !!value && (type == 'object' || type == 'function');
7904 }
7905 /**
7906 * Performs a deep comparison between `object` and `source` to determine if
7907 * `object` contains equivalent property values. If `customizer` is provided
7908 * it's invoked to compare values. If `customizer` returns `undefined`
7909 * comparisons are handled by the method instead. The `customizer` is bound
7910 * to `thisArg` and invoked with three arguments: (value, other, index|key).
7911 *
7912 * **Note:** This method supports comparing properties of arrays, booleans,
7913 * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
7914 * and DOM nodes are **not** supported. Provide a customizer function to extend
7915 * support for comparing other values.
7916 *
7917 * @static
7918 * @memberOf _
7919 * @category Lang
7920 * @param {Object} object The object to inspect.
7921 * @param {Object} source The object of property values to match.
7922 * @param {Function} [customizer] The function to customize value comparisons.
7923 * @param {*} [thisArg] The `this` binding of `customizer`.
7924 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
7925 * @example
7926 *
7927 * var object = { 'user': 'fred', 'age': 40 };
7928 *
7929 * _.isMatch(object, { 'age': 40 });
7930 * // => true
7931 *
7932 * _.isMatch(object, { 'age': 36 });
7933 * // => false
7934 *
7935 * // using a customizer callback
7936 * var object = { 'greeting': 'hello' };
7937 * var source = { 'greeting': 'hi' };
7938 *
7939 * _.isMatch(object, source, function(value, other) {
7940 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
7941 * });
7942 * // => true
7943 */
7944 function isMatch(object, source, customizer, thisArg) {
7945 customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
7946 return baseIsMatch(object, getMatchData(source), customizer);
7947 }
7948 /**
7949 * Checks if `value` is `NaN`.
7950 *
7951 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
7952 * which returns `true` for `undefined` and other non-numeric values.
7953 *
7954 * @static
7955 * @memberOf _
7956 * @category Lang
7957 * @param {*} value The value to check.
7958 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
7959 * @example
7960 *
7961 * _.isNaN(NaN);
7962 * // => true
7963 *
7964 * _.isNaN(new Number(NaN));
7965 * // => true
7966 *
7967 * isNaN(undefined);
7968 * // => true
7969 *
7970 * _.isNaN(undefined);
7971 * // => false
7972 */
7973 function isNaN(value) {
7974 // An `NaN` primitive is the only value that is not equal to itself.
7975 // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
7976 return isNumber(value) && value != +value;
7977 }
7978 /**
7979 * Checks if `value` is a native function.
7980 *
7981 * @static
7982 * @memberOf _
7983 * @category Lang
7984 * @param {*} value The value to check.
7985 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
7986 * @example
7987 *
7988 * _.isNative(Array.prototype.push);
7989 * // => true
7990 *
7991 * _.isNative(_);
7992 * // => false
7993 */
7994 function isNative(value) {
7995 if (value == null) {
7996 return false;
7997 }
7998 if (isFunction(value)) {
7999 return reIsNative.test(fnToString.call(value));
8000 }
8001 return isObjectLike(value) && reIsHostCtor.test(value);
8002 }
8003 /**
8004 * Checks if `value` is `null`.
8005 *
8006 * @static
8007 * @memberOf _
8008 * @category Lang
8009 * @param {*} value The value to check.
8010 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
8011 * @example
8012 *
8013 * _.isNull(null);
8014 * // => true
8015 *
8016 * _.isNull(void 0);
8017 * // => false
8018 */
8019 function isNull(value) {
8020 return value === null;
8021 }
8022 /**
8023 * Checks if `value` is classified as a `Number` primitive or object.
8024 *
8025 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
8026 * as numbers, use the `_.isFinite` method.
8027 *
8028 * @static
8029 * @memberOf _
8030 * @category Lang
8031 * @param {*} value The value to check.
8032 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8033 * @example
8034 *
8035 * _.isNumber(8.4);
8036 * // => true
8037 *
8038 * _.isNumber(NaN);
8039 * // => true
8040 *
8041 * _.isNumber('8.4');
8042 * // => false
8043 */
8044 function isNumber(value) {
8045 return typeof value == 'number' || isObjectLike(value) && objToString.call(value) == numberTag;
8046 }
8047 /**
8048 * Checks if `value` is a plain object, that is, an object created by the
8049 * `Object` constructor or one with a `[[Prototype]]` of `null`.
8050 *
8051 * **Note:** This method assumes objects created by the `Object` constructor
8052 * have no inherited enumerable properties.
8053 *
8054 * @static
8055 * @memberOf _
8056 * @category Lang
8057 * @param {*} value The value to check.
8058 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
8059 * @example
8060 *
8061 * function Foo() {
8062 * this.a = 1;
8063 * }
8064 *
8065 * _.isPlainObject(new Foo);
8066 * // => false
8067 *
8068 * _.isPlainObject([1, 2, 3]);
8069 * // => false
8070 *
8071 * _.isPlainObject({ 'x': 0, 'y': 0 });
8072 * // => true
8073 *
8074 * _.isPlainObject(Object.create(null));
8075 * // => true
8076 */
8077 function isPlainObject(value) {
8078 var Ctor;
8079 // Exit early for non `Object` objects.
8080 if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) || !hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor))) {
8081 return false;
8082 }
8083 // IE < 9 iterates inherited properties before own properties. If the first
8084 // iterated property is an object's own property then there are no inherited
8085 // enumerable properties.
8086 var result;
8087 // In most environments an object's own properties are iterated before
8088 // its inherited properties. If the last iterated property is an object's
8089 // own property then there are no inherited enumerable properties.
8090 baseForIn(value, function (subValue, key) {
8091 result = key;
8092 });
8093 return result === undefined || hasOwnProperty.call(value, result);
8094 }
8095 /**
8096 * Checks if `value` is classified as a `RegExp` object.
8097 *
8098 * @static
8099 * @memberOf _
8100 * @category Lang
8101 * @param {*} value The value to check.
8102 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8103 * @example
8104 *
8105 * _.isRegExp(/abc/);
8106 * // => true
8107 *
8108 * _.isRegExp('/abc/');
8109 * // => false
8110 */
8111 function isRegExp(value) {
8112 return isObject(value) && objToString.call(value) == regexpTag;
8113 }
8114 /**
8115 * Checks if `value` is classified as a `String` primitive or object.
8116 *
8117 * @static
8118 * @memberOf _
8119 * @category Lang
8120 * @param {*} value The value to check.
8121 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8122 * @example
8123 *
8124 * _.isString('abc');
8125 * // => true
8126 *
8127 * _.isString(1);
8128 * // => false
8129 */
8130 function isString(value) {
8131 return typeof value == 'string' || isObjectLike(value) && objToString.call(value) == stringTag;
8132 }
8133 /**
8134 * Checks if `value` is classified as a typed array.
8135 *
8136 * @static
8137 * @memberOf _
8138 * @category Lang
8139 * @param {*} value The value to check.
8140 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8141 * @example
8142 *
8143 * _.isTypedArray(new Uint8Array);
8144 * // => true
8145 *
8146 * _.isTypedArray([]);
8147 * // => false
8148 */
8149 function isTypedArray(value) {
8150 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
8151 }
8152 /**
8153 * Checks if `value` is `undefined`.
8154 *
8155 * @static
8156 * @memberOf _
8157 * @category Lang
8158 * @param {*} value The value to check.
8159 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
8160 * @example
8161 *
8162 * _.isUndefined(void 0);
8163 * // => true
8164 *
8165 * _.isUndefined(null);
8166 * // => false
8167 */
8168 function isUndefined(value) {
8169 return value === undefined;
8170 }
8171 /**
8172 * Checks if `value` is less than `other`.
8173 *
8174 * @static
8175 * @memberOf _
8176 * @category Lang
8177 * @param {*} value The value to compare.
8178 * @param {*} other The other value to compare.
8179 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
8180 * @example
8181 *
8182 * _.lt(1, 3);
8183 * // => true
8184 *
8185 * _.lt(3, 3);
8186 * // => false
8187 *
8188 * _.lt(3, 1);
8189 * // => false
8190 */
8191 function lt(value, other) {
8192 return value < other;
8193 }
8194 /**
8195 * Checks if `value` is less than or equal to `other`.
8196 *
8197 * @static
8198 * @memberOf _
8199 * @category Lang
8200 * @param {*} value The value to compare.
8201 * @param {*} other The other value to compare.
8202 * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
8203 * @example
8204 *
8205 * _.lte(1, 3);
8206 * // => true
8207 *
8208 * _.lte(3, 3);
8209 * // => true
8210 *
8211 * _.lte(3, 1);
8212 * // => false
8213 */
8214 function lte(value, other) {
8215 return value <= other;
8216 }
8217 /**
8218 * Converts `value` to an array.
8219 *
8220 * @static
8221 * @memberOf _
8222 * @category Lang
8223 * @param {*} value The value to convert.
8224 * @returns {Array} Returns the converted array.
8225 * @example
8226 *
8227 * (function() {
8228 * return _.toArray(arguments).slice(1);
8229 * }(1, 2, 3));
8230 * // => [2, 3]
8231 */
8232 function toArray(value) {
8233 var length = value ? getLength(value) : 0;
8234 if (!isLength(length)) {
8235 return values(value);
8236 }
8237 if (!length) {
8238 return [];
8239 }
8240 return arrayCopy(value);
8241 }
8242 /**
8243 * Converts `value` to a plain object flattening inherited enumerable
8244 * properties of `value` to own properties of the plain object.
8245 *
8246 * @static
8247 * @memberOf _
8248 * @category Lang
8249 * @param {*} value The value to convert.
8250 * @returns {Object} Returns the converted plain object.
8251 * @example
8252 *
8253 * function Foo() {
8254 * this.b = 2;
8255 * }
8256 *
8257 * Foo.prototype.c = 3;
8258 *
8259 * _.assign({ 'a': 1 }, new Foo);
8260 * // => { 'a': 1, 'b': 2 }
8261 *
8262 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
8263 * // => { 'a': 1, 'b': 2, 'c': 3 }
8264 */
8265 function toPlainObject(value) {
8266 return baseCopy(value, keysIn(value));
8267 }
8268 /*------------------------------------------------------------------------*/
8269 /**
8270 * Recursively merges own enumerable properties of the source object(s), that
8271 * don't resolve to `undefined` into the destination object. Subsequent sources
8272 * overwrite property assignments of previous sources. If `customizer` is
8273 * provided it's invoked to produce the merged values of the destination and
8274 * source properties. If `customizer` returns `undefined` merging is handled
8275 * by the method instead. The `customizer` is bound to `thisArg` and invoked
8276 * with five arguments: (objectValue, sourceValue, key, object, source).
8277 *
8278 * @static
8279 * @memberOf _
8280 * @category Object
8281 * @param {Object} object The destination object.
8282 * @param {...Object} [sources] The source objects.
8283 * @param {Function} [customizer] The function to customize assigned values.
8284 * @param {*} [thisArg] The `this` binding of `customizer`.
8285 * @returns {Object} Returns `object`.
8286 * @example
8287 *
8288 * var users = {
8289 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
8290 * };
8291 *
8292 * var ages = {
8293 * 'data': [{ 'age': 36 }, { 'age': 40 }]
8294 * };
8295 *
8296 * _.merge(users, ages);
8297 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
8298 *
8299 * // using a customizer callback
8300 * var object = {
8301 * 'fruits': ['apple'],
8302 * 'vegetables': ['beet']
8303 * };
8304 *
8305 * var other = {
8306 * 'fruits': ['banana'],
8307 * 'vegetables': ['carrot']
8308 * };
8309 *
8310 * _.merge(object, other, function(a, b) {
8311 * if (_.isArray(a)) {
8312 * return a.concat(b);
8313 * }
8314 * });
8315 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
8316 */
8317 var merge = createAssigner(baseMerge);
8318 /**
8319 * Assigns own enumerable properties of source object(s) to the destination
8320 * object. Subsequent sources overwrite property assignments of previous sources.
8321 * If `customizer` is provided it's invoked to produce the assigned values.
8322 * The `customizer` is bound to `thisArg` and invoked with five arguments:
8323 * (objectValue, sourceValue, key, object, source).
8324 *
8325 * **Note:** This method mutates `object` and is based on
8326 * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
8327 *
8328 * @static
8329 * @memberOf _
8330 * @alias extend
8331 * @category Object
8332 * @param {Object} object The destination object.
8333 * @param {...Object} [sources] The source objects.
8334 * @param {Function} [customizer] The function to customize assigned values.
8335 * @param {*} [thisArg] The `this` binding of `customizer`.
8336 * @returns {Object} Returns `object`.
8337 * @example
8338 *
8339 * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
8340 * // => { 'user': 'fred', 'age': 40 }
8341 *
8342 * // using a customizer callback
8343 * var defaults = _.partialRight(_.assign, function(value, other) {
8344 * return _.isUndefined(value) ? other : value;
8345 * });
8346 *
8347 * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
8348 * // => { 'user': 'barney', 'age': 36 }
8349 */
8350 var assign = createAssigner(function (object, source, customizer) {
8351 return customizer ? assignWith(object, source, customizer) : baseAssign(object, source);
8352 });
8353 /**
8354 * Creates an object that inherits from the given `prototype` object. If a
8355 * `properties` object is provided its own enumerable properties are assigned
8356 * to the created object.
8357 *
8358 * @static
8359 * @memberOf _
8360 * @category Object
8361 * @param {Object} prototype The object to inherit from.
8362 * @param {Object} [properties] The properties to assign to the object.
8363 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
8364 * @returns {Object} Returns the new object.
8365 * @example
8366 *
8367 * function Shape() {
8368 * this.x = 0;
8369 * this.y = 0;
8370 * }
8371 *
8372 * function Circle() {
8373 * Shape.call(this);
8374 * }
8375 *
8376 * Circle.prototype = _.create(Shape.prototype, {
8377 * 'constructor': Circle
8378 * });
8379 *
8380 * var circle = new Circle;
8381 * circle instanceof Circle;
8382 * // => true
8383 *
8384 * circle instanceof Shape;
8385 * // => true
8386 */
8387 function create(prototype, properties, guard) {
8388 var result = baseCreate(prototype);
8389 if (guard && isIterateeCall(prototype, properties, guard)) {
8390 properties = undefined;
8391 }
8392 return properties ? baseAssign(result, properties) : result;
8393 }
8394 /**
8395 * Assigns own enumerable properties of source object(s) to the destination
8396 * object for all destination properties that resolve to `undefined`. Once a
8397 * property is set, additional values of the same property are ignored.
8398 *
8399 * **Note:** This method mutates `object`.
8400 *
8401 * @static
8402 * @memberOf _
8403 * @category Object
8404 * @param {Object} object The destination object.
8405 * @param {...Object} [sources] The source objects.
8406 * @returns {Object} Returns `object`.
8407 * @example
8408 *
8409 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
8410 * // => { 'user': 'barney', 'age': 36 }
8411 */
8412 var defaults = createDefaults(assign, assignDefaults);
8413 /**
8414 * This method is like `_.defaults` except that it recursively assigns
8415 * default properties.
8416 *
8417 * **Note:** This method mutates `object`.
8418 *
8419 * @static
8420 * @memberOf _
8421 * @category Object
8422 * @param {Object} object The destination object.
8423 * @param {...Object} [sources] The source objects.
8424 * @returns {Object} Returns `object`.
8425 * @example
8426 *
8427 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
8428 * // => { 'user': { 'name': 'barney', 'age': 36 } }
8429 *
8430 */
8431 var defaultsDeep = createDefaults(merge, mergeDefaults);
8432 /**
8433 * This method is like `_.find` except that it returns the key of the first
8434 * element `predicate` returns truthy for instead of the element itself.
8435 *
8436 * If a property name is provided for `predicate` the created `_.property`
8437 * style callback returns the property value of the given element.
8438 *
8439 * If a value is also provided for `thisArg` the created `_.matchesProperty`
8440 * style callback returns `true` for elements that have a matching property
8441 * value, else `false`.
8442 *
8443 * If an object is provided for `predicate` the created `_.matches` style
8444 * callback returns `true` for elements that have the properties of the given
8445 * object, else `false`.
8446 *
8447 * @static
8448 * @memberOf _
8449 * @category Object
8450 * @param {Object} object The object to search.
8451 * @param {Function|Object|string} [predicate=_.identity] The function invoked
8452 * per iteration.
8453 * @param {*} [thisArg] The `this` binding of `predicate`.
8454 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
8455 * @example
8456 *
8457 * var users = {
8458 * 'barney': { 'age': 36, 'active': true },
8459 * 'fred': { 'age': 40, 'active': false },
8460 * 'pebbles': { 'age': 1, 'active': true }
8461 * };
8462 *
8463 * _.findKey(users, function(chr) {
8464 * return chr.age < 40;
8465 * });
8466 * // => 'barney' (iteration order is not guaranteed)
8467 *
8468 * // using the `_.matches` callback shorthand
8469 * _.findKey(users, { 'age': 1, 'active': true });
8470 * // => 'pebbles'
8471 *
8472 * // using the `_.matchesProperty` callback shorthand
8473 * _.findKey(users, 'active', false);
8474 * // => 'fred'
8475 *
8476 * // using the `_.property` callback shorthand
8477 * _.findKey(users, 'active');
8478 * // => 'barney'
8479 */
8480 var findKey = createFindKey(baseForOwn);
8481 /**
8482 * This method is like `_.findKey` except that it iterates over elements of
8483 * a collection in the opposite order.
8484 *
8485 * If a property name is provided for `predicate` the created `_.property`
8486 * style callback returns the property value of the given element.
8487 *
8488 * If a value is also provided for `thisArg` the created `_.matchesProperty`
8489 * style callback returns `true` for elements that have a matching property
8490 * value, else `false`.
8491 *
8492 * If an object is provided for `predicate` the created `_.matches` style
8493 * callback returns `true` for elements that have the properties of the given
8494 * object, else `false`.
8495 *
8496 * @static
8497 * @memberOf _
8498 * @category Object
8499 * @param {Object} object The object to search.
8500 * @param {Function|Object|string} [predicate=_.identity] The function invoked
8501 * per iteration.
8502 * @param {*} [thisArg] The `this` binding of `predicate`.
8503 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
8504 * @example
8505 *
8506 * var users = {
8507 * 'barney': { 'age': 36, 'active': true },
8508 * 'fred': { 'age': 40, 'active': false },
8509 * 'pebbles': { 'age': 1, 'active': true }
8510 * };
8511 *
8512 * _.findLastKey(users, function(chr) {
8513 * return chr.age < 40;
8514 * });
8515 * // => returns `pebbles` assuming `_.findKey` returns `barney`
8516 *
8517 * // using the `_.matches` callback shorthand
8518 * _.findLastKey(users, { 'age': 36, 'active': true });
8519 * // => 'barney'
8520 *
8521 * // using the `_.matchesProperty` callback shorthand
8522 * _.findLastKey(users, 'active', false);
8523 * // => 'fred'
8524 *
8525 * // using the `_.property` callback shorthand
8526 * _.findLastKey(users, 'active');
8527 * // => 'pebbles'
8528 */
8529 var findLastKey = createFindKey(baseForOwnRight);
8530 /**
8531 * Iterates over own and inherited enumerable properties of an object invoking
8532 * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
8533 * with three arguments: (value, key, object). Iteratee functions may exit
8534 * iteration early by explicitly returning `false`.
8535 *
8536 * @static
8537 * @memberOf _
8538 * @category Object
8539 * @param {Object} object The object to iterate over.
8540 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8541 * @param {*} [thisArg] The `this` binding of `iteratee`.
8542 * @returns {Object} Returns `object`.
8543 * @example
8544 *
8545 * function Foo() {
8546 * this.a = 1;
8547 * this.b = 2;
8548 * }
8549 *
8550 * Foo.prototype.c = 3;
8551 *
8552 * _.forIn(new Foo, function(value, key) {
8553 * console.log(key);
8554 * });
8555 * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
8556 */
8557 var forIn = createForIn(baseFor);
8558 /**
8559 * This method is like `_.forIn` except that it iterates over properties of
8560 * `object` in the opposite order.
8561 *
8562 * @static
8563 * @memberOf _
8564 * @category Object
8565 * @param {Object} object The object to iterate over.
8566 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8567 * @param {*} [thisArg] The `this` binding of `iteratee`.
8568 * @returns {Object} Returns `object`.
8569 * @example
8570 *
8571 * function Foo() {
8572 * this.a = 1;
8573 * this.b = 2;
8574 * }
8575 *
8576 * Foo.prototype.c = 3;
8577 *
8578 * _.forInRight(new Foo, function(value, key) {
8579 * console.log(key);
8580 * });
8581 * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
8582 */
8583 var forInRight = createForIn(baseForRight);
8584 /**
8585 * Iterates over own enumerable properties of an object invoking `iteratee`
8586 * for each property. The `iteratee` is bound to `thisArg` and invoked with
8587 * three arguments: (value, key, object). Iteratee functions may exit iteration
8588 * early by explicitly returning `false`.
8589 *
8590 * @static
8591 * @memberOf _
8592 * @category Object
8593 * @param {Object} object The object to iterate over.
8594 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8595 * @param {*} [thisArg] The `this` binding of `iteratee`.
8596 * @returns {Object} Returns `object`.
8597 * @example
8598 *
8599 * function Foo() {
8600 * this.a = 1;
8601 * this.b = 2;
8602 * }
8603 *
8604 * Foo.prototype.c = 3;
8605 *
8606 * _.forOwn(new Foo, function(value, key) {
8607 * console.log(key);
8608 * });
8609 * // => logs 'a' and 'b' (iteration order is not guaranteed)
8610 */
8611 var forOwn = createForOwn(baseForOwn);
8612 /**
8613 * This method is like `_.forOwn` except that it iterates over properties of
8614 * `object` in the opposite order.
8615 *
8616 * @static
8617 * @memberOf _
8618 * @category Object
8619 * @param {Object} object The object to iterate over.
8620 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8621 * @param {*} [thisArg] The `this` binding of `iteratee`.
8622 * @returns {Object} Returns `object`.
8623 * @example
8624 *
8625 * function Foo() {
8626 * this.a = 1;
8627 * this.b = 2;
8628 * }
8629 *
8630 * Foo.prototype.c = 3;
8631 *
8632 * _.forOwnRight(new Foo, function(value, key) {
8633 * console.log(key);
8634 * });
8635 * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
8636 */
8637 var forOwnRight = createForOwn(baseForOwnRight);
8638 /**
8639 * Creates an array of function property names from all enumerable properties,
8640 * own and inherited, of `object`.
8641 *
8642 * @static
8643 * @memberOf _
8644 * @alias methods
8645 * @category Object
8646 * @param {Object} object The object to inspect.
8647 * @returns {Array} Returns the new array of property names.
8648 * @example
8649 *
8650 * _.functions(_);
8651 * // => ['after', 'ary', 'assign', ...]
8652 */
8653 function functions(object) {
8654 return baseFunctions(object, keysIn(object));
8655 }
8656 /**
8657 * Gets the property value at `path` of `object`. If the resolved value is
8658 * `undefined` the `defaultValue` is used in its place.
8659 *
8660 * @static
8661 * @memberOf _
8662 * @category Object
8663 * @param {Object} object The object to query.
8664 * @param {Array|string} path The path of the property to get.
8665 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
8666 * @returns {*} Returns the resolved value.
8667 * @example
8668 *
8669 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
8670 *
8671 * _.get(object, 'a[0].b.c');
8672 * // => 3
8673 *
8674 * _.get(object, ['a', '0', 'b', 'c']);
8675 * // => 3
8676 *
8677 * _.get(object, 'a.b.c', 'default');
8678 * // => 'default'
8679 */
8680 function get(object, path, defaultValue) {
8681 var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
8682 return result === undefined ? defaultValue : result;
8683 }
8684 /**
8685 * Checks if `path` is a direct property.
8686 *
8687 * @static
8688 * @memberOf _
8689 * @category Object
8690 * @param {Object} object The object to query.
8691 * @param {Array|string} path The path to check.
8692 * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
8693 * @example
8694 *
8695 * var object = { 'a': { 'b': { 'c': 3 } } };
8696 *
8697 * _.has(object, 'a');
8698 * // => true
8699 *
8700 * _.has(object, 'a.b.c');
8701 * // => true
8702 *
8703 * _.has(object, ['a', 'b', 'c']);
8704 * // => true
8705 */
8706 function has(object, path) {
8707 if (object == null) {
8708 return false;
8709 }
8710 var result = hasOwnProperty.call(object, path);
8711 if (!result && !isKey(path)) {
8712 path = toPath(path);
8713 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
8714 if (object == null) {
8715 return false;
8716 }
8717 path = last(path);
8718 result = hasOwnProperty.call(object, path);
8719 }
8720 return result || isLength(object.length) && isIndex(path, object.length) && (isArray(object) || isArguments(object));
8721 }
8722 /**
8723 * Creates an object composed of the inverted keys and values of `object`.
8724 * If `object` contains duplicate values, subsequent values overwrite property
8725 * assignments of previous values unless `multiValue` is `true`.
8726 *
8727 * @static
8728 * @memberOf _
8729 * @category Object
8730 * @param {Object} object The object to invert.
8731 * @param {boolean} [multiValue] Allow multiple values per key.
8732 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
8733 * @returns {Object} Returns the new inverted object.
8734 * @example
8735 *
8736 * var object = { 'a': 1, 'b': 2, 'c': 1 };
8737 *
8738 * _.invert(object);
8739 * // => { '1': 'c', '2': 'b' }
8740 *
8741 * // with `multiValue`
8742 * _.invert(object, true);
8743 * // => { '1': ['a', 'c'], '2': ['b'] }
8744 */
8745 function invert(object, multiValue, guard) {
8746 if (guard && isIterateeCall(object, multiValue, guard)) {
8747 multiValue = undefined;
8748 }
8749 var index = -1, props = keys(object), length = props.length, result = {};
8750 while (++index < length) {
8751 var key = props[index], value = object[key];
8752 if (multiValue) {
8753 if (hasOwnProperty.call(result, value)) {
8754 result[value].push(key);
8755 } else {
8756 result[value] = [key];
8757 }
8758 } else {
8759 result[value] = key;
8760 }
8761 }
8762 return result;
8763 }
8764 /**
8765 * Creates an array of the own enumerable property names of `object`.
8766 *
8767 * **Note:** Non-object values are coerced to objects. See the
8768 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
8769 * for more details.
8770 *
8771 * @static
8772 * @memberOf _
8773 * @category Object
8774 * @param {Object} object The object to query.
8775 * @returns {Array} Returns the array of property names.
8776 * @example
8777 *
8778 * function Foo() {
8779 * this.a = 1;
8780 * this.b = 2;
8781 * }
8782 *
8783 * Foo.prototype.c = 3;
8784 *
8785 * _.keys(new Foo);
8786 * // => ['a', 'b'] (iteration order is not guaranteed)
8787 *
8788 * _.keys('hi');
8789 * // => ['0', '1']
8790 */
8791 var keys = !nativeKeys ? shimKeys : function (object) {
8792 var Ctor = object == null ? undefined : object.constructor;
8793 if (typeof Ctor == 'function' && Ctor.prototype === object || typeof object != 'function' && isArrayLike(object)) {
8794 return shimKeys(object);
8795 }
8796 return isObject(object) ? nativeKeys(object) : [];
8797 };
8798 /**
8799 * Creates an array of the own and inherited enumerable property names of `object`.
8800 *
8801 * **Note:** Non-object values are coerced to objects.
8802 *
8803 * @static
8804 * @memberOf _
8805 * @category Object
8806 * @param {Object} object The object to query.
8807 * @returns {Array} Returns the array of property names.
8808 * @example
8809 *
8810 * function Foo() {
8811 * this.a = 1;
8812 * this.b = 2;
8813 * }
8814 *
8815 * Foo.prototype.c = 3;
8816 *
8817 * _.keysIn(new Foo);
8818 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
8819 */
8820 function keysIn(object) {
8821 if (object == null) {
8822 return [];
8823 }
8824 if (!isObject(object)) {
8825 object = Object(object);
8826 }
8827 var length = object.length;
8828 length = length && isLength(length) && (isArray(object) || isArguments(object)) && length || 0;
8829 var Ctor = object.constructor, index = -1, isProto = typeof Ctor == 'function' && Ctor.prototype === object, result = Array(length), skipIndexes = length > 0;
8830 while (++index < length) {
8831 result[index] = index + '';
8832 }
8833 for (var key in object) {
8834 if (!(skipIndexes && isIndex(key, length)) && !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
8835 result.push(key);
8836 }
8837 }
8838 return result;
8839 }
8840 /**
8841 * The opposite of `_.mapValues`; this method creates an object with the
8842 * same values as `object` and keys generated by running each own enumerable
8843 * property of `object` through `iteratee`.
8844 *
8845 * @static
8846 * @memberOf _
8847 * @category Object
8848 * @param {Object} object The object to iterate over.
8849 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
8850 * per iteration.
8851 * @param {*} [thisArg] The `this` binding of `iteratee`.
8852 * @returns {Object} Returns the new mapped object.
8853 * @example
8854 *
8855 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
8856 * return key + value;
8857 * });
8858 * // => { 'a1': 1, 'b2': 2 }
8859 */
8860 var mapKeys = createObjectMapper(true);
8861 /**
8862 * Creates an object with the same keys as `object` and values generated by
8863 * running each own enumerable property of `object` through `iteratee`. The
8864 * iteratee function is bound to `thisArg` and invoked with three arguments:
8865 * (value, key, object).
8866 *
8867 * If a property name is provided for `iteratee` the created `_.property`
8868 * style callback returns the property value of the given element.
8869 *
8870 * If a value is also provided for `thisArg` the created `_.matchesProperty`
8871 * style callback returns `true` for elements that have a matching property
8872 * value, else `false`.
8873 *
8874 * If an object is provided for `iteratee` the created `_.matches` style
8875 * callback returns `true` for elements that have the properties of the given
8876 * object, else `false`.
8877 *
8878 * @static
8879 * @memberOf _
8880 * @category Object
8881 * @param {Object} object The object to iterate over.
8882 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
8883 * per iteration.
8884 * @param {*} [thisArg] The `this` binding of `iteratee`.
8885 * @returns {Object} Returns the new mapped object.
8886 * @example
8887 *
8888 * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
8889 * return n * 3;
8890 * });
8891 * // => { 'a': 3, 'b': 6 }
8892 *
8893 * var users = {
8894 * 'fred': { 'user': 'fred', 'age': 40 },
8895 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
8896 * };
8897 *
8898 * // using the `_.property` callback shorthand
8899 * _.mapValues(users, 'age');
8900 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
8901 */
8902 var mapValues = createObjectMapper();
8903 /**
8904 * The opposite of `_.pick`; this method creates an object composed of the
8905 * own and inherited enumerable properties of `object` that are not omitted.
8906 *
8907 * @static
8908 * @memberOf _
8909 * @category Object
8910 * @param {Object} object The source object.
8911 * @param {Function|...(string|string[])} [predicate] The function invoked per
8912 * iteration or property names to omit, specified as individual property
8913 * names or arrays of property names.
8914 * @param {*} [thisArg] The `this` binding of `predicate`.
8915 * @returns {Object} Returns the new object.
8916 * @example
8917 *
8918 * var object = { 'user': 'fred', 'age': 40 };
8919 *
8920 * _.omit(object, 'age');
8921 * // => { 'user': 'fred' }
8922 *
8923 * _.omit(object, _.isNumber);
8924 * // => { 'user': 'fred' }
8925 */
8926 var omit = restParam(function (object, props) {
8927 if (object == null) {
8928 return {};
8929 }
8930 if (typeof props[0] != 'function') {
8931 var props = arrayMap(baseFlatten(props), String);
8932 return pickByArray(object, baseDifference(keysIn(object), props));
8933 }
8934 var predicate = bindCallback(props[0], props[1], 3);
8935 return pickByCallback(object, function (value, key, object) {
8936 return !predicate(value, key, object);
8937 });
8938 });
8939 /**
8940 * Creates a two dimensional array of the key-value pairs for `object`,
8941 * e.g. `[[key1, value1], [key2, value2]]`.
8942 *
8943 * @static
8944 * @memberOf _
8945 * @category Object
8946 * @param {Object} object The object to query.
8947 * @returns {Array} Returns the new array of key-value pairs.
8948 * @example
8949 *
8950 * _.pairs({ 'barney': 36, 'fred': 40 });
8951 * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
8952 */
8953 function pairs(object) {
8954 object = toObject(object);
8955 var index = -1, props = keys(object), length = props.length, result = Array(length);
8956 while (++index < length) {
8957 var key = props[index];
8958 result[index] = [
8959 key,
8960 object[key]
8961 ];
8962 }
8963 return result;
8964 }
8965 /**
8966 * Creates an object composed of the picked `object` properties. Property
8967 * names may be specified as individual arguments or as arrays of property
8968 * names. If `predicate` is provided it's invoked for each property of `object`
8969 * picking the properties `predicate` returns truthy for. The predicate is
8970 * bound to `thisArg` and invoked with three arguments: (value, key, object).
8971 *
8972 * @static
8973 * @memberOf _
8974 * @category Object
8975 * @param {Object} object The source object.
8976 * @param {Function|...(string|string[])} [predicate] The function invoked per
8977 * iteration or property names to pick, specified as individual property
8978 * names or arrays of property names.
8979 * @param {*} [thisArg] The `this` binding of `predicate`.
8980 * @returns {Object} Returns the new object.
8981 * @example
8982 *
8983 * var object = { 'user': 'fred', 'age': 40 };
8984 *
8985 * _.pick(object, 'user');
8986 * // => { 'user': 'fred' }
8987 *
8988 * _.pick(object, _.isString);
8989 * // => { 'user': 'fred' }
8990 */
8991 var pick = restParam(function (object, props) {
8992 if (object == null) {
8993 return {};
8994 }
8995 return typeof props[0] == 'function' ? pickByCallback(object, bindCallback(props[0], props[1], 3)) : pickByArray(object, baseFlatten(props));
8996 });
8997 /**
8998 * This method is like `_.get` except that if the resolved value is a function
8999 * it's invoked with the `this` binding of its parent object and its result
9000 * is returned.
9001 *
9002 * @static
9003 * @memberOf _
9004 * @category Object
9005 * @param {Object} object The object to query.
9006 * @param {Array|string} path The path of the property to resolve.
9007 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9008 * @returns {*} Returns the resolved value.
9009 * @example
9010 *
9011 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
9012 *
9013 * _.result(object, 'a[0].b.c1');
9014 * // => 3
9015 *
9016 * _.result(object, 'a[0].b.c2');
9017 * // => 4
9018 *
9019 * _.result(object, 'a.b.c', 'default');
9020 * // => 'default'
9021 *
9022 * _.result(object, 'a.b.c', _.constant('default'));
9023 * // => 'default'
9024 */
9025 function result(object, path, defaultValue) {
9026 var result = object == null ? undefined : object[path];
9027 if (result === undefined) {
9028 if (object != null && !isKey(path, object)) {
9029 path = toPath(path);
9030 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9031 result = object == null ? undefined : object[last(path)];
9032 }
9033 result = result === undefined ? defaultValue : result;
9034 }
9035 return isFunction(result) ? result.call(object) : result;
9036 }
9037 /**
9038 * Sets the property value of `path` on `object`. If a portion of `path`
9039 * does not exist it's created.
9040 *
9041 * @static
9042 * @memberOf _
9043 * @category Object
9044 * @param {Object} object The object to augment.
9045 * @param {Array|string} path The path of the property to set.
9046 * @param {*} value The value to set.
9047 * @returns {Object} Returns `object`.
9048 * @example
9049 *
9050 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9051 *
9052 * _.set(object, 'a[0].b.c', 4);
9053 * console.log(object.a[0].b.c);
9054 * // => 4
9055 *
9056 * _.set(object, 'x[0].y.z', 5);
9057 * console.log(object.x[0].y.z);
9058 * // => 5
9059 */
9060 function set(object, path, value) {
9061 if (object == null) {
9062 return object;
9063 }
9064 var pathKey = path + '';
9065 path = object[pathKey] != null || isKey(path, object) ? [pathKey] : toPath(path);
9066 var index = -1, length = path.length, lastIndex = length - 1, nested = object;
9067 while (nested != null && ++index < length) {
9068 var key = path[index];
9069 if (isObject(nested)) {
9070 if (index == lastIndex) {
9071 nested[key] = value;
9072 } else if (nested[key] == null) {
9073 nested[key] = isIndex(path[index + 1]) ? [] : {};
9074 }
9075 }
9076 nested = nested[key];
9077 }
9078 return object;
9079 }
9080 /**
9081 * An alternative to `_.reduce`; this method transforms `object` to a new
9082 * `accumulator` object which is the result of running each of its own enumerable
9083 * properties through `iteratee`, with each invocation potentially mutating
9084 * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
9085 * with four arguments: (accumulator, value, key, object). Iteratee functions
9086 * may exit iteration early by explicitly returning `false`.
9087 *
9088 * @static
9089 * @memberOf _
9090 * @category Object
9091 * @param {Array|Object} object The object to iterate over.
9092 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9093 * @param {*} [accumulator] The custom accumulator value.
9094 * @param {*} [thisArg] The `this` binding of `iteratee`.
9095 * @returns {*} Returns the accumulated value.
9096 * @example
9097 *
9098 * _.transform([2, 3, 4], function(result, n) {
9099 * result.push(n *= n);
9100 * return n % 2 == 0;
9101 * });
9102 * // => [4, 9]
9103 *
9104 * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
9105 * result[key] = n * 3;
9106 * });
9107 * // => { 'a': 3, 'b': 6 }
9108 */
9109 function transform(object, iteratee, accumulator, thisArg) {
9110 var isArr = isArray(object) || isTypedArray(object);
9111 iteratee = getCallback(iteratee, thisArg, 4);
9112 if (accumulator == null) {
9113 if (isArr || isObject(object)) {
9114 var Ctor = object.constructor;
9115 if (isArr) {
9116 accumulator = isArray(object) ? new Ctor() : [];
9117 } else {
9118 accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
9119 }
9120 } else {
9121 accumulator = {};
9122 }
9123 }
9124 (isArr ? arrayEach : baseForOwn)(object, function (value, index, object) {
9125 return iteratee(accumulator, value, index, object);
9126 });
9127 return accumulator;
9128 }
9129 /**
9130 * Creates an array of the own enumerable property values of `object`.
9131 *
9132 * **Note:** Non-object values are coerced to objects.
9133 *
9134 * @static
9135 * @memberOf _
9136 * @category Object
9137 * @param {Object} object The object to query.
9138 * @returns {Array} Returns the array of property values.
9139 * @example
9140 *
9141 * function Foo() {
9142 * this.a = 1;
9143 * this.b = 2;
9144 * }
9145 *
9146 * Foo.prototype.c = 3;
9147 *
9148 * _.values(new Foo);
9149 * // => [1, 2] (iteration order is not guaranteed)
9150 *
9151 * _.values('hi');
9152 * // => ['h', 'i']
9153 */
9154 function values(object) {
9155 return baseValues(object, keys(object));
9156 }
9157 /**
9158 * Creates an array of the own and inherited enumerable property values
9159 * of `object`.
9160 *
9161 * **Note:** Non-object values are coerced to objects.
9162 *
9163 * @static
9164 * @memberOf _
9165 * @category Object
9166 * @param {Object} object The object to query.
9167 * @returns {Array} Returns the array of property values.
9168 * @example
9169 *
9170 * function Foo() {
9171 * this.a = 1;
9172 * this.b = 2;
9173 * }
9174 *
9175 * Foo.prototype.c = 3;
9176 *
9177 * _.valuesIn(new Foo);
9178 * // => [1, 2, 3] (iteration order is not guaranteed)
9179 */
9180 function valuesIn(object) {
9181 return baseValues(object, keysIn(object));
9182 }
9183 /*------------------------------------------------------------------------*/
9184 /**
9185 * Checks if `n` is between `start` and up to but not including, `end`. If
9186 * `end` is not specified it's set to `start` with `start` then set to `0`.
9187 *
9188 * @static
9189 * @memberOf _
9190 * @category Number
9191 * @param {number} n The number to check.
9192 * @param {number} [start=0] The start of the range.
9193 * @param {number} end The end of the range.
9194 * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
9195 * @example
9196 *
9197 * _.inRange(3, 2, 4);
9198 * // => true
9199 *
9200 * _.inRange(4, 8);
9201 * // => true
9202 *
9203 * _.inRange(4, 2);
9204 * // => false
9205 *
9206 * _.inRange(2, 2);
9207 * // => false
9208 *
9209 * _.inRange(1.2, 2);
9210 * // => true
9211 *
9212 * _.inRange(5.2, 4);
9213 * // => false
9214 */
9215 function inRange(value, start, end) {
9216 start = +start || 0;
9217 if (end === undefined) {
9218 end = start;
9219 start = 0;
9220 } else {
9221 end = +end || 0;
9222 }
9223 return value >= nativeMin(start, end) && value < nativeMax(start, end);
9224 }
9225 /**
9226 * Produces a random number between `min` and `max` (inclusive). If only one
9227 * argument is provided a number between `0` and the given number is returned.
9228 * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
9229 * number is returned instead of an integer.
9230 *
9231 * @static
9232 * @memberOf _
9233 * @category Number
9234 * @param {number} [min=0] The minimum possible value.
9235 * @param {number} [max=1] The maximum possible value.
9236 * @param {boolean} [floating] Specify returning a floating-point number.
9237 * @returns {number} Returns the random number.
9238 * @example
9239 *
9240 * _.random(0, 5);
9241 * // => an integer between 0 and 5
9242 *
9243 * _.random(5);
9244 * // => also an integer between 0 and 5
9245 *
9246 * _.random(5, true);
9247 * // => a floating-point number between 0 and 5
9248 *
9249 * _.random(1.2, 5.2);
9250 * // => a floating-point number between 1.2 and 5.2
9251 */
9252 function random(min, max, floating) {
9253 if (floating && isIterateeCall(min, max, floating)) {
9254 max = floating = undefined;
9255 }
9256 var noMin = min == null, noMax = max == null;
9257 if (floating == null) {
9258 if (noMax && typeof min == 'boolean') {
9259 floating = min;
9260 min = 1;
9261 } else if (typeof max == 'boolean') {
9262 floating = max;
9263 noMax = true;
9264 }
9265 }
9266 if (noMin && noMax) {
9267 max = 1;
9268 noMax = false;
9269 }
9270 min = +min || 0;
9271 if (noMax) {
9272 max = min;
9273 min = 0;
9274 } else {
9275 max = +max || 0;
9276 }
9277 if (floating || min % 1 || max % 1) {
9278 var rand = nativeRandom();
9279 return nativeMin(min + rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1))), max);
9280 }
9281 return baseRandom(min, max);
9282 }
9283 /*------------------------------------------------------------------------*/
9284 /**
9285 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
9286 *
9287 * @static
9288 * @memberOf _
9289 * @category String
9290 * @param {string} [string=''] The string to convert.
9291 * @returns {string} Returns the camel cased string.
9292 * @example
9293 *
9294 * _.camelCase('Foo Bar');
9295 * // => 'fooBar'
9296 *
9297 * _.camelCase('--foo-bar');
9298 * // => 'fooBar'
9299 *
9300 * _.camelCase('__foo_bar__');
9301 * // => 'fooBar'
9302 */
9303 var camelCase = createCompounder(function (result, word, index) {
9304 word = word.toLowerCase();
9305 return result + (index ? word.charAt(0).toUpperCase() + word.slice(1) : word);
9306 });
9307 /**
9308 * Capitalizes the first character of `string`.
9309 *
9310 * @static
9311 * @memberOf _
9312 * @category String
9313 * @param {string} [string=''] The string to capitalize.
9314 * @returns {string} Returns the capitalized string.
9315 * @example
9316 *
9317 * _.capitalize('fred');
9318 * // => 'Fred'
9319 */
9320 function capitalize(string) {
9321 string = baseToString(string);
9322 return string && string.charAt(0).toUpperCase() + string.slice(1);
9323 }
9324 /**
9325 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
9326 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
9327 *
9328 * @static
9329 * @memberOf _
9330 * @category String
9331 * @param {string} [string=''] The string to deburr.
9332 * @returns {string} Returns the deburred string.
9333 * @example
9334 *
9335 * _.deburr('déjà vu');
9336 * // => 'deja vu'
9337 */
9338 function deburr(string) {
9339 string = baseToString(string);
9340 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
9341 }
9342 /**
9343 * Checks if `string` ends with the given target string.
9344 *
9345 * @static
9346 * @memberOf _
9347 * @category String
9348 * @param {string} [string=''] The string to search.
9349 * @param {string} [target] The string to search for.
9350 * @param {number} [position=string.length] The position to search from.
9351 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
9352 * @example
9353 *
9354 * _.endsWith('abc', 'c');
9355 * // => true
9356 *
9357 * _.endsWith('abc', 'b');
9358 * // => false
9359 *
9360 * _.endsWith('abc', 'b', 2);
9361 * // => true
9362 */
9363 function endsWith(string, target, position) {
9364 string = baseToString(string);
9365 target = target + '';
9366 var length = string.length;
9367 position = position === undefined ? length : nativeMin(position < 0 ? 0 : +position || 0, length);
9368 position -= target.length;
9369 return position >= 0 && string.indexOf(target, position) == position;
9370 }
9371 /**
9372 * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
9373 * their corresponding HTML entities.
9374 *
9375 * **Note:** No other characters are escaped. To escape additional characters
9376 * use a third-party library like [_he_](https://mths.be/he).
9377 *
9378 * Though the ">" character is escaped for symmetry, characters like
9379 * ">" and "/" don't need escaping in HTML and have no special meaning
9380 * unless they're part of a tag or unquoted attribute value.
9381 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
9382 * (under "semi-related fun fact") for more details.
9383 *
9384 * Backticks are escaped because in Internet Explorer < 9, they can break out
9385 * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
9386 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
9387 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
9388 * for more details.
9389 *
9390 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
9391 * to reduce XSS vectors.
9392 *
9393 * @static
9394 * @memberOf _
9395 * @category String
9396 * @param {string} [string=''] The string to escape.
9397 * @returns {string} Returns the escaped string.
9398 * @example
9399 *
9400 * _.escape('fred, barney, & pebbles');
9401 * // => 'fred, barney, &amp; pebbles'
9402 */
9403 function escape(string) {
9404 // Reset `lastIndex` because in IE < 9 `String#replace` does not.
9405 string = baseToString(string);
9406 return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, escapeHtmlChar) : string;
9407 }
9408 /**
9409 * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
9410 * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
9411 *
9412 * @static
9413 * @memberOf _
9414 * @category String
9415 * @param {string} [string=''] The string to escape.
9416 * @returns {string} Returns the escaped string.
9417 * @example
9418 *
9419 * _.escapeRegExp('[lodash](https://lodash.com/)');
9420 * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
9421 */
9422 function escapeRegExp(string) {
9423 string = baseToString(string);
9424 return string && reHasRegExpChars.test(string) ? string.replace(reRegExpChars, escapeRegExpChar) : string || '(?:)';
9425 }
9426 /**
9427 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
9428 *
9429 * @static
9430 * @memberOf _
9431 * @category String
9432 * @param {string} [string=''] The string to convert.
9433 * @returns {string} Returns the kebab cased string.
9434 * @example
9435 *
9436 * _.kebabCase('Foo Bar');
9437 * // => 'foo-bar'
9438 *
9439 * _.kebabCase('fooBar');
9440 * // => 'foo-bar'
9441 *
9442 * _.kebabCase('__foo_bar__');
9443 * // => 'foo-bar'
9444 */
9445 var kebabCase = createCompounder(function (result, word, index) {
9446 return result + (index ? '-' : '') + word.toLowerCase();
9447 });
9448 /**
9449 * Pads `string` on the left and right sides if it's shorter than `length`.
9450 * Padding characters are truncated if they can't be evenly divided by `length`.
9451 *
9452 * @static
9453 * @memberOf _
9454 * @category String
9455 * @param {string} [string=''] The string to pad.
9456 * @param {number} [length=0] The padding length.
9457 * @param {string} [chars=' '] The string used as padding.
9458 * @returns {string} Returns the padded string.
9459 * @example
9460 *
9461 * _.pad('abc', 8);
9462 * // => ' abc '
9463 *
9464 * _.pad('abc', 8, '_-');
9465 * // => '_-abc_-_'
9466 *
9467 * _.pad('abc', 3);
9468 * // => 'abc'
9469 */
9470 function pad(string, length, chars) {
9471 string = baseToString(string);
9472 length = +length;
9473 var strLength = string.length;
9474 if (strLength >= length || !nativeIsFinite(length)) {
9475 return string;
9476 }
9477 var mid = (length - strLength) / 2, leftLength = nativeFloor(mid), rightLength = nativeCeil(mid);
9478 chars = createPadding('', rightLength, chars);
9479 return chars.slice(0, leftLength) + string + chars;
9480 }
9481 /**
9482 * Pads `string` on the left side if it's shorter than `length`. Padding
9483 * characters are truncated if they exceed `length`.
9484 *
9485 * @static
9486 * @memberOf _
9487 * @category String
9488 * @param {string} [string=''] The string to pad.
9489 * @param {number} [length=0] The padding length.
9490 * @param {string} [chars=' '] The string used as padding.
9491 * @returns {string} Returns the padded string.
9492 * @example
9493 *
9494 * _.padLeft('abc', 6);
9495 * // => ' abc'
9496 *
9497 * _.padLeft('abc', 6, '_-');
9498 * // => '_-_abc'
9499 *
9500 * _.padLeft('abc', 3);
9501 * // => 'abc'
9502 */
9503 var padLeft = createPadDir();
9504 /**
9505 * Pads `string` on the right side if it's shorter than `length`. Padding
9506 * characters are truncated if they exceed `length`.
9507 *
9508 * @static
9509 * @memberOf _
9510 * @category String
9511 * @param {string} [string=''] The string to pad.
9512 * @param {number} [length=0] The padding length.
9513 * @param {string} [chars=' '] The string used as padding.
9514 * @returns {string} Returns the padded string.
9515 * @example
9516 *
9517 * _.padRight('abc', 6);
9518 * // => 'abc '
9519 *
9520 * _.padRight('abc', 6, '_-');
9521 * // => 'abc_-_'
9522 *
9523 * _.padRight('abc', 3);
9524 * // => 'abc'
9525 */
9526 var padRight = createPadDir(true);
9527 /**
9528 * Converts `string` to an integer of the specified radix. If `radix` is
9529 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
9530 * in which case a `radix` of `16` is used.
9531 *
9532 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
9533 * of `parseInt`.
9534 *
9535 * @static
9536 * @memberOf _
9537 * @category String
9538 * @param {string} string The string to convert.
9539 * @param {number} [radix] The radix to interpret `value` by.
9540 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9541 * @returns {number} Returns the converted integer.
9542 * @example
9543 *
9544 * _.parseInt('08');
9545 * // => 8
9546 *
9547 * _.map(['6', '08', '10'], _.parseInt);
9548 * // => [6, 8, 10]
9549 */
9550 function parseInt(string, radix, guard) {
9551 // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
9552 // Chrome fails to trim leading <BOM> whitespace characters.
9553 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
9554 if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
9555 radix = 0;
9556 } else if (radix) {
9557 radix = +radix;
9558 }
9559 string = trim(string);
9560 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
9561 }
9562 /**
9563 * Repeats the given string `n` times.
9564 *
9565 * @static
9566 * @memberOf _
9567 * @category String
9568 * @param {string} [string=''] The string to repeat.
9569 * @param {number} [n=0] The number of times to repeat the string.
9570 * @returns {string} Returns the repeated string.
9571 * @example
9572 *
9573 * _.repeat('*', 3);
9574 * // => '***'
9575 *
9576 * _.repeat('abc', 2);
9577 * // => 'abcabc'
9578 *
9579 * _.repeat('abc', 0);
9580 * // => ''
9581 */
9582 function repeat(string, n) {
9583 var result = '';
9584 string = baseToString(string);
9585 n = +n;
9586 if (n < 1 || !string || !nativeIsFinite(n)) {
9587 return result;
9588 }
9589 // Leverage the exponentiation by squaring algorithm for a faster repeat.
9590 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
9591 do {
9592 if (n % 2) {
9593 result += string;
9594 }
9595 n = nativeFloor(n / 2);
9596 string += string;
9597 } while (n);
9598 return result;
9599 }
9600 /**
9601 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
9602 *
9603 * @static
9604 * @memberOf _
9605 * @category String
9606 * @param {string} [string=''] The string to convert.
9607 * @returns {string} Returns the snake cased string.
9608 * @example
9609 *
9610 * _.snakeCase('Foo Bar');
9611 * // => 'foo_bar'
9612 *
9613 * _.snakeCase('fooBar');
9614 * // => 'foo_bar'
9615 *
9616 * _.snakeCase('--foo-bar');
9617 * // => 'foo_bar'
9618 */
9619 var snakeCase = createCompounder(function (result, word, index) {
9620 return result + (index ? '_' : '') + word.toLowerCase();
9621 });
9622 /**
9623 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
9624 *
9625 * @static
9626 * @memberOf _
9627 * @category String
9628 * @param {string} [string=''] The string to convert.
9629 * @returns {string} Returns the start cased string.
9630 * @example
9631 *
9632 * _.startCase('--foo-bar');
9633 * // => 'Foo Bar'
9634 *
9635 * _.startCase('fooBar');
9636 * // => 'Foo Bar'
9637 *
9638 * _.startCase('__foo_bar__');
9639 * // => 'Foo Bar'
9640 */
9641 var startCase = createCompounder(function (result, word, index) {
9642 return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
9643 });
9644 /**
9645 * Checks if `string` starts with the given target string.
9646 *
9647 * @static
9648 * @memberOf _
9649 * @category String
9650 * @param {string} [string=''] The string to search.
9651 * @param {string} [target] The string to search for.
9652 * @param {number} [position=0] The position to search from.
9653 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
9654 * @example
9655 *
9656 * _.startsWith('abc', 'a');
9657 * // => true
9658 *
9659 * _.startsWith('abc', 'b');
9660 * // => false
9661 *
9662 * _.startsWith('abc', 'b', 1);
9663 * // => true
9664 */
9665 function startsWith(string, target, position) {
9666 string = baseToString(string);
9667 position = position == null ? 0 : nativeMin(position < 0 ? 0 : +position || 0, string.length);
9668 return string.lastIndexOf(target, position) == position;
9669 }
9670 /**
9671 * Creates a compiled template function that can interpolate data properties
9672 * in "interpolate" delimiters, HTML-escape interpolated data properties in
9673 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
9674 * properties may be accessed as free variables in the template. If a setting
9675 * object is provided it takes precedence over `_.templateSettings` values.
9676 *
9677 * **Note:** In the development build `_.template` utilizes
9678 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
9679 * for easier debugging.
9680 *
9681 * For more information on precompiling templates see
9682 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
9683 *
9684 * For more information on Chrome extension sandboxes see
9685 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
9686 *
9687 * @static
9688 * @memberOf _
9689 * @category String
9690 * @param {string} [string=''] The template string.
9691 * @param {Object} [options] The options object.
9692 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
9693 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
9694 * @param {Object} [options.imports] An object to import into the template as free variables.
9695 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
9696 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
9697 * @param {string} [options.variable] The data object variable name.
9698 * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
9699 * @returns {Function} Returns the compiled template function.
9700 * @example
9701 *
9702 * // using the "interpolate" delimiter to create a compiled template
9703 * var compiled = _.template('hello <%= user %>!');
9704 * compiled({ 'user': 'fred' });
9705 * // => 'hello fred!'
9706 *
9707 * // using the HTML "escape" delimiter to escape data property values
9708 * var compiled = _.template('<b><%- value %></b>');
9709 * compiled({ 'value': '<script>' });
9710 * // => '<b>&lt;script&gt;</b>'
9711 *
9712 * // using the "evaluate" delimiter to execute JavaScript and generate HTML
9713 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
9714 * compiled({ 'users': ['fred', 'barney'] });
9715 * // => '<li>fred</li><li>barney</li>'
9716 *
9717 * // using the internal `print` function in "evaluate" delimiters
9718 * var compiled = _.template('<% print("hello " + user); %>!');
9719 * compiled({ 'user': 'barney' });
9720 * // => 'hello barney!'
9721 *
9722 * // using the ES delimiter as an alternative to the default "interpolate" delimiter
9723 * var compiled = _.template('hello ${ user }!');
9724 * compiled({ 'user': 'pebbles' });
9725 * // => 'hello pebbles!'
9726 *
9727 * // using custom template delimiters
9728 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
9729 * var compiled = _.template('hello {{ user }}!');
9730 * compiled({ 'user': 'mustache' });
9731 * // => 'hello mustache!'
9732 *
9733 * // using backslashes to treat delimiters as plain text
9734 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
9735 * compiled({ 'value': 'ignored' });
9736 * // => '<%- value %>'
9737 *
9738 * // using the `imports` option to import `jQuery` as `jq`
9739 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
9740 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
9741 * compiled({ 'users': ['fred', 'barney'] });
9742 * // => '<li>fred</li><li>barney</li>'
9743 *
9744 * // using the `sourceURL` option to specify a custom sourceURL for the template
9745 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
9746 * compiled(data);
9747 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
9748 *
9749 * // using the `variable` option to ensure a with-statement isn't used in the compiled template
9750 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
9751 * compiled.source;
9752 * // => function(data) {
9753 * // var __t, __p = '';
9754 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
9755 * // return __p;
9756 * // }
9757 *
9758 * // using the `source` property to inline compiled templates for meaningful
9759 * // line numbers in error messages and a stack trace
9760 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
9761 * var JST = {\
9762 * "main": ' + _.template(mainText).source + '\
9763 * };\
9764 * ');
9765 */
9766 function template(string, options, otherOptions) {
9767 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
9768 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
9769 var settings = lodash.templateSettings;
9770 if (otherOptions && isIterateeCall(string, options, otherOptions)) {
9771 options = otherOptions = undefined;
9772 }
9773 string = baseToString(string);
9774 options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
9775 var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
9776 var isEscaping, isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = '__p += \'';
9777 // Compile the regexp to match each delimiter.
9778 var reDelimiters = RegExp((options.escape || reNoMatch).source + '|' + interpolate.source + '|' + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + (options.evaluate || reNoMatch).source + '|$', 'g');
9779 // Use a sourceURL for easier debugging.
9780 var sourceURL = '//# sourceURL=' + ('sourceURL' in options ? options.sourceURL : 'lodash.templateSources[' + ++templateCounter + ']') + '\n';
9781 string.replace(reDelimiters, function (match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
9782 interpolateValue || (interpolateValue = esTemplateValue);
9783 // Escape characters that can't be included in string literals.
9784 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
9785 // Replace delimiters with snippets.
9786 if (escapeValue) {
9787 isEscaping = true;
9788 source += '\' +\n__e(' + escapeValue + ') +\n\'';
9789 }
9790 if (evaluateValue) {
9791 isEvaluating = true;
9792 source += '\';\n' + evaluateValue + ';\n__p += \'';
9793 }
9794 if (interpolateValue) {
9795 source += '\' +\n((__t = (' + interpolateValue + ')) == null ? \'\' : __t) +\n\'';
9796 }
9797 index = offset + match.length;
9798 // The JS engine embedded in Adobe products requires returning the `match`
9799 // string in order to produce the correct `offset` value.
9800 return match;
9801 });
9802 source += '\';\n';
9803 // If `variable` is not specified wrap a with-statement around the generated
9804 // code to add the data object to the top of the scope chain.
9805 var variable = options.variable;
9806 if (!variable) {
9807 source = 'with (obj) {\n' + source + '\n}\n';
9808 }
9809 // Cleanup code by stripping empty strings.
9810 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source).replace(reEmptyStringMiddle, '$1').replace(reEmptyStringTrailing, '$1;');
9811 // Frame code as the function body.
9812 source = 'function(' + (variable || 'obj') + ') {\n' + (variable ? '' : 'obj || (obj = {});\n') + 'var __t, __p = \'\'' + (isEscaping ? ', __e = _.escape' : '') + (isEvaluating ? ', __j = Array.prototype.join;\n' + 'function print() { __p += __j.call(arguments, \'\') }\n' : ';\n') + source + 'return __p\n}';
9813 var result = attempt(function () {
9814 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
9815 });
9816 // Provide the compiled function's source by its `toString` method or
9817 // the `source` property as a convenience for inlining compiled templates.
9818 result.source = source;
9819 if (isError(result)) {
9820 throw result;
9821 }
9822 return result;
9823 }
9824 /**
9825 * Removes leading and trailing whitespace or specified characters from `string`.
9826 *
9827 * @static
9828 * @memberOf _
9829 * @category String
9830 * @param {string} [string=''] The string to trim.
9831 * @param {string} [chars=whitespace] The characters to trim.
9832 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9833 * @returns {string} Returns the trimmed string.
9834 * @example
9835 *
9836 * _.trim(' abc ');
9837 * // => 'abc'
9838 *
9839 * _.trim('-_-abc-_-', '_-');
9840 * // => 'abc'
9841 *
9842 * _.map([' foo ', ' bar '], _.trim);
9843 * // => ['foo', 'bar']
9844 */
9845 function trim(string, chars, guard) {
9846 var value = string;
9847 string = baseToString(string);
9848 if (!string) {
9849 return string;
9850 }
9851 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
9852 return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
9853 }
9854 chars = chars + '';
9855 return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
9856 }
9857 /**
9858 * Removes leading whitespace or specified characters from `string`.
9859 *
9860 * @static
9861 * @memberOf _
9862 * @category String
9863 * @param {string} [string=''] The string to trim.
9864 * @param {string} [chars=whitespace] The characters to trim.
9865 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9866 * @returns {string} Returns the trimmed string.
9867 * @example
9868 *
9869 * _.trimLeft(' abc ');
9870 * // => 'abc '
9871 *
9872 * _.trimLeft('-_-abc-_-', '_-');
9873 * // => 'abc-_-'
9874 */
9875 function trimLeft(string, chars, guard) {
9876 var value = string;
9877 string = baseToString(string);
9878 if (!string) {
9879 return string;
9880 }
9881 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
9882 return string.slice(trimmedLeftIndex(string));
9883 }
9884 return string.slice(charsLeftIndex(string, chars + ''));
9885 }
9886 /**
9887 * Removes trailing whitespace or specified characters from `string`.
9888 *
9889 * @static
9890 * @memberOf _
9891 * @category String
9892 * @param {string} [string=''] The string to trim.
9893 * @param {string} [chars=whitespace] The characters to trim.
9894 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9895 * @returns {string} Returns the trimmed string.
9896 * @example
9897 *
9898 * _.trimRight(' abc ');
9899 * // => ' abc'
9900 *
9901 * _.trimRight('-_-abc-_-', '_-');
9902 * // => '-_-abc'
9903 */
9904 function trimRight(string, chars, guard) {
9905 var value = string;
9906 string = baseToString(string);
9907 if (!string) {
9908 return string;
9909 }
9910 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
9911 return string.slice(0, trimmedRightIndex(string) + 1);
9912 }
9913 return string.slice(0, charsRightIndex(string, chars + '') + 1);
9914 }
9915 /**
9916 * Truncates `string` if it's longer than the given maximum string length.
9917 * The last characters of the truncated string are replaced with the omission
9918 * string which defaults to "...".
9919 *
9920 * @static
9921 * @memberOf _
9922 * @category String
9923 * @param {string} [string=''] The string to truncate.
9924 * @param {Object|number} [options] The options object or maximum string length.
9925 * @param {number} [options.length=30] The maximum string length.
9926 * @param {string} [options.omission='...'] The string to indicate text is omitted.
9927 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
9928 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9929 * @returns {string} Returns the truncated string.
9930 * @example
9931 *
9932 * _.trunc('hi-diddly-ho there, neighborino');
9933 * // => 'hi-diddly-ho there, neighbo...'
9934 *
9935 * _.trunc('hi-diddly-ho there, neighborino', 24);
9936 * // => 'hi-diddly-ho there, n...'
9937 *
9938 * _.trunc('hi-diddly-ho there, neighborino', {
9939 * 'length': 24,
9940 * 'separator': ' '
9941 * });
9942 * // => 'hi-diddly-ho there,...'
9943 *
9944 * _.trunc('hi-diddly-ho there, neighborino', {
9945 * 'length': 24,
9946 * 'separator': /,? +/
9947 * });
9948 * // => 'hi-diddly-ho there...'
9949 *
9950 * _.trunc('hi-diddly-ho there, neighborino', {
9951 * 'omission': ' [...]'
9952 * });
9953 * // => 'hi-diddly-ho there, neig [...]'
9954 */
9955 function trunc(string, options, guard) {
9956 if (guard && isIterateeCall(string, options, guard)) {
9957 options = undefined;
9958 }
9959 var length = DEFAULT_TRUNC_LENGTH, omission = DEFAULT_TRUNC_OMISSION;
9960 if (options != null) {
9961 if (isObject(options)) {
9962 var separator = 'separator' in options ? options.separator : separator;
9963 length = 'length' in options ? +options.length || 0 : length;
9964 omission = 'omission' in options ? baseToString(options.omission) : omission;
9965 } else {
9966 length = +options || 0;
9967 }
9968 }
9969 string = baseToString(string);
9970 if (length >= string.length) {
9971 return string;
9972 }
9973 var end = length - omission.length;
9974 if (end < 1) {
9975 return omission;
9976 }
9977 var result = string.slice(0, end);
9978 if (separator == null) {
9979 return result + omission;
9980 }
9981 if (isRegExp(separator)) {
9982 if (string.slice(end).search(separator)) {
9983 var match, newEnd, substring = string.slice(0, end);
9984 if (!separator.global) {
9985 separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
9986 }
9987 separator.lastIndex = 0;
9988 while (match = separator.exec(substring)) {
9989 newEnd = match.index;
9990 }
9991 result = result.slice(0, newEnd == null ? end : newEnd);
9992 }
9993 } else if (string.indexOf(separator, end) != end) {
9994 var index = result.lastIndexOf(separator);
9995 if (index > -1) {
9996 result = result.slice(0, index);
9997 }
9998 }
9999 return result + omission;
10000 }
10001 /**
10002 * The inverse of `_.escape`; this method converts the HTML entities
10003 * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
10004 * corresponding characters.
10005 *
10006 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
10007 * entities use a third-party library like [_he_](https://mths.be/he).
10008 *
10009 * @static
10010 * @memberOf _
10011 * @category String
10012 * @param {string} [string=''] The string to unescape.
10013 * @returns {string} Returns the unescaped string.
10014 * @example
10015 *
10016 * _.unescape('fred, barney, &amp; pebbles');
10017 * // => 'fred, barney, & pebbles'
10018 */
10019 function unescape(string) {
10020 string = baseToString(string);
10021 return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string;
10022 }
10023 /**
10024 * Splits `string` into an array of its words.
10025 *
10026 * @static
10027 * @memberOf _
10028 * @category String
10029 * @param {string} [string=''] The string to inspect.
10030 * @param {RegExp|string} [pattern] The pattern to match words.
10031 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10032 * @returns {Array} Returns the words of `string`.
10033 * @example
10034 *
10035 * _.words('fred, barney, & pebbles');
10036 * // => ['fred', 'barney', 'pebbles']
10037 *
10038 * _.words('fred, barney, & pebbles', /[^, ]+/g);
10039 * // => ['fred', 'barney', '&', 'pebbles']
10040 */
10041 function words(string, pattern, guard) {
10042 if (guard && isIterateeCall(string, pattern, guard)) {
10043 pattern = undefined;
10044 }
10045 string = baseToString(string);
10046 return string.match(pattern || reWords) || [];
10047 }
10048 /*------------------------------------------------------------------------*/
10049 /**
10050 * Attempts to invoke `func`, returning either the result or the caught error
10051 * object. Any additional arguments are provided to `func` when it's invoked.
10052 *
10053 * @static
10054 * @memberOf _
10055 * @category Utility
10056 * @param {Function} func The function to attempt.
10057 * @returns {*} Returns the `func` result or error object.
10058 * @example
10059 *
10060 * // avoid throwing errors for invalid selectors
10061 * var elements = _.attempt(function(selector) {
10062 * return document.querySelectorAll(selector);
10063 * }, '>_>');
10064 *
10065 * if (_.isError(elements)) {
10066 * elements = [];
10067 * }
10068 */
10069 var attempt = restParam(function (func, args) {
10070 try {
10071 return func.apply(undefined, args);
10072 } catch (e) {
10073 return isError(e) ? e : new Error(e);
10074 }
10075 });
10076 /**
10077 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10078 * and arguments of the created function. If `func` is a property name the
10079 * created callback returns the property value for a given element. If `func`
10080 * is an object the created callback returns `true` for elements that contain
10081 * the equivalent object properties, otherwise it returns `false`.
10082 *
10083 * @static
10084 * @memberOf _
10085 * @alias iteratee
10086 * @category Utility
10087 * @param {*} [func=_.identity] The value to convert to a callback.
10088 * @param {*} [thisArg] The `this` binding of `func`.
10089 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10090 * @returns {Function} Returns the callback.
10091 * @example
10092 *
10093 * var users = [
10094 * { 'user': 'barney', 'age': 36 },
10095 * { 'user': 'fred', 'age': 40 }
10096 * ];
10097 *
10098 * // wrap to create custom callback shorthands
10099 * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
10100 * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
10101 * if (!match) {
10102 * return callback(func, thisArg);
10103 * }
10104 * return function(object) {
10105 * return match[2] == 'gt'
10106 * ? object[match[1]] > match[3]
10107 * : object[match[1]] < match[3];
10108 * };
10109 * });
10110 *
10111 * _.filter(users, 'age__gt36');
10112 * // => [{ 'user': 'fred', 'age': 40 }]
10113 */
10114 function callback(func, thisArg, guard) {
10115 if (guard && isIterateeCall(func, thisArg, guard)) {
10116 thisArg = undefined;
10117 }
10118 return isObjectLike(func) ? matches(func) : baseCallback(func, thisArg);
10119 }
10120 /**
10121 * Creates a function that returns `value`.
10122 *
10123 * @static
10124 * @memberOf _
10125 * @category Utility
10126 * @param {*} value The value to return from the new function.
10127 * @returns {Function} Returns the new function.
10128 * @example
10129 *
10130 * var object = { 'user': 'fred' };
10131 * var getter = _.constant(object);
10132 *
10133 * getter() === object;
10134 * // => true
10135 */
10136 function constant(value) {
10137 return function () {
10138 return value;
10139 };
10140 }
10141 /**
10142 * This method returns the first argument provided to it.
10143 *
10144 * @static
10145 * @memberOf _
10146 * @category Utility
10147 * @param {*} value Any value.
10148 * @returns {*} Returns `value`.
10149 * @example
10150 *
10151 * var object = { 'user': 'fred' };
10152 *
10153 * _.identity(object) === object;
10154 * // => true
10155 */
10156 function identity(value) {
10157 return value;
10158 }
10159 /**
10160 * Creates a function that performs a deep comparison between a given object
10161 * and `source`, returning `true` if the given object has equivalent property
10162 * values, else `false`.
10163 *
10164 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
10165 * numbers, `Object` objects, regexes, and strings. Objects are compared by
10166 * their own, not inherited, enumerable properties. For comparing a single
10167 * own or inherited property value see `_.matchesProperty`.
10168 *
10169 * @static
10170 * @memberOf _
10171 * @category Utility
10172 * @param {Object} source The object of property values to match.
10173 * @returns {Function} Returns the new function.
10174 * @example
10175 *
10176 * var users = [
10177 * { 'user': 'barney', 'age': 36, 'active': true },
10178 * { 'user': 'fred', 'age': 40, 'active': false }
10179 * ];
10180 *
10181 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
10182 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
10183 */
10184 function matches(source) {
10185 return baseMatches(baseClone(source, true));
10186 }
10187 /**
10188 * Creates a function that compares the property value of `path` on a given
10189 * object to `value`.
10190 *
10191 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
10192 * numbers, `Object` objects, regexes, and strings. Objects are compared by
10193 * their own, not inherited, enumerable properties.
10194 *
10195 * @static
10196 * @memberOf _
10197 * @category Utility
10198 * @param {Array|string} path The path of the property to get.
10199 * @param {*} srcValue The value to match.
10200 * @returns {Function} Returns the new function.
10201 * @example
10202 *
10203 * var users = [
10204 * { 'user': 'barney' },
10205 * { 'user': 'fred' }
10206 * ];
10207 *
10208 * _.find(users, _.matchesProperty('user', 'fred'));
10209 * // => { 'user': 'fred' }
10210 */
10211 function matchesProperty(path, srcValue) {
10212 return baseMatchesProperty(path, baseClone(srcValue, true));
10213 }
10214 /**
10215 * Creates a function that invokes the method at `path` on a given object.
10216 * Any additional arguments are provided to the invoked method.
10217 *
10218 * @static
10219 * @memberOf _
10220 * @category Utility
10221 * @param {Array|string} path The path of the method to invoke.
10222 * @param {...*} [args] The arguments to invoke the method with.
10223 * @returns {Function} Returns the new function.
10224 * @example
10225 *
10226 * var objects = [
10227 * { 'a': { 'b': { 'c': _.constant(2) } } },
10228 * { 'a': { 'b': { 'c': _.constant(1) } } }
10229 * ];
10230 *
10231 * _.map(objects, _.method('a.b.c'));
10232 * // => [2, 1]
10233 *
10234 * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
10235 * // => [1, 2]
10236 */
10237 var method = restParam(function (path, args) {
10238 return function (object) {
10239 return invokePath(object, path, args);
10240 };
10241 });
10242 /**
10243 * The opposite of `_.method`; this method creates a function that invokes
10244 * the method at a given path on `object`. Any additional arguments are
10245 * provided to the invoked method.
10246 *
10247 * @static
10248 * @memberOf _
10249 * @category Utility
10250 * @param {Object} object The object to query.
10251 * @param {...*} [args] The arguments to invoke the method with.
10252 * @returns {Function} Returns the new function.
10253 * @example
10254 *
10255 * var array = _.times(3, _.constant),
10256 * object = { 'a': array, 'b': array, 'c': array };
10257 *
10258 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
10259 * // => [2, 0]
10260 *
10261 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
10262 * // => [2, 0]
10263 */
10264 var methodOf = restParam(function (object, args) {
10265 return function (path) {
10266 return invokePath(object, path, args);
10267 };
10268 });
10269 /**
10270 * Adds all own enumerable function properties of a source object to the
10271 * destination object. If `object` is a function then methods are added to
10272 * its prototype as well.
10273 *
10274 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
10275 * avoid conflicts caused by modifying the original.
10276 *
10277 * @static
10278 * @memberOf _
10279 * @category Utility
10280 * @param {Function|Object} [object=lodash] The destination object.
10281 * @param {Object} source The object of functions to add.
10282 * @param {Object} [options] The options object.
10283 * @param {boolean} [options.chain=true] Specify whether the functions added
10284 * are chainable.
10285 * @returns {Function|Object} Returns `object`.
10286 * @example
10287 *
10288 * function vowels(string) {
10289 * return _.filter(string, function(v) {
10290 * return /[aeiou]/i.test(v);
10291 * });
10292 * }
10293 *
10294 * _.mixin({ 'vowels': vowels });
10295 * _.vowels('fred');
10296 * // => ['e']
10297 *
10298 * _('fred').vowels().value();
10299 * // => ['e']
10300 *
10301 * _.mixin({ 'vowels': vowels }, { 'chain': false });
10302 * _('fred').vowels();
10303 * // => ['e']
10304 */
10305 function mixin(object, source, options) {
10306 if (options == null) {
10307 var isObj = isObject(source), props = isObj ? keys(source) : undefined, methodNames = props && props.length ? baseFunctions(source, props) : undefined;
10308 if (!(methodNames ? methodNames.length : isObj)) {
10309 methodNames = false;
10310 options = source;
10311 source = object;
10312 object = this;
10313 }
10314 }
10315 if (!methodNames) {
10316 methodNames = baseFunctions(source, keys(source));
10317 }
10318 var chain = true, index = -1, isFunc = isFunction(object), length = methodNames.length;
10319 if (options === false) {
10320 chain = false;
10321 } else if (isObject(options) && 'chain' in options) {
10322 chain = options.chain;
10323 }
10324 while (++index < length) {
10325 var methodName = methodNames[index], func = source[methodName];
10326 object[methodName] = func;
10327 if (isFunc) {
10328 object.prototype[methodName] = function (func) {
10329 return function () {
10330 var chainAll = this.__chain__;
10331 if (chain || chainAll) {
10332 var result = object(this.__wrapped__), actions = result.__actions__ = arrayCopy(this.__actions__);
10333 actions.push({
10334 'func': func,
10335 'args': arguments,
10336 'thisArg': object
10337 });
10338 result.__chain__ = chainAll;
10339 return result;
10340 }
10341 return func.apply(object, arrayPush([this.value()], arguments));
10342 };
10343 }(func);
10344 }
10345 }
10346 return object;
10347 }
10348 /**
10349 * Reverts the `_` variable to its previous value and returns a reference to
10350 * the `lodash` function.
10351 *
10352 * @static
10353 * @memberOf _
10354 * @category Utility
10355 * @returns {Function} Returns the `lodash` function.
10356 * @example
10357 *
10358 * var lodash = _.noConflict();
10359 */
10360 function noConflict() {
10361 root._ = oldDash;
10362 return this;
10363 }
10364 /**
10365 * A no-operation function that returns `undefined` regardless of the
10366 * arguments it receives.
10367 *
10368 * @static
10369 * @memberOf _
10370 * @category Utility
10371 * @example
10372 *
10373 * var object = { 'user': 'fred' };
10374 *
10375 * _.noop(object) === undefined;
10376 * // => true
10377 */
10378 function noop() {
10379 }
10380 /**
10381 * Creates a function that returns the property value at `path` on a
10382 * given object.
10383 *
10384 * @static
10385 * @memberOf _
10386 * @category Utility
10387 * @param {Array|string} path The path of the property to get.
10388 * @returns {Function} Returns the new function.
10389 * @example
10390 *
10391 * var objects = [
10392 * { 'a': { 'b': { 'c': 2 } } },
10393 * { 'a': { 'b': { 'c': 1 } } }
10394 * ];
10395 *
10396 * _.map(objects, _.property('a.b.c'));
10397 * // => [2, 1]
10398 *
10399 * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
10400 * // => [1, 2]
10401 */
10402 function property(path) {
10403 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
10404 }
10405 /**
10406 * The opposite of `_.property`; this method creates a function that returns
10407 * the property value at a given path on `object`.
10408 *
10409 * @static
10410 * @memberOf _
10411 * @category Utility
10412 * @param {Object} object The object to query.
10413 * @returns {Function} Returns the new function.
10414 * @example
10415 *
10416 * var array = [0, 1, 2],
10417 * object = { 'a': array, 'b': array, 'c': array };
10418 *
10419 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
10420 * // => [2, 0]
10421 *
10422 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
10423 * // => [2, 0]
10424 */
10425 function propertyOf(object) {
10426 return function (path) {
10427 return baseGet(object, toPath(path), path + '');
10428 };
10429 }
10430 /**
10431 * Creates an array of numbers (positive and/or negative) progressing from
10432 * `start` up to, but not including, `end`. If `end` is not specified it's
10433 * set to `start` with `start` then set to `0`. If `end` is less than `start`
10434 * a zero-length range is created unless a negative `step` is specified.
10435 *
10436 * @static
10437 * @memberOf _
10438 * @category Utility
10439 * @param {number} [start=0] The start of the range.
10440 * @param {number} end The end of the range.
10441 * @param {number} [step=1] The value to increment or decrement by.
10442 * @returns {Array} Returns the new array of numbers.
10443 * @example
10444 *
10445 * _.range(4);
10446 * // => [0, 1, 2, 3]
10447 *
10448 * _.range(1, 5);
10449 * // => [1, 2, 3, 4]
10450 *
10451 * _.range(0, 20, 5);
10452 * // => [0, 5, 10, 15]
10453 *
10454 * _.range(0, -4, -1);
10455 * // => [0, -1, -2, -3]
10456 *
10457 * _.range(1, 4, 0);
10458 * // => [1, 1, 1]
10459 *
10460 * _.range(0);
10461 * // => []
10462 */
10463 function range(start, end, step) {
10464 if (step && isIterateeCall(start, end, step)) {
10465 end = step = undefined;
10466 }
10467 start = +start || 0;
10468 step = step == null ? 1 : +step || 0;
10469 if (end == null) {
10470 end = start;
10471 start = 0;
10472 } else {
10473 end = +end || 0;
10474 }
10475 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
10476 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
10477 var index = -1, length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), result = Array(length);
10478 while (++index < length) {
10479 result[index] = start;
10480 start += step;
10481 }
10482 return result;
10483 }
10484 /**
10485 * Invokes the iteratee function `n` times, returning an array of the results
10486 * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
10487 * one argument; (index).
10488 *
10489 * @static
10490 * @memberOf _
10491 * @category Utility
10492 * @param {number} n The number of times to invoke `iteratee`.
10493 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10494 * @param {*} [thisArg] The `this` binding of `iteratee`.
10495 * @returns {Array} Returns the array of results.
10496 * @example
10497 *
10498 * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
10499 * // => [3, 6, 4]
10500 *
10501 * _.times(3, function(n) {
10502 * mage.castSpell(n);
10503 * });
10504 * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
10505 *
10506 * _.times(3, function(n) {
10507 * this.cast(n);
10508 * }, mage);
10509 * // => also invokes `mage.castSpell(n)` three times
10510 */
10511 function times(n, iteratee, thisArg) {
10512 n = nativeFloor(n);
10513 // Exit early to avoid a JSC JIT bug in Safari 8
10514 // where `Array(0)` is treated as `Array(1)`.
10515 if (n < 1 || !nativeIsFinite(n)) {
10516 return [];
10517 }
10518 var index = -1, result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
10519 iteratee = bindCallback(iteratee, thisArg, 1);
10520 while (++index < n) {
10521 if (index < MAX_ARRAY_LENGTH) {
10522 result[index] = iteratee(index);
10523 } else {
10524 iteratee(index);
10525 }
10526 }
10527 return result;
10528 }
10529 /**
10530 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
10531 *
10532 * @static
10533 * @memberOf _
10534 * @category Utility
10535 * @param {string} [prefix] The value to prefix the ID with.
10536 * @returns {string} Returns the unique ID.
10537 * @example
10538 *
10539 * _.uniqueId('contact_');
10540 * // => 'contact_104'
10541 *
10542 * _.uniqueId();
10543 * // => '105'
10544 */
10545 function uniqueId(prefix) {
10546 var id = ++idCounter;
10547 return baseToString(prefix) + id;
10548 }
10549 /*------------------------------------------------------------------------*/
10550 /**
10551 * Adds two numbers.
10552 *
10553 * @static
10554 * @memberOf _
10555 * @category Math
10556 * @param {number} augend The first number to add.
10557 * @param {number} addend The second number to add.
10558 * @returns {number} Returns the sum.
10559 * @example
10560 *
10561 * _.add(6, 4);
10562 * // => 10
10563 */
10564 function add(augend, addend) {
10565 return (+augend || 0) + (+addend || 0);
10566 }
10567 /**
10568 * Calculates `n` rounded up to `precision`.
10569 *
10570 * @static
10571 * @memberOf _
10572 * @category Math
10573 * @param {number} n The number to round up.
10574 * @param {number} [precision=0] The precision to round up to.
10575 * @returns {number} Returns the rounded up number.
10576 * @example
10577 *
10578 * _.ceil(4.006);
10579 * // => 5
10580 *
10581 * _.ceil(6.004, 2);
10582 * // => 6.01
10583 *
10584 * _.ceil(6040, -2);
10585 * // => 6100
10586 */
10587 var ceil = createRound('ceil');
10588 /**
10589 * Calculates `n` rounded down to `precision`.
10590 *
10591 * @static
10592 * @memberOf _
10593 * @category Math
10594 * @param {number} n The number to round down.
10595 * @param {number} [precision=0] The precision to round down to.
10596 * @returns {number} Returns the rounded down number.
10597 * @example
10598 *
10599 * _.floor(4.006);
10600 * // => 4
10601 *
10602 * _.floor(0.046, 2);
10603 * // => 0.04
10604 *
10605 * _.floor(4060, -2);
10606 * // => 4000
10607 */
10608 var floor = createRound('floor');
10609 /**
10610 * Gets the maximum value of `collection`. If `collection` is empty or falsey
10611 * `-Infinity` is returned. If an iteratee function is provided it's invoked
10612 * for each value in `collection` to generate the criterion by which the value
10613 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
10614 * arguments: (value, index, collection).
10615 *
10616 * If a property name is provided for `iteratee` the created `_.property`
10617 * style callback returns the property value of the given element.
10618 *
10619 * If a value is also provided for `thisArg` the created `_.matchesProperty`
10620 * style callback returns `true` for elements that have a matching property
10621 * value, else `false`.
10622 *
10623 * If an object is provided for `iteratee` the created `_.matches` style
10624 * callback returns `true` for elements that have the properties of the given
10625 * object, else `false`.
10626 *
10627 * @static
10628 * @memberOf _
10629 * @category Math
10630 * @param {Array|Object|string} collection The collection to iterate over.
10631 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
10632 * @param {*} [thisArg] The `this` binding of `iteratee`.
10633 * @returns {*} Returns the maximum value.
10634 * @example
10635 *
10636 * _.max([4, 2, 8, 6]);
10637 * // => 8
10638 *
10639 * _.max([]);
10640 * // => -Infinity
10641 *
10642 * var users = [
10643 * { 'user': 'barney', 'age': 36 },
10644 * { 'user': 'fred', 'age': 40 }
10645 * ];
10646 *
10647 * _.max(users, function(chr) {
10648 * return chr.age;
10649 * });
10650 * // => { 'user': 'fred', 'age': 40 }
10651 *
10652 * // using the `_.property` callback shorthand
10653 * _.max(users, 'age');
10654 * // => { 'user': 'fred', 'age': 40 }
10655 */
10656 var max = createExtremum(gt, NEGATIVE_INFINITY);
10657 /**
10658 * Gets the minimum value of `collection`. If `collection` is empty or falsey
10659 * `Infinity` is returned. If an iteratee function is provided it's invoked
10660 * for each value in `collection` to generate the criterion by which the value
10661 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
10662 * arguments: (value, index, collection).
10663 *
10664 * If a property name is provided for `iteratee` the created `_.property`
10665 * style callback returns the property value of the given element.
10666 *
10667 * If a value is also provided for `thisArg` the created `_.matchesProperty`
10668 * style callback returns `true` for elements that have a matching property
10669 * value, else `false`.
10670 *
10671 * If an object is provided for `iteratee` the created `_.matches` style
10672 * callback returns `true` for elements that have the properties of the given
10673 * object, else `false`.
10674 *
10675 * @static
10676 * @memberOf _
10677 * @category Math
10678 * @param {Array|Object|string} collection The collection to iterate over.
10679 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
10680 * @param {*} [thisArg] The `this` binding of `iteratee`.
10681 * @returns {*} Returns the minimum value.
10682 * @example
10683 *
10684 * _.min([4, 2, 8, 6]);
10685 * // => 2
10686 *
10687 * _.min([]);
10688 * // => Infinity
10689 *
10690 * var users = [
10691 * { 'user': 'barney', 'age': 36 },
10692 * { 'user': 'fred', 'age': 40 }
10693 * ];
10694 *
10695 * _.min(users, function(chr) {
10696 * return chr.age;
10697 * });
10698 * // => { 'user': 'barney', 'age': 36 }
10699 *
10700 * // using the `_.property` callback shorthand
10701 * _.min(users, 'age');
10702 * // => { 'user': 'barney', 'age': 36 }
10703 */
10704 var min = createExtremum(lt, POSITIVE_INFINITY);
10705 /**
10706 * Calculates `n` rounded to `precision`.
10707 *
10708 * @static
10709 * @memberOf _
10710 * @category Math
10711 * @param {number} n The number to round.
10712 * @param {number} [precision=0] The precision to round to.
10713 * @returns {number} Returns the rounded number.
10714 * @example
10715 *
10716 * _.round(4.006);
10717 * // => 4
10718 *
10719 * _.round(4.006, 2);
10720 * // => 4.01
10721 *
10722 * _.round(4060, -2);
10723 * // => 4100
10724 */
10725 var round = createRound('round');
10726 /**
10727 * Gets the sum of the values in `collection`.
10728 *
10729 * @static
10730 * @memberOf _
10731 * @category Math
10732 * @param {Array|Object|string} collection The collection to iterate over.
10733 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
10734 * @param {*} [thisArg] The `this` binding of `iteratee`.
10735 * @returns {number} Returns the sum.
10736 * @example
10737 *
10738 * _.sum([4, 6]);
10739 * // => 10
10740 *
10741 * _.sum({ 'a': 4, 'b': 6 });
10742 * // => 10
10743 *
10744 * var objects = [
10745 * { 'n': 4 },
10746 * { 'n': 6 }
10747 * ];
10748 *
10749 * _.sum(objects, function(object) {
10750 * return object.n;
10751 * });
10752 * // => 10
10753 *
10754 * // using the `_.property` callback shorthand
10755 * _.sum(objects, 'n');
10756 * // => 10
10757 */
10758 function sum(collection, iteratee, thisArg) {
10759 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
10760 iteratee = undefined;
10761 }
10762 iteratee = getCallback(iteratee, thisArg, 3);
10763 return iteratee.length == 1 ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee) : baseSum(collection, iteratee);
10764 }
10765 /*------------------------------------------------------------------------*/
10766 // Ensure wrappers are instances of `baseLodash`.
10767 lodash.prototype = baseLodash.prototype;
10768 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
10769 LodashWrapper.prototype.constructor = LodashWrapper;
10770 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
10771 LazyWrapper.prototype.constructor = LazyWrapper;
10772 // Add functions to the `Map` cache.
10773 MapCache.prototype['delete'] = mapDelete;
10774 MapCache.prototype.get = mapGet;
10775 MapCache.prototype.has = mapHas;
10776 MapCache.prototype.set = mapSet;
10777 // Add functions to the `Set` cache.
10778 SetCache.prototype.push = cachePush;
10779 // Assign cache to `_.memoize`.
10780 memoize.Cache = MapCache;
10781 // Add functions that return wrapped values when chaining.
10782 lodash.after = after;
10783 lodash.ary = ary;
10784 lodash.assign = assign;
10785 lodash.at = at;
10786 lodash.before = before;
10787 lodash.bind = bind;
10788 lodash.bindAll = bindAll;
10789 lodash.bindKey = bindKey;
10790 lodash.callback = callback;
10791 lodash.chain = chain;
10792 lodash.chunk = chunk;
10793 lodash.compact = compact;
10794 lodash.constant = constant;
10795 lodash.countBy = countBy;
10796 lodash.create = create;
10797 lodash.curry = curry;
10798 lodash.curryRight = curryRight;
10799 lodash.debounce = debounce;
10800 lodash.defaults = defaults;
10801 lodash.defaultsDeep = defaultsDeep;
10802 lodash.defer = defer;
10803 lodash.delay = delay;
10804 lodash.difference = difference;
10805 lodash.drop = drop;
10806 lodash.dropRight = dropRight;
10807 lodash.dropRightWhile = dropRightWhile;
10808 lodash.dropWhile = dropWhile;
10809 lodash.fill = fill;
10810 lodash.filter = filter;
10811 lodash.flatten = flatten;
10812 lodash.flattenDeep = flattenDeep;
10813 lodash.flow = flow;
10814 lodash.flowRight = flowRight;
10815 lodash.forEach = forEach;
10816 lodash.forEachRight = forEachRight;
10817 lodash.forIn = forIn;
10818 lodash.forInRight = forInRight;
10819 lodash.forOwn = forOwn;
10820 lodash.forOwnRight = forOwnRight;
10821 lodash.functions = functions;
10822 lodash.groupBy = groupBy;
10823 lodash.indexBy = indexBy;
10824 lodash.initial = initial;
10825 lodash.intersection = intersection;
10826 lodash.invert = invert;
10827 lodash.invoke = invoke;
10828 lodash.keys = keys;
10829 lodash.keysIn = keysIn;
10830 lodash.map = map;
10831 lodash.mapKeys = mapKeys;
10832 lodash.mapValues = mapValues;
10833 lodash.matches = matches;
10834 lodash.matchesProperty = matchesProperty;
10835 lodash.memoize = memoize;
10836 lodash.merge = merge;
10837 lodash.method = method;
10838 lodash.methodOf = methodOf;
10839 lodash.mixin = mixin;
10840 lodash.modArgs = modArgs;
10841 lodash.negate = negate;
10842 lodash.omit = omit;
10843 lodash.once = once;
10844 lodash.pairs = pairs;
10845 lodash.partial = partial;
10846 lodash.partialRight = partialRight;
10847 lodash.partition = partition;
10848 lodash.pick = pick;
10849 lodash.pluck = pluck;
10850 lodash.property = property;
10851 lodash.propertyOf = propertyOf;
10852 lodash.pull = pull;
10853 lodash.pullAt = pullAt;
10854 lodash.range = range;
10855 lodash.rearg = rearg;
10856 lodash.reject = reject;
10857 lodash.remove = remove;
10858 lodash.rest = rest;
10859 lodash.restParam = restParam;
10860 lodash.set = set;
10861 lodash.shuffle = shuffle;
10862 lodash.slice = slice;
10863 lodash.sortBy = sortBy;
10864 lodash.sortByAll = sortByAll;
10865 lodash.sortByOrder = sortByOrder;
10866 lodash.spread = spread;
10867 lodash.take = take;
10868 lodash.takeRight = takeRight;
10869 lodash.takeRightWhile = takeRightWhile;
10870 lodash.takeWhile = takeWhile;
10871 lodash.tap = tap;
10872 lodash.throttle = throttle;
10873 lodash.thru = thru;
10874 lodash.times = times;
10875 lodash.toArray = toArray;
10876 lodash.toPlainObject = toPlainObject;
10877 lodash.transform = transform;
10878 lodash.union = union;
10879 lodash.uniq = uniq;
10880 lodash.unzip = unzip;
10881 lodash.unzipWith = unzipWith;
10882 lodash.values = values;
10883 lodash.valuesIn = valuesIn;
10884 lodash.where = where;
10885 lodash.without = without;
10886 lodash.wrap = wrap;
10887 lodash.xor = xor;
10888 lodash.zip = zip;
10889 lodash.zipObject = zipObject;
10890 lodash.zipWith = zipWith;
10891 // Add aliases.
10892 lodash.backflow = flowRight;
10893 lodash.collect = map;
10894 lodash.compose = flowRight;
10895 lodash.each = forEach;
10896 lodash.eachRight = forEachRight;
10897 lodash.extend = assign;
10898 lodash.iteratee = callback;
10899 lodash.methods = functions;
10900 lodash.object = zipObject;
10901 lodash.select = filter;
10902 lodash.tail = rest;
10903 lodash.unique = uniq;
10904 // Add functions to `lodash.prototype`.
10905 mixin(lodash, lodash);
10906 /*------------------------------------------------------------------------*/
10907 // Add functions that return unwrapped values when chaining.
10908 lodash.add = add;
10909 lodash.attempt = attempt;
10910 lodash.camelCase = camelCase;
10911 lodash.capitalize = capitalize;
10912 lodash.ceil = ceil;
10913 lodash.clone = clone;
10914 lodash.cloneDeep = cloneDeep;
10915 lodash.deburr = deburr;
10916 lodash.endsWith = endsWith;
10917 lodash.escape = escape;
10918 lodash.escapeRegExp = escapeRegExp;
10919 lodash.every = every;
10920 lodash.find = find;
10921 lodash.findIndex = findIndex;
10922 lodash.findKey = findKey;
10923 lodash.findLast = findLast;
10924 lodash.findLastIndex = findLastIndex;
10925 lodash.findLastKey = findLastKey;
10926 lodash.findWhere = findWhere;
10927 lodash.first = first;
10928 lodash.floor = floor;
10929 lodash.get = get;
10930 lodash.gt = gt;
10931 lodash.gte = gte;
10932 lodash.has = has;
10933 lodash.identity = identity;
10934 lodash.includes = includes;
10935 lodash.indexOf = indexOf;
10936 lodash.inRange = inRange;
10937 lodash.isArguments = isArguments;
10938 lodash.isArray = isArray;
10939 lodash.isBoolean = isBoolean;
10940 lodash.isDate = isDate;
10941 lodash.isElement = isElement;
10942 lodash.isEmpty = isEmpty;
10943 lodash.isEqual = isEqual;
10944 lodash.isError = isError;
10945 lodash.isFinite = isFinite;
10946 lodash.isFunction = isFunction;
10947 lodash.isMatch = isMatch;
10948 lodash.isNaN = isNaN;
10949 lodash.isNative = isNative;
10950 lodash.isNull = isNull;
10951 lodash.isNumber = isNumber;
10952 lodash.isObject = isObject;
10953 lodash.isPlainObject = isPlainObject;
10954 lodash.isRegExp = isRegExp;
10955 lodash.isString = isString;
10956 lodash.isTypedArray = isTypedArray;
10957 lodash.isUndefined = isUndefined;
10958 lodash.kebabCase = kebabCase;
10959 lodash.last = last;
10960 lodash.lastIndexOf = lastIndexOf;
10961 lodash.lt = lt;
10962 lodash.lte = lte;
10963 lodash.max = max;
10964 lodash.min = min;
10965 lodash.noConflict = noConflict;
10966 lodash.noop = noop;
10967 lodash.now = now;
10968 lodash.pad = pad;
10969 lodash.padLeft = padLeft;
10970 lodash.padRight = padRight;
10971 lodash.parseInt = parseInt;
10972 lodash.random = random;
10973 lodash.reduce = reduce;
10974 lodash.reduceRight = reduceRight;
10975 lodash.repeat = repeat;
10976 lodash.result = result;
10977 lodash.round = round;
10978 lodash.runInContext = runInContext;
10979 lodash.size = size;
10980 lodash.snakeCase = snakeCase;
10981 lodash.some = some;
10982 lodash.sortedIndex = sortedIndex;
10983 lodash.sortedLastIndex = sortedLastIndex;
10984 lodash.startCase = startCase;
10985 lodash.startsWith = startsWith;
10986 lodash.sum = sum;
10987 lodash.template = template;
10988 lodash.trim = trim;
10989 lodash.trimLeft = trimLeft;
10990 lodash.trimRight = trimRight;
10991 lodash.trunc = trunc;
10992 lodash.unescape = unescape;
10993 lodash.uniqueId = uniqueId;
10994 lodash.words = words;
10995 // Add aliases.
10996 lodash.all = every;
10997 lodash.any = some;
10998 lodash.contains = includes;
10999 lodash.eq = isEqual;
11000 lodash.detect = find;
11001 lodash.foldl = reduce;
11002 lodash.foldr = reduceRight;
11003 lodash.head = first;
11004 lodash.include = includes;
11005 lodash.inject = reduce;
11006 mixin(lodash, function () {
11007 var source = {};
11008 baseForOwn(lodash, function (func, methodName) {
11009 if (!lodash.prototype[methodName]) {
11010 source[methodName] = func;
11011 }
11012 });
11013 return source;
11014 }(), false);
11015 /*------------------------------------------------------------------------*/
11016 // Add functions capable of returning wrapped and unwrapped values when chaining.
11017 lodash.sample = sample;
11018 lodash.prototype.sample = function (n) {
11019 if (!this.__chain__ && n == null) {
11020 return sample(this.value());
11021 }
11022 return this.thru(function (value) {
11023 return sample(value, n);
11024 });
11025 };
11026 /*------------------------------------------------------------------------*/
11027 /**
11028 * The semantic version number.
11029 *
11030 * @static
11031 * @memberOf _
11032 * @type string
11033 */
11034 lodash.VERSION = VERSION;
11035 // Assign default placeholders.
11036 arrayEach([
11037 'bind',
11038 'bindKey',
11039 'curry',
11040 'curryRight',
11041 'partial',
11042 'partialRight'
11043 ], function (methodName) {
11044 lodash[methodName].placeholder = lodash;
11045 });
11046 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
11047 arrayEach([
11048 'drop',
11049 'take'
11050 ], function (methodName, index) {
11051 LazyWrapper.prototype[methodName] = function (n) {
11052 var filtered = this.__filtered__;
11053 if (filtered && !index) {
11054 return new LazyWrapper(this);
11055 }
11056 n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
11057 var result = this.clone();
11058 if (filtered) {
11059 result.__takeCount__ = nativeMin(result.__takeCount__, n);
11060 } else {
11061 result.__views__.push({
11062 'size': n,
11063 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
11064 });
11065 }
11066 return result;
11067 };
11068 LazyWrapper.prototype[methodName + 'Right'] = function (n) {
11069 return this.reverse()[methodName](n).reverse();
11070 };
11071 });
11072 // Add `LazyWrapper` methods that accept an `iteratee` value.
11073 arrayEach([
11074 'filter',
11075 'map',
11076 'takeWhile'
11077 ], function (methodName, index) {
11078 var type = index + 1, isFilter = type != LAZY_MAP_FLAG;
11079 LazyWrapper.prototype[methodName] = function (iteratee, thisArg) {
11080 var result = this.clone();
11081 result.__iteratees__.push({
11082 'iteratee': getCallback(iteratee, thisArg, 1),
11083 'type': type
11084 });
11085 result.__filtered__ = result.__filtered__ || isFilter;
11086 return result;
11087 };
11088 });
11089 // Add `LazyWrapper` methods for `_.first` and `_.last`.
11090 arrayEach([
11091 'first',
11092 'last'
11093 ], function (methodName, index) {
11094 var takeName = 'take' + (index ? 'Right' : '');
11095 LazyWrapper.prototype[methodName] = function () {
11096 return this[takeName](1).value()[0];
11097 };
11098 });
11099 // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
11100 arrayEach([
11101 'initial',
11102 'rest'
11103 ], function (methodName, index) {
11104 var dropName = 'drop' + (index ? '' : 'Right');
11105 LazyWrapper.prototype[methodName] = function () {
11106 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
11107 };
11108 });
11109 // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
11110 arrayEach([
11111 'pluck',
11112 'where'
11113 ], function (methodName, index) {
11114 var operationName = index ? 'filter' : 'map', createCallback = index ? baseMatches : property;
11115 LazyWrapper.prototype[methodName] = function (value) {
11116 return this[operationName](createCallback(value));
11117 };
11118 });
11119 LazyWrapper.prototype.compact = function () {
11120 return this.filter(identity);
11121 };
11122 LazyWrapper.prototype.reject = function (predicate, thisArg) {
11123 predicate = getCallback(predicate, thisArg, 1);
11124 return this.filter(function (value) {
11125 return !predicate(value);
11126 });
11127 };
11128 LazyWrapper.prototype.slice = function (start, end) {
11129 start = start == null ? 0 : +start || 0;
11130 var result = this;
11131 if (result.__filtered__ && (start > 0 || end < 0)) {
11132 return new LazyWrapper(result);
11133 }
11134 if (start < 0) {
11135 result = result.takeRight(-start);
11136 } else if (start) {
11137 result = result.drop(start);
11138 }
11139 if (end !== undefined) {
11140 end = +end || 0;
11141 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
11142 }
11143 return result;
11144 };
11145 LazyWrapper.prototype.takeRightWhile = function (predicate, thisArg) {
11146 return this.reverse().takeWhile(predicate, thisArg).reverse();
11147 };
11148 LazyWrapper.prototype.toArray = function () {
11149 return this.take(POSITIVE_INFINITY);
11150 };
11151 // Add `LazyWrapper` methods to `lodash.prototype`.
11152 baseForOwn(LazyWrapper.prototype, function (func, methodName) {
11153 var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName), retUnwrapped = /^(?:first|last)$/.test(methodName), lodashFunc = lodash[retUnwrapped ? 'take' + (methodName == 'last' ? 'Right' : '') : methodName];
11154 if (!lodashFunc) {
11155 return;
11156 }
11157 lodash.prototype[methodName] = function () {
11158 var args = retUnwrapped ? [1] : arguments, chainAll = this.__chain__, value = this.__wrapped__, isHybrid = !!this.__actions__.length, isLazy = value instanceof LazyWrapper, iteratee = args[0], useLazy = isLazy || isArray(value);
11159 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
11160 // Avoid lazy use if the iteratee has a "length" value other than `1`.
11161 isLazy = useLazy = false;
11162 }
11163 var interceptor = function (value) {
11164 return retUnwrapped && chainAll ? lodashFunc(value, 1)[0] : lodashFunc.apply(undefined, arrayPush([value], args));
11165 };
11166 var action = {
11167 'func': thru,
11168 'args': [interceptor],
11169 'thisArg': undefined
11170 }, onlyLazy = isLazy && !isHybrid;
11171 if (retUnwrapped && !chainAll) {
11172 if (onlyLazy) {
11173 value = value.clone();
11174 value.__actions__.push(action);
11175 return func.call(value);
11176 }
11177 return lodashFunc.call(undefined, this.value())[0];
11178 }
11179 if (!retUnwrapped && useLazy) {
11180 value = onlyLazy ? value : new LazyWrapper(this);
11181 var result = func.apply(value, args);
11182 result.__actions__.push(action);
11183 return new LodashWrapper(result, chainAll);
11184 }
11185 return this.thru(interceptor);
11186 };
11187 });
11188 // Add `Array` and `String` methods to `lodash.prototype`.
11189 arrayEach([
11190 'join',
11191 'pop',
11192 'push',
11193 'replace',
11194 'shift',
11195 'sort',
11196 'splice',
11197 'split',
11198 'unshift'
11199 ], function (methodName) {
11200 var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName], chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
11201 lodash.prototype[methodName] = function () {
11202 var args = arguments;
11203 if (retUnwrapped && !this.__chain__) {
11204 return func.apply(this.value(), args);
11205 }
11206 return this[chainName](function (value) {
11207 return func.apply(value, args);
11208 });
11209 };
11210 });
11211 // Map minified function names to their real names.
11212 baseForOwn(LazyWrapper.prototype, function (func, methodName) {
11213 var lodashFunc = lodash[methodName];
11214 if (lodashFunc) {
11215 var key = lodashFunc.name + '', names = realNames[key] || (realNames[key] = []);
11216 names.push({
11217 'name': methodName,
11218 'func': lodashFunc
11219 });
11220 }
11221 });
11222 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
11223 'name': 'wrapper',
11224 'func': undefined
11225 }];
11226 // Add functions to the lazy wrapper.
11227 LazyWrapper.prototype.clone = lazyClone;
11228 LazyWrapper.prototype.reverse = lazyReverse;
11229 LazyWrapper.prototype.value = lazyValue;
11230 // Add chaining functions to the `lodash` wrapper.
11231 lodash.prototype.chain = wrapperChain;
11232 lodash.prototype.commit = wrapperCommit;
11233 lodash.prototype.concat = wrapperConcat;
11234 lodash.prototype.plant = wrapperPlant;
11235 lodash.prototype.reverse = wrapperReverse;
11236 lodash.prototype.toString = wrapperToString;
11237 lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
11238 // Add function aliases to the `lodash` wrapper.
11239 lodash.prototype.collect = lodash.prototype.map;
11240 lodash.prototype.head = lodash.prototype.first;
11241 lodash.prototype.select = lodash.prototype.filter;
11242 lodash.prototype.tail = lodash.prototype.rest;
11243 return lodash;
11244 }
11245 /*--------------------------------------------------------------------------*/
11246 // Export lodash.
11247 var _ = runInContext();
11248 // Some AMD build optimizers like r.js check for condition patterns like the following:
11249 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
11250 // Define as an anonymous module so, through path mapping, it can be
11251 // referenced as the "underscore" module.
11252 define(function () {
11253 return _;
11254 });
11255 } // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
11256 else if (freeExports && freeModule) {
11257 // Export for Node.js or RingoJS.
11258 if (moduleExports) {
11259 (freeModule.exports = _)._ = _;
11260 } // Export for Rhino with CommonJS support.
11261 else {
11262 freeExports._ = _;
11263 }
11264 }
11265 $provide.constant('lodash', _);
11266 }
11267]);