3 * lodash 4.11.2 (Custom Build) <https://lodash.com/>
4 * Build: `lodash -o ./dist/lodash.js`
5 * Copyright jQuery Foundation and other contributors <https://jquery.org/>
6 * Released under MIT license <https://lodash.com/license>
7 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
8 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '4.11.2';
18 /** Used as the size to enable large array optimizations. */
19 var LARGE_ARRAY_SIZE = 200;
21 /** Used as the `TypeError` message for "Functions" methods. */
22 var FUNC_ERROR_TEXT = 'Expected a function';
24 /** Used to stand-in for `undefined` hash values. */
25 var HASH_UNDEFINED = '__lodash_hash_undefined__';
27 /** Used as the internal argument placeholder. */
28 var PLACEHOLDER = '__lodash_placeholder__';
30 /** Used to compose bitmasks for wrapper metadata. */
35 CURRY_RIGHT_FLAG = 16,
37 PARTIAL_RIGHT_FLAG = 64,
42 /** Used to compose bitmasks for comparison styles. */
43 var UNORDERED_COMPARE_FLAG = 1,
44 PARTIAL_COMPARE_FLAG = 2;
46 /** Used as default options for `_.truncate`. */
47 var DEFAULT_TRUNC_LENGTH = 30,
48 DEFAULT_TRUNC_OMISSION = '...';
50 /** Used to detect hot functions by number of calls within a span of milliseconds. */
54 /** Used to indicate the type of lazy iteratees. */
55 var LAZY_FILTER_FLAG = 1,
59 /** Used as references for various `Number` constants. */
61 MAX_SAFE_INTEGER = 9007199254740991,
62 MAX_INTEGER = 1.7976931348623157e+308,
65 /** Used as references for the maximum length and index of an array. */
66 var MAX_ARRAY_LENGTH = 4294967295,
67 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
68 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
70 /** `Object#toString` result references. */
71 var argsTag = '[object Arguments]',
72 arrayTag = '[object Array]',
73 boolTag = '[object Boolean]',
74 dateTag = '[object Date]',
75 errorTag = '[object Error]',
76 funcTag = '[object Function]',
77 genTag = '[object GeneratorFunction]',
78 mapTag = '[object Map]',
79 numberTag = '[object Number]',
80 objectTag = '[object Object]',
81 promiseTag = '[object Promise]',
82 regexpTag = '[object RegExp]',
83 setTag = '[object Set]',
84 stringTag = '[object String]',
85 symbolTag = '[object Symbol]',
86 weakMapTag = '[object WeakMap]',
87 weakSetTag = '[object WeakSet]';
89 var arrayBufferTag = '[object ArrayBuffer]',
90 dataViewTag = '[object DataView]',
91 float32Tag = '[object Float32Array]',
92 float64Tag = '[object Float64Array]',
93 int8Tag = '[object Int8Array]',
94 int16Tag = '[object Int16Array]',
95 int32Tag = '[object Int32Array]',
96 uint8Tag = '[object Uint8Array]',
97 uint8ClampedTag = '[object Uint8ClampedArray]',
98 uint16Tag = '[object Uint16Array]',
99 uint32Tag = '[object Uint32Array]';
101 /** Used to match empty string literals in compiled template source. */
102 var reEmptyStringLeading = /\b__p \+= '';/g,
103 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
104 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
106 /** Used to match HTML entities and HTML characters. */
107 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
108 reUnescapedHtml = /[&<>"'`]/g,
109 reHasEscapedHtml = RegExp(reEscapedHtml.source),
110 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
112 /** Used to match template delimiters. */
113 var reEscape = /<%-([\s\S]+?)%>/g,
114 reEvaluate = /<%([\s\S]+?)%>/g,
115 reInterpolate = /<%=([\s\S]+?)%>/g;
117 /** Used to match property names within property paths. */
118 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
119 reIsPlainProp = /^\w*$/,
120 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
123 * Used to match `RegExp`
124 * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
126 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
127 reHasRegExpChar = RegExp(reRegExpChar.source);
129 /** Used to match leading and trailing whitespace. */
130 var reTrim = /^\s+|\s+$/g,
131 reTrimStart = /^\s+/,
134 /** Used to match non-compound words composed of alphanumeric characters. */
135 var reBasicWord = /[a-zA-Z0-9]+/g;
137 /** Used to match backslashes in property paths. */
138 var reEscapeChar = /\\(\\)?/g;
142 * [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components).
144 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
146 /** Used to match `RegExp` flags from their coerced string values. */
147 var reFlags = /\w*$/;
149 /** Used to detect hexadecimal string values. */
150 var reHasHexPrefix = /^0x/i;
152 /** Used to detect bad signed hexadecimal string values. */
153 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
155 /** Used to detect binary string values. */
156 var reIsBinary = /^0b[01]+$/i;
158 /** Used to detect host constructors (Safari). */
159 var reIsHostCtor = /^\[object .+?Constructor\]$/;
161 /** Used to detect octal string values. */
162 var reIsOctal = /^0o[0-7]+$/i;
164 /** Used to detect unsigned integer values. */
165 var reIsUint = /^(?:0|[1-9]\d*)$/;
167 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
168 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
170 /** Used to ensure capturing order of template delimiters. */
171 var reNoMatch = /($^)/;
173 /** Used to match unescaped characters in compiled string literals. */
174 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
176 /** Used to compose unicode character classes. */
177 var rsAstralRange = '\\ud800-\\udfff',
178 rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
179 rsComboSymbolsRange = '\\u20d0-\\u20f0',
180 rsDingbatRange = '\\u2700-\\u27bf',
181 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
182 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
183 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
184 rsPunctuationRange = '\\u2000-\\u206f',
185 rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
186 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
187 rsVarRange = '\\ufe0e\\ufe0f',
188 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
190 /** Used to compose unicode capture groups. */
191 var rsApos = "['\u2019]",
192 rsAstral = '[' + rsAstralRange + ']',
193 rsBreak = '[' + rsBreakRange + ']',
194 rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
196 rsDingbat = '[' + rsDingbatRange + ']',
197 rsLower = '[' + rsLowerRange + ']',
198 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
199 rsFitz = '\\ud83c[\\udffb-\\udfff]',
200 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
201 rsNonAstral = '[^' + rsAstralRange + ']',
202 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
203 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
204 rsUpper = '[' + rsUpperRange + ']',
207 /** Used to compose unicode regexes. */
208 var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
209 rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
210 rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
211 rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
212 reOptMod = rsModifier + '?',
213 rsOptVar = '[' + rsVarRange + ']?',
214 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
215 rsSeq = rsOptVar + reOptMod + rsOptJoin,
216 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
217 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
219 /** Used to match apostrophes. */
220 var reApos = RegExp(rsApos, 'g');
223 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
224 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
226 var reComboMark = RegExp(rsCombo, 'g');
228 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
229 var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
231 /** Used to match complex or compound words. */
232 var reComplexWord = RegExp([
233 rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
234 rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
235 rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
236 rsUpper + '+' + rsOptUpperContr,
241 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
242 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
244 /** Used to detect strings that need a more robust regexp to match words. */
245 var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
247 /** Used to assign default `context` object properties. */
249 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
250 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
251 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError',
252 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
253 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
256 /** Used to make template sourceURLs easier to identify. */
257 var templateCounter = -1;
259 /** Used to identify `toStringTag` values of typed arrays. */
260 var typedArrayTags = {};
261 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
262 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
263 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
264 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
265 typedArrayTags[uint32Tag] = true;
266 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
267 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
268 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
269 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
270 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
271 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
272 typedArrayTags[setTag] = typedArrayTags[stringTag] =
273 typedArrayTags[weakMapTag] = false;
275 /** Used to identify `toStringTag` values supported by `_.clone`. */
276 var cloneableTags = {};
277 cloneableTags[argsTag] = cloneableTags[arrayTag] =
278 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
279 cloneableTags[boolTag] = cloneableTags[dateTag] =
280 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
281 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
282 cloneableTags[int32Tag] = cloneableTags[mapTag] =
283 cloneableTags[numberTag] = cloneableTags[objectTag] =
284 cloneableTags[regexpTag] = cloneableTags[setTag] =
285 cloneableTags[stringTag] = cloneableTags[symbolTag] =
286 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
287 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
288 cloneableTags[errorTag] = cloneableTags[funcTag] =
289 cloneableTags[weakMapTag] = false;
291 /** Used to map latin-1 supplementary letters to basic latin letters. */
292 var deburredLetters = {
293 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
294 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
295 '\xc7': 'C', '\xe7': 'c',
296 '\xd0': 'D', '\xf0': 'd',
297 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
298 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
299 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
300 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
301 '\xd1': 'N', '\xf1': 'n',
302 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
303 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
304 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
305 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
306 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
307 '\xc6': 'Ae', '\xe6': 'ae',
308 '\xde': 'Th', '\xfe': 'th',
312 /** Used to map characters to HTML entities. */
322 /** Used to map HTML entities to characters. */
323 var htmlUnescapes = {
332 /** Used to determine if values are of the language type `Object`. */
338 /** Used to escape characters for inclusion in compiled string literals. */
339 var stringEscapes = {
348 /** Built-in method references without a dependency on `root`. */
349 var freeParseFloat = parseFloat,
350 freeParseInt = parseInt;
352 /** Detect free variable `exports`. */
353 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
357 /** Detect free variable `module`. */
358 var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
362 /** Detect the popular CommonJS extension `module.exports`. */
363 var moduleExports = (freeModule && freeModule.exports === freeExports)
367 /** Detect free variable `global` from Node.js. */
368 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
370 /** Detect free variable `self`. */
371 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
373 /** Detect free variable `window`. */
374 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
376 /** Detect `this` as the global object. */
377 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
380 * Used as a reference to the global object.
382 * The `this` value is used if it's the global object to avoid Greasemonkey's
383 * restricted `window` object, otherwise the `window` object is used.
385 var root = freeGlobal ||
386 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
387 freeSelf || thisGlobal || Function('return this')();
389 /*--------------------------------------------------------------------------*/
392 * Adds the key-value `pair` to `map`.
395 * @param {Object} map The map to modify.
396 * @param {Array} pair The key-value pair to add.
397 * @returns {Object} Returns `map`.
399 function addMapEntry(map, pair) {
400 // Don't return `Map#set` because it doesn't return the map instance in IE 11.
401 map.set(pair[0], pair[1]);
406 * Adds `value` to `set`.
409 * @param {Object} set The set to modify.
410 * @param {*} value The value to add.
411 * @returns {Object} Returns `set`.
413 function addSetEntry(set, value) {
419 * A faster alternative to `Function#apply`, this function invokes `func`
420 * with the `this` binding of `thisArg` and the arguments of `args`.
423 * @param {Function} func The function to invoke.
424 * @param {*} thisArg The `this` binding of `func`.
425 * @param {Array} args The arguments to invoke `func` with.
426 * @returns {*} Returns the result of `func`.
428 function apply(func, thisArg, args) {
429 var length = args.length;
431 case 0: return func.call(thisArg);
432 case 1: return func.call(thisArg, args[0]);
433 case 2: return func.call(thisArg, args[0], args[1]);
434 case 3: return func.call(thisArg, args[0], args[1], args[2]);
436 return func.apply(thisArg, args);
440 * A specialized version of `baseAggregator` for arrays.
443 * @param {Array} array The array to iterate over.
444 * @param {Function} setter The function to set `accumulator` values.
445 * @param {Function} iteratee The iteratee to transform keys.
446 * @param {Object} accumulator The initial aggregated object.
447 * @returns {Function} Returns `accumulator`.
449 function arrayAggregator(array, setter, iteratee, accumulator) {
451 length = array.length;
453 while (++index < length) {
454 var value = array[index];
455 setter(accumulator, value, iteratee(value), array);
461 * Creates a new array concatenating `array` with `other`.
464 * @param {Array} array The first array to concatenate.
465 * @param {Array} other The second array to concatenate.
466 * @returns {Array} Returns the new concatenated array.
468 function arrayConcat(array, other) {
470 length = array.length,
472 othLength = other.length,
473 result = Array(length + othLength);
475 while (++index < length) {
476 result[index] = array[index];
478 while (++othIndex < othLength) {
479 result[index++] = other[othIndex];
485 * A specialized version of `_.forEach` for arrays without support for
486 * iteratee shorthands.
489 * @param {Array} array The array to iterate over.
490 * @param {Function} iteratee The function invoked per iteration.
491 * @returns {Array} Returns `array`.
493 function arrayEach(array, iteratee) {
495 length = array.length;
497 while (++index < length) {
498 if (iteratee(array[index], index, array) === false) {
506 * A specialized version of `_.forEachRight` for arrays without support for
507 * iteratee shorthands.
510 * @param {Array} array The array to iterate over.
511 * @param {Function} iteratee The function invoked per iteration.
512 * @returns {Array} Returns `array`.
514 function arrayEachRight(array, iteratee) {
515 var length = array.length;
518 if (iteratee(array[length], length, array) === false) {
526 * A specialized version of `_.every` for arrays without support for
527 * iteratee shorthands.
530 * @param {Array} array The array to iterate over.
531 * @param {Function} predicate The function invoked per iteration.
532 * @returns {boolean} Returns `true` if all elements pass the predicate check,
535 function arrayEvery(array, predicate) {
537 length = array.length;
539 while (++index < length) {
540 if (!predicate(array[index], index, array)) {
548 * A specialized version of `_.filter` for arrays without support for
549 * iteratee shorthands.
552 * @param {Array} array The array to iterate over.
553 * @param {Function} predicate The function invoked per iteration.
554 * @returns {Array} Returns the new filtered array.
556 function arrayFilter(array, predicate) {
558 length = array.length,
562 while (++index < length) {
563 var value = array[index];
564 if (predicate(value, index, array)) {
565 result[resIndex++] = value;
572 * A specialized version of `_.includes` for arrays without support for
573 * specifying an index to search from.
576 * @param {Array} array The array to search.
577 * @param {*} target The value to search for.
578 * @returns {boolean} Returns `true` if `target` is found, else `false`.
580 function arrayIncludes(array, value) {
581 return !!array.length && baseIndexOf(array, value, 0) > -1;
585 * This function is like `arrayIncludes` except that it accepts a comparator.
588 * @param {Array} array The array to search.
589 * @param {*} target The value to search for.
590 * @param {Function} comparator The comparator invoked per element.
591 * @returns {boolean} Returns `true` if `target` is found, else `false`.
593 function arrayIncludesWith(array, value, comparator) {
595 length = array.length;
597 while (++index < length) {
598 if (comparator(value, array[index])) {
606 * A specialized version of `_.map` for arrays without support for iteratee
610 * @param {Array} array The array to iterate over.
611 * @param {Function} iteratee The function invoked per iteration.
612 * @returns {Array} Returns the new mapped array.
614 function arrayMap(array, iteratee) {
616 length = array.length,
617 result = Array(length);
619 while (++index < length) {
620 result[index] = iteratee(array[index], index, array);
626 * Appends the elements of `values` to `array`.
629 * @param {Array} array The array to modify.
630 * @param {Array} values The values to append.
631 * @returns {Array} Returns `array`.
633 function arrayPush(array, values) {
635 length = values.length,
636 offset = array.length;
638 while (++index < length) {
639 array[offset + index] = values[index];
645 * A specialized version of `_.reduce` for arrays without support for
646 * iteratee shorthands.
649 * @param {Array} array The array to iterate over.
650 * @param {Function} iteratee The function invoked per iteration.
651 * @param {*} [accumulator] The initial value.
652 * @param {boolean} [initAccum] Specify using the first element of `array` as
654 * @returns {*} Returns the accumulated value.
656 function arrayReduce(array, iteratee, accumulator, initAccum) {
658 length = array.length;
660 if (initAccum && length) {
661 accumulator = array[++index];
663 while (++index < length) {
664 accumulator = iteratee(accumulator, array[index], index, array);
670 * A specialized version of `_.reduceRight` for arrays without support for
671 * iteratee shorthands.
674 * @param {Array} array The array to iterate over.
675 * @param {Function} iteratee The function invoked per iteration.
676 * @param {*} [accumulator] The initial value.
677 * @param {boolean} [initAccum] Specify using the last element of `array` as
679 * @returns {*} Returns the accumulated value.
681 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
682 var length = array.length;
683 if (initAccum && length) {
684 accumulator = array[--length];
687 accumulator = iteratee(accumulator, array[length], length, array);
693 * A specialized version of `_.some` for arrays without support for iteratee
697 * @param {Array} array The array to iterate over.
698 * @param {Function} predicate The function invoked per iteration.
699 * @returns {boolean} Returns `true` if any element passes the predicate check,
702 function arraySome(array, predicate) {
704 length = array.length;
706 while (++index < length) {
707 if (predicate(array[index], index, array)) {
715 * The base implementation of methods like `_.find` and `_.findKey`, without
716 * support for iteratee shorthands, which iterates over `collection` using
720 * @param {Array|Object} collection The collection to search.
721 * @param {Function} predicate The function invoked per iteration.
722 * @param {Function} eachFunc The function to iterate over `collection`.
723 * @param {boolean} [retKey] Specify returning the key of the found element
724 * instead of the element itself.
725 * @returns {*} Returns the found element or its key, else `undefined`.
727 function baseFind(collection, predicate, eachFunc, retKey) {
729 eachFunc(collection, function(value, key, collection) {
730 if (predicate(value, key, collection)) {
731 result = retKey ? key : value;
739 * The base implementation of `_.findIndex` and `_.findLastIndex` without
740 * support for iteratee shorthands.
743 * @param {Array} array The array to search.
744 * @param {Function} predicate The function invoked per iteration.
745 * @param {boolean} [fromRight] Specify iterating from right to left.
746 * @returns {number} Returns the index of the matched value, else `-1`.
748 function baseFindIndex(array, predicate, fromRight) {
749 var length = array.length,
750 index = fromRight ? length : -1;
752 while ((fromRight ? index-- : ++index < length)) {
753 if (predicate(array[index], index, array)) {
761 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
764 * @param {Array} array The array to search.
765 * @param {*} value The value to search for.
766 * @param {number} fromIndex The index to search from.
767 * @returns {number} Returns the index of the matched value, else `-1`.
769 function baseIndexOf(array, value, fromIndex) {
770 if (value !== value) {
771 return indexOfNaN(array, fromIndex);
773 var index = fromIndex - 1,
774 length = array.length;
776 while (++index < length) {
777 if (array[index] === value) {
785 * This function is like `baseIndexOf` except that it accepts a comparator.
788 * @param {Array} array The array to search.
789 * @param {*} value The value to search for.
790 * @param {number} fromIndex The index to search from.
791 * @param {Function} comparator The comparator invoked per element.
792 * @returns {number} Returns the index of the matched value, else `-1`.
794 function baseIndexOfWith(array, value, fromIndex, comparator) {
795 var index = fromIndex - 1,
796 length = array.length;
798 while (++index < length) {
799 if (comparator(array[index], value)) {
807 * The base implementation of `_.mean` and `_.meanBy` without support for
808 * iteratee shorthands.
811 * @param {Array} array The array to iterate over.
812 * @param {Function} iteratee The function invoked per iteration.
813 * @returns {number} Returns the mean.
815 function baseMean(array, iteratee) {
816 var length = array ? array.length : 0;
817 return length ? (baseSum(array, iteratee) / length) : NAN;
821 * The base implementation of `_.reduce` and `_.reduceRight`, without support
822 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
825 * @param {Array|Object} collection The collection to iterate over.
826 * @param {Function} iteratee The function invoked per iteration.
827 * @param {*} accumulator The initial value.
828 * @param {boolean} initAccum Specify using the first or last element of
829 * `collection` as the initial value.
830 * @param {Function} eachFunc The function to iterate over `collection`.
831 * @returns {*} Returns the accumulated value.
833 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
834 eachFunc(collection, function(value, index, collection) {
835 accumulator = initAccum
836 ? (initAccum = false, value)
837 : iteratee(accumulator, value, index, collection);
843 * The base implementation of `_.sortBy` which uses `comparer` to define the
844 * sort order of `array` and replaces criteria objects with their corresponding
848 * @param {Array} array The array to sort.
849 * @param {Function} comparer The function to define sort order.
850 * @returns {Array} Returns `array`.
852 function baseSortBy(array, comparer) {
853 var length = array.length;
855 array.sort(comparer);
857 array[length] = array[length].value;
863 * The base implementation of `_.sum` and `_.sumBy` without support for
864 * iteratee shorthands.
867 * @param {Array} array The array to iterate over.
868 * @param {Function} iteratee The function invoked per iteration.
869 * @returns {number} Returns the sum.
871 function baseSum(array, iteratee) {
874 length = array.length;
876 while (++index < length) {
877 var current = iteratee(array[index]);
878 if (current !== undefined) {
879 result = result === undefined ? current : (result + current);
886 * The base implementation of `_.times` without support for iteratee shorthands
887 * or max array length checks.
890 * @param {number} n The number of times to invoke `iteratee`.
891 * @param {Function} iteratee The function invoked per iteration.
892 * @returns {Array} Returns the array of results.
894 function baseTimes(n, iteratee) {
898 while (++index < n) {
899 result[index] = iteratee(index);
905 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
906 * of key-value pairs for `object` corresponding to the property names of `props`.
909 * @param {Object} object The object to query.
910 * @param {Array} props The property names to get values for.
911 * @returns {Object} Returns the new array of key-value pairs.
913 function baseToPairs(object, props) {
914 return arrayMap(props, function(key) {
915 return [key, object[key]];
920 * The base implementation of `_.unary` without support for storing wrapper metadata.
923 * @param {Function} func The function to cap arguments for.
924 * @returns {Function} Returns the new function.
926 function baseUnary(func) {
927 return function(value) {
933 * The base implementation of `_.values` and `_.valuesIn` which creates an
934 * array of `object` property values corresponding to the property names
938 * @param {Object} object The object to query.
939 * @param {Array} props The property names to get values for.
940 * @returns {Object} Returns the array of property values.
942 function baseValues(object, props) {
943 return arrayMap(props, function(key) {
949 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
950 * that is not found in the character symbols.
953 * @param {Array} strSymbols The string symbols to inspect.
954 * @param {Array} chrSymbols The character symbols to find.
955 * @returns {number} Returns the index of the first unmatched string symbol.
957 function charsStartIndex(strSymbols, chrSymbols) {
959 length = strSymbols.length;
961 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
966 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
967 * that is not found in the character symbols.
970 * @param {Array} strSymbols The string symbols to inspect.
971 * @param {Array} chrSymbols The character symbols to find.
972 * @returns {number} Returns the index of the last unmatched string symbol.
974 function charsEndIndex(strSymbols, chrSymbols) {
975 var index = strSymbols.length;
977 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
982 * Checks if `value` is a global object.
985 * @param {*} value The value to check.
986 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
988 function checkGlobal(value) {
989 return (value && value.Object === Object) ? value : null;
993 * Gets the number of `placeholder` occurrences in `array`.
996 * @param {Array} array The array to inspect.
997 * @param {*} placeholder The placeholder to search for.
998 * @returns {number} Returns the placeholder count.
1000 function countHolders(array, placeholder) {
1001 var length = array.length,
1005 if (array[length] === placeholder) {
1013 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
1016 * @param {string} letter The matched letter to deburr.
1017 * @returns {string} Returns the deburred letter.
1019 function deburrLetter(letter) {
1020 return deburredLetters[letter];
1024 * Used by `_.escape` to convert characters to HTML entities.
1027 * @param {string} chr The matched character to escape.
1028 * @returns {string} Returns the escaped character.
1030 function escapeHtmlChar(chr) {
1031 return htmlEscapes[chr];
1035 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1038 * @param {string} chr The matched character to escape.
1039 * @returns {string} Returns the escaped character.
1041 function escapeStringChar(chr) {
1042 return '\\' + stringEscapes[chr];
1046 * Gets the index at which the first occurrence of `NaN` is found in `array`.
1049 * @param {Array} array The array to search.
1050 * @param {number} fromIndex The index to search from.
1051 * @param {boolean} [fromRight] Specify iterating from right to left.
1052 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
1054 function indexOfNaN(array, fromIndex, fromRight) {
1055 var length = array.length,
1056 index = fromIndex + (fromRight ? 0 : -1);
1058 while ((fromRight ? index-- : ++index < length)) {
1059 var other = array[index];
1060 if (other !== other) {
1068 * Checks if `value` is a host object in IE < 9.
1071 * @param {*} value The value to check.
1072 * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
1074 function isHostObject(value) {
1075 // Many host objects are `Object` objects that can coerce to strings
1076 // despite having improperly defined `toString` methods.
1078 if (value != null && typeof value.toString != 'function') {
1080 result = !!(value + '');
1087 * Converts `iterator` to an array.
1090 * @param {Object} iterator The iterator to convert.
1091 * @returns {Array} Returns the converted array.
1093 function iteratorToArray(iterator) {
1097 while (!(data = iterator.next()).done) {
1098 result.push(data.value);
1104 * Converts `map` to an array.
1107 * @param {Object} map The map to convert.
1108 * @returns {Array} Returns the converted array.
1110 function mapToArray(map) {
1112 result = Array(map.size);
1114 map.forEach(function(value, key) {
1115 result[++index] = [key, value];
1121 * Replaces all `placeholder` elements in `array` with an internal placeholder
1122 * and returns an array of their indexes.
1125 * @param {Array} array The array to modify.
1126 * @param {*} placeholder The placeholder to replace.
1127 * @returns {Array} Returns the new array of placeholder indexes.
1129 function replaceHolders(array, placeholder) {
1131 length = array.length,
1135 while (++index < length) {
1136 var value = array[index];
1137 if (value === placeholder || value === PLACEHOLDER) {
1138 array[index] = PLACEHOLDER;
1139 result[resIndex++] = index;
1146 * Converts `set` to an array.
1149 * @param {Object} set The set to convert.
1150 * @returns {Array} Returns the converted array.
1152 function setToArray(set) {
1154 result = Array(set.size);
1156 set.forEach(function(value) {
1157 result[++index] = value;
1163 * Gets the number of symbols in `string`.
1166 * @param {string} string The string to inspect.
1167 * @returns {number} Returns the string size.
1169 function stringSize(string) {
1170 if (!(string && reHasComplexSymbol.test(string))) {
1171 return string.length;
1173 var result = reComplexSymbol.lastIndex = 0;
1174 while (reComplexSymbol.test(string)) {
1181 * Converts `string` to an array.
1184 * @param {string} string The string to convert.
1185 * @returns {Array} Returns the converted array.
1187 function stringToArray(string) {
1188 return string.match(reComplexSymbol);
1192 * Used by `_.unescape` to convert HTML entities to characters.
1195 * @param {string} chr The matched character to unescape.
1196 * @returns {string} Returns the unescaped character.
1198 function unescapeHtmlChar(chr) {
1199 return htmlUnescapes[chr];
1202 /*--------------------------------------------------------------------------*/
1205 * Create a new pristine `lodash` function using the `context` object.
1211 * @param {Object} [context=root] The context object.
1212 * @returns {Function} Returns a new `lodash` function.
1215 * _.mixin({ 'foo': _.constant('foo') });
1217 * var lodash = _.runInContext();
1218 * lodash.mixin({ 'bar': lodash.constant('bar') });
1220 * _.isFunction(_.foo);
1222 * _.isFunction(_.bar);
1225 * lodash.isFunction(lodash.foo);
1227 * lodash.isFunction(lodash.bar);
1230 * // Use `context` to mock `Date#getTime` use in `_.now`.
1231 * var mock = _.runInContext({
1232 * 'Date': function() {
1233 * return { 'getTime': getTimeMock };
1237 * // Create a suped-up `defer` in Node.js.
1238 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1240 function runInContext(context) {
1241 context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
1243 /** Built-in constructor references. */
1244 var Date = context.Date,
1245 Error = context.Error,
1246 Math = context.Math,
1247 RegExp = context.RegExp,
1248 TypeError = context.TypeError;
1250 /** Used for built-in method references. */
1251 var arrayProto = context.Array.prototype,
1252 objectProto = context.Object.prototype,
1253 stringProto = context.String.prototype;
1255 /** Used to resolve the decompiled source of functions. */
1256 var funcToString = context.Function.prototype.toString;
1258 /** Used to check objects for own properties. */
1259 var hasOwnProperty = objectProto.hasOwnProperty;
1261 /** Used to generate unique IDs. */
1264 /** Used to infer the `Object` constructor. */
1265 var objectCtorString = funcToString.call(Object);
1268 * Used to resolve the
1269 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
1272 var objectToString = objectProto.toString;
1274 /** Used to restore the original `_` reference in `_.noConflict`. */
1275 var oldDash = root._;
1277 /** Used to detect if a method is native. */
1278 var reIsNative = RegExp('^' +
1279 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1280 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1283 /** Built-in value references. */
1284 var Buffer = moduleExports ? context.Buffer : undefined,
1285 Reflect = context.Reflect,
1286 Symbol = context.Symbol,
1287 Uint8Array = context.Uint8Array,
1288 clearTimeout = context.clearTimeout,
1289 enumerate = Reflect ? Reflect.enumerate : undefined,
1290 getOwnPropertySymbols = Object.getOwnPropertySymbols,
1291 iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
1292 objectCreate = Object.create,
1293 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1294 setTimeout = context.setTimeout,
1295 splice = arrayProto.splice;
1297 /* Built-in method references for those with the same name as other `lodash` methods. */
1298 var nativeCeil = Math.ceil,
1299 nativeFloor = Math.floor,
1300 nativeGetPrototype = Object.getPrototypeOf,
1301 nativeIsFinite = context.isFinite,
1302 nativeJoin = arrayProto.join,
1303 nativeKeys = Object.keys,
1304 nativeMax = Math.max,
1305 nativeMin = Math.min,
1306 nativeParseInt = context.parseInt,
1307 nativeRandom = Math.random,
1308 nativeReplace = stringProto.replace,
1309 nativeReverse = arrayProto.reverse,
1310 nativeSplit = stringProto.split;
1312 /* Built-in method references that are verified to be native. */
1313 var DataView = getNative(context, 'DataView'),
1314 Map = getNative(context, 'Map'),
1315 Promise = getNative(context, 'Promise'),
1316 Set = getNative(context, 'Set'),
1317 WeakMap = getNative(context, 'WeakMap'),
1318 nativeCreate = getNative(Object, 'create');
1320 /** Used to store function metadata. */
1321 var metaMap = WeakMap && new WeakMap;
1323 /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
1324 var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
1326 /** Used to lookup unminified function names. */
1329 /** Used to detect maps, sets, and weakmaps. */
1330 var dataViewCtorString = toSource(DataView),
1331 mapCtorString = toSource(Map),
1332 promiseCtorString = toSource(Promise),
1333 setCtorString = toSource(Set),
1334 weakMapCtorString = toSource(WeakMap);
1336 /** Used to convert symbols to primitives and strings. */
1337 var symbolProto = Symbol ? Symbol.prototype : undefined,
1338 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1339 symbolToString = symbolProto ? symbolProto.toString : undefined;
1341 /*------------------------------------------------------------------------*/
1344 * Creates a `lodash` object which wraps `value` to enable implicit method
1345 * chain sequences. Methods that operate on and return arrays, collections,
1346 * and functions can be chained together. Methods that retrieve a single value
1347 * or may return a primitive value will automatically end the chain sequence
1348 * and return the unwrapped value. Otherwise, the value must be unwrapped
1351 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1352 * enabled using `_.chain`.
1354 * The execution of chained methods is lazy, that is, it's deferred until
1355 * `_#value` is implicitly or explicitly called.
1357 * Lazy evaluation allows several methods to support shortcut fusion.
1358 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1359 * the creation of intermediate arrays and can greatly reduce the number of
1360 * iteratee executions. Sections of a chain sequence qualify for shortcut
1361 * fusion if the section is applied to an array of at least `200` elements
1362 * and any iteratees accept only one argument. The heuristic for whether a
1363 * section qualifies for shortcut fusion is subject to change.
1365 * Chaining is supported in custom builds as long as the `_#value` method is
1366 * directly or indirectly included in the build.
1368 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1370 * The wrapper `Array` methods are:
1371 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1373 * The wrapper `String` methods are:
1374 * `replace` and `split`
1376 * The wrapper methods that support shortcut fusion are:
1377 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1378 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1379 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1381 * The chainable wrapper methods are:
1382 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1383 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1384 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1385 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1386 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1387 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1388 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1389 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1390 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1391 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1392 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1393 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1394 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1395 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1396 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1397 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1398 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1399 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1400 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1401 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1402 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1403 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1404 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1405 * `zipObject`, `zipObjectDeep`, and `zipWith`
1407 * The wrapper methods that are **not** chainable by default are:
1408 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1409 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `divide`, `each`,
1410 * `eachRight`, `endsWith`, `eq`, `escape`, `escapeRegExp`, `every`, `find`,
1411 * `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `first`,
1412 * `floor`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
1413 * `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`, `head`, `identity`,
1414 * `includes`, `indexOf`, `inRange`, `invoke`, `isArguments`, `isArray`,
1415 * `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isBuffer`,
1416 * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`, `isError`,
1417 * `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`, `isMatch`,
1418 * `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
1419 * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
1420 * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`,
1421 * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`,
1422 * `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`,
1423 * `noConflict`, `noop`, `now`, `nth`, `pad`, `padEnd`, `padStart`, `parseInt`,
1424 * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
1425 * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
1426 * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
1427 * `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toInteger`,
1428 * `toJSON`, `toLength`, `toLower`, `toNumber`, `toSafeInteger`, `toString`,
1429 * `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`,
1430 * `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words`
1435 * @param {*} value The value to wrap in a `lodash` instance.
1436 * @returns {Object} Returns the new `lodash` wrapper instance.
1439 * function square(n) {
1443 * var wrapped = _([1, 2, 3]);
1445 * // Returns an unwrapped value.
1446 * wrapped.reduce(_.add);
1449 * // Returns a wrapped value.
1450 * var squares = wrapped.map(square);
1452 * _.isArray(squares);
1455 * _.isArray(squares.value());
1458 function lodash(value) {
1459 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1460 if (value instanceof LodashWrapper) {
1463 if (hasOwnProperty.call(value, '__wrapped__')) {
1464 return wrapperClone(value);
1467 return new LodashWrapper(value);
1471 * The function whose prototype chain sequence wrappers inherit from.
1475 function baseLodash() {
1476 // No operation performed.
1480 * The base constructor for creating `lodash` wrapper objects.
1483 * @param {*} value The value to wrap.
1484 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1486 function LodashWrapper(value, chainAll) {
1487 this.__wrapped__ = value;
1488 this.__actions__ = [];
1489 this.__chain__ = !!chainAll;
1491 this.__values__ = undefined;
1495 * By default, the template delimiters used by lodash are like those in
1496 * embedded Ruby (ERB). Change the following template settings to use
1497 * alternative delimiters.
1503 lodash.templateSettings = {
1506 * Used to detect `data` property values to be HTML-escaped.
1508 * @memberOf _.templateSettings
1514 * Used to detect code to be evaluated.
1516 * @memberOf _.templateSettings
1519 'evaluate': reEvaluate,
1522 * Used to detect `data` property values to inject.
1524 * @memberOf _.templateSettings
1527 'interpolate': reInterpolate,
1530 * Used to reference the data object in the template text.
1532 * @memberOf _.templateSettings
1538 * Used to import variables into the compiled template.
1540 * @memberOf _.templateSettings
1546 * A reference to the `lodash` function.
1548 * @memberOf _.templateSettings.imports
1555 // Ensure wrappers are instances of `baseLodash`.
1556 lodash.prototype = baseLodash.prototype;
1557 lodash.prototype.constructor = lodash;
1559 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1560 LodashWrapper.prototype.constructor = LodashWrapper;
1562 /*------------------------------------------------------------------------*/
1565 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1569 * @param {*} value The value to wrap.
1571 function LazyWrapper(value) {
1572 this.__wrapped__ = value;
1573 this.__actions__ = [];
1575 this.__filtered__ = false;
1576 this.__iteratees__ = [];
1577 this.__takeCount__ = MAX_ARRAY_LENGTH;
1578 this.__views__ = [];
1582 * Creates a clone of the lazy wrapper object.
1586 * @memberOf LazyWrapper
1587 * @returns {Object} Returns the cloned `LazyWrapper` object.
1589 function lazyClone() {
1590 var result = new LazyWrapper(this.__wrapped__);
1591 result.__actions__ = copyArray(this.__actions__);
1592 result.__dir__ = this.__dir__;
1593 result.__filtered__ = this.__filtered__;
1594 result.__iteratees__ = copyArray(this.__iteratees__);
1595 result.__takeCount__ = this.__takeCount__;
1596 result.__views__ = copyArray(this.__views__);
1601 * Reverses the direction of lazy iteration.
1605 * @memberOf LazyWrapper
1606 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1608 function lazyReverse() {
1609 if (this.__filtered__) {
1610 var result = new LazyWrapper(this);
1611 result.__dir__ = -1;
1612 result.__filtered__ = true;
1614 result = this.clone();
1615 result.__dir__ *= -1;
1621 * Extracts the unwrapped value from its lazy wrapper.
1625 * @memberOf LazyWrapper
1626 * @returns {*} Returns the unwrapped value.
1628 function lazyValue() {
1629 var array = this.__wrapped__.value(),
1631 isArr = isArray(array),
1633 arrLength = isArr ? array.length : 0,
1634 view = getView(0, arrLength, this.__views__),
1637 length = end - start,
1638 index = isRight ? end : (start - 1),
1639 iteratees = this.__iteratees__,
1640 iterLength = iteratees.length,
1642 takeCount = nativeMin(length, this.__takeCount__);
1644 if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
1645 (arrLength == length && takeCount == length)) {
1646 return baseWrapperValue(array, this.__actions__);
1651 while (length-- && resIndex < takeCount) {
1655 value = array[index];
1657 while (++iterIndex < iterLength) {
1658 var data = iteratees[iterIndex],
1659 iteratee = data.iteratee,
1661 computed = iteratee(value);
1663 if (type == LAZY_MAP_FLAG) {
1665 } else if (!computed) {
1666 if (type == LAZY_FILTER_FLAG) {
1673 result[resIndex++] = value;
1678 // Ensure `LazyWrapper` is an instance of `baseLodash`.
1679 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
1680 LazyWrapper.prototype.constructor = LazyWrapper;
1682 /*------------------------------------------------------------------------*/
1685 * Creates a hash object.
1689 * @returns {Object} Returns the new hash object.
1694 * Removes `key` and its value from the hash.
1697 * @param {Object} hash The hash to modify.
1698 * @param {string} key The key of the value to remove.
1699 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1701 function hashDelete(hash, key) {
1702 return hashHas(hash, key) && delete hash[key];
1706 * Gets the hash value for `key`.
1709 * @param {Object} hash The hash to query.
1710 * @param {string} key The key of the value to get.
1711 * @returns {*} Returns the entry value.
1713 function hashGet(hash, key) {
1715 var result = hash[key];
1716 return result === HASH_UNDEFINED ? undefined : result;
1718 return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
1722 * Checks if a hash value for `key` exists.
1725 * @param {Object} hash The hash to query.
1726 * @param {string} key The key of the entry to check.
1727 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1729 function hashHas(hash, key) {
1730 return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
1734 * Sets the hash `key` to `value`.
1737 * @param {Object} hash The hash to modify.
1738 * @param {string} key The key of the value to set.
1739 * @param {*} value The value to set.
1741 function hashSet(hash, key, value) {
1742 hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
1745 // Avoid inheriting from `Object.prototype` when possible.
1746 Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
1748 /*------------------------------------------------------------------------*/
1751 * Creates a map cache object to store key-value pairs.
1755 * @param {Array} [values] The values to cache.
1757 function MapCache(values) {
1759 length = values ? values.length : 0;
1762 while (++index < length) {
1763 var entry = values[index];
1764 this.set(entry[0], entry[1]);
1769 * Removes all key-value entries from the map.
1773 * @memberOf MapCache
1775 function mapClear() {
1778 'map': Map ? new Map : [],
1784 * Removes `key` and its value from the map.
1788 * @memberOf MapCache
1789 * @param {string} key The key of the value to remove.
1790 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1792 function mapDelete(key) {
1793 var data = this.__data__;
1794 if (isKeyable(key)) {
1795 return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
1797 return Map ? data.map['delete'](key) : assocDelete(data.map, key);
1801 * Gets the map value for `key`.
1805 * @memberOf MapCache
1806 * @param {string} key The key of the value to get.
1807 * @returns {*} Returns the entry value.
1809 function mapGet(key) {
1810 var data = this.__data__;
1811 if (isKeyable(key)) {
1812 return hashGet(typeof key == 'string' ? data.string : data.hash, key);
1814 return Map ? data.map.get(key) : assocGet(data.map, key);
1818 * Checks if a map value for `key` exists.
1822 * @memberOf MapCache
1823 * @param {string} key The key of the entry to check.
1824 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1826 function mapHas(key) {
1827 var data = this.__data__;
1828 if (isKeyable(key)) {
1829 return hashHas(typeof key == 'string' ? data.string : data.hash, key);
1831 return Map ? data.map.has(key) : assocHas(data.map, key);
1835 * Sets the map `key` to `value`.
1839 * @memberOf MapCache
1840 * @param {string} key The key of the value to set.
1841 * @param {*} value The value to set.
1842 * @returns {Object} Returns the map cache instance.
1844 function mapSet(key, value) {
1845 var data = this.__data__;
1846 if (isKeyable(key)) {
1847 hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
1849 data.map.set(key, value);
1851 assocSet(data.map, key, value);
1856 // Add methods to `MapCache`.
1857 MapCache.prototype.clear = mapClear;
1858 MapCache.prototype['delete'] = mapDelete;
1859 MapCache.prototype.get = mapGet;
1860 MapCache.prototype.has = mapHas;
1861 MapCache.prototype.set = mapSet;
1863 /*------------------------------------------------------------------------*/
1867 * Creates a set cache object to store unique values.
1871 * @param {Array} [values] The values to cache.
1873 function SetCache(values) {
1875 length = values ? values.length : 0;
1877 this.__data__ = new MapCache;
1878 while (++index < length) {
1879 this.push(values[index]);
1884 * Checks if `value` is in `cache`.
1887 * @param {Object} cache The set cache to search.
1888 * @param {*} value The value to search for.
1889 * @returns {number} Returns `true` if `value` is found, else `false`.
1891 function cacheHas(cache, value) {
1892 var map = cache.__data__;
1893 if (isKeyable(value)) {
1894 var data = map.__data__,
1895 hash = typeof value == 'string' ? data.string : data.hash;
1897 return hash[value] === HASH_UNDEFINED;
1899 return map.has(value);
1903 * Adds `value` to the set cache.
1907 * @memberOf SetCache
1908 * @param {*} value The value to cache.
1910 function cachePush(value) {
1911 var map = this.__data__;
1912 if (isKeyable(value)) {
1913 var data = map.__data__,
1914 hash = typeof value == 'string' ? data.string : data.hash;
1916 hash[value] = HASH_UNDEFINED;
1919 map.set(value, HASH_UNDEFINED);
1923 // Add methods to `SetCache`.
1924 SetCache.prototype.push = cachePush;
1926 /*------------------------------------------------------------------------*/
1929 * Creates a stack cache object to store key-value pairs.
1933 * @param {Array} [values] The values to cache.
1935 function Stack(values) {
1937 length = values ? values.length : 0;
1940 while (++index < length) {
1941 var entry = values[index];
1942 this.set(entry[0], entry[1]);
1947 * Removes all key-value entries from the stack.
1953 function stackClear() {
1954 this.__data__ = { 'array': [], 'map': null };
1958 * Removes `key` and its value from the stack.
1963 * @param {string} key The key of the value to remove.
1964 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1966 function stackDelete(key) {
1967 var data = this.__data__,
1970 return array ? assocDelete(array, key) : data.map['delete'](key);
1974 * Gets the stack value for `key`.
1979 * @param {string} key The key of the value to get.
1980 * @returns {*} Returns the entry value.
1982 function stackGet(key) {
1983 var data = this.__data__,
1986 return array ? assocGet(array, key) : data.map.get(key);
1990 * Checks if a stack value for `key` exists.
1995 * @param {string} key The key of the entry to check.
1996 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1998 function stackHas(key) {
1999 var data = this.__data__,
2002 return array ? assocHas(array, key) : data.map.has(key);
2006 * Sets the stack `key` to `value`.
2011 * @param {string} key The key of the value to set.
2012 * @param {*} value The value to set.
2013 * @returns {Object} Returns the stack cache instance.
2015 function stackSet(key, value) {
2016 var data = this.__data__,
2020 if (array.length < (LARGE_ARRAY_SIZE - 1)) {
2021 assocSet(array, key, value);
2024 data.map = new MapCache(array);
2029 map.set(key, value);
2034 // Add methods to `Stack`.
2035 Stack.prototype.clear = stackClear;
2036 Stack.prototype['delete'] = stackDelete;
2037 Stack.prototype.get = stackGet;
2038 Stack.prototype.has = stackHas;
2039 Stack.prototype.set = stackSet;
2041 /*------------------------------------------------------------------------*/
2044 * Removes `key` and its value from the associative array.
2047 * @param {Array} array The array to modify.
2048 * @param {string} key The key of the value to remove.
2049 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2051 function assocDelete(array, key) {
2052 var index = assocIndexOf(array, key);
2056 var lastIndex = array.length - 1;
2057 if (index == lastIndex) {
2060 splice.call(array, index, 1);
2066 * Gets the associative array value for `key`.
2069 * @param {Array} array The array to query.
2070 * @param {string} key The key of the value to get.
2071 * @returns {*} Returns the entry value.
2073 function assocGet(array, key) {
2074 var index = assocIndexOf(array, key);
2075 return index < 0 ? undefined : array[index][1];
2079 * Checks if an associative array value for `key` exists.
2082 * @param {Array} array The array to query.
2083 * @param {string} key The key of the entry to check.
2084 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2086 function assocHas(array, key) {
2087 return assocIndexOf(array, key) > -1;
2091 * Gets the index at which the `key` is found in `array` of key-value pairs.
2094 * @param {Array} array The array to search.
2095 * @param {*} key The key to search for.
2096 * @returns {number} Returns the index of the matched value, else `-1`.
2098 function assocIndexOf(array, key) {
2099 var length = array.length;
2101 if (eq(array[length][0], key)) {
2109 * Sets the associative array `key` to `value`.
2112 * @param {Array} array The array to modify.
2113 * @param {string} key The key of the value to set.
2114 * @param {*} value The value to set.
2116 function assocSet(array, key, value) {
2117 var index = assocIndexOf(array, key);
2119 array.push([key, value]);
2121 array[index][1] = value;
2125 /*------------------------------------------------------------------------*/
2128 * Used by `_.defaults` to customize its `_.assignIn` use.
2131 * @param {*} objValue The destination value.
2132 * @param {*} srcValue The source value.
2133 * @param {string} key The key of the property to assign.
2134 * @param {Object} object The parent object of `objValue`.
2135 * @returns {*} Returns the value to assign.
2137 function assignInDefaults(objValue, srcValue, key, object) {
2138 if (objValue === undefined ||
2139 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2146 * This function is like `assignValue` except that it doesn't assign
2147 * `undefined` values.
2150 * @param {Object} object The object to modify.
2151 * @param {string} key The key of the property to assign.
2152 * @param {*} value The value to assign.
2154 function assignMergeValue(object, key, value) {
2155 if ((value !== undefined && !eq(object[key], value)) ||
2156 (typeof key == 'number' && value === undefined && !(key in object))) {
2157 object[key] = value;
2162 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2163 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
2164 * for equality comparisons.
2167 * @param {Object} object The object to modify.
2168 * @param {string} key The key of the property to assign.
2169 * @param {*} value The value to assign.
2171 function assignValue(object, key, value) {
2172 var objValue = object[key];
2173 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2174 (value === undefined && !(key in object))) {
2175 object[key] = value;
2180 * Aggregates elements of `collection` on `accumulator` with keys transformed
2181 * by `iteratee` and values set by `setter`.
2184 * @param {Array|Object} collection The collection to iterate over.
2185 * @param {Function} setter The function to set `accumulator` values.
2186 * @param {Function} iteratee The iteratee to transform keys.
2187 * @param {Object} accumulator The initial aggregated object.
2188 * @returns {Function} Returns `accumulator`.
2190 function baseAggregator(collection, setter, iteratee, accumulator) {
2191 baseEach(collection, function(value, key, collection) {
2192 setter(accumulator, value, iteratee(value), collection);
2198 * The base implementation of `_.assign` without support for multiple sources
2199 * or `customizer` functions.
2202 * @param {Object} object The destination object.
2203 * @param {Object} source The source object.
2204 * @returns {Object} Returns `object`.
2206 function baseAssign(object, source) {
2207 return object && copyObject(source, keys(source), object);
2211 * The base implementation of `_.at` without support for individual paths.
2214 * @param {Object} object The object to iterate over.
2215 * @param {string[]} paths The property paths of elements to pick.
2216 * @returns {Array} Returns the new array of picked elements.
2218 function baseAt(object, paths) {
2220 isNil = object == null,
2221 length = paths.length,
2222 result = Array(length);
2224 while (++index < length) {
2225 result[index] = isNil ? undefined : get(object, paths[index]);
2231 * The base implementation of `_.clamp` which doesn't coerce arguments to numbers.
2234 * @param {number} number The number to clamp.
2235 * @param {number} [lower] The lower bound.
2236 * @param {number} upper The upper bound.
2237 * @returns {number} Returns the clamped number.
2239 function baseClamp(number, lower, upper) {
2240 if (number === number) {
2241 if (upper !== undefined) {
2242 number = number <= upper ? number : upper;
2244 if (lower !== undefined) {
2245 number = number >= lower ? number : lower;
2252 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2253 * traversed objects.
2256 * @param {*} value The value to clone.
2257 * @param {boolean} [isDeep] Specify a deep clone.
2258 * @param {boolean} [isFull] Specify a clone including symbols.
2259 * @param {Function} [customizer] The function to customize cloning.
2260 * @param {string} [key] The key of `value`.
2261 * @param {Object} [object] The parent object of `value`.
2262 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2263 * @returns {*} Returns the cloned value.
2265 function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
2268 result = object ? customizer(value, key, object, stack) : customizer(value);
2270 if (result !== undefined) {
2273 if (!isObject(value)) {
2276 var isArr = isArray(value);
2278 result = initCloneArray(value);
2280 return copyArray(value, result);
2283 var tag = getTag(value),
2284 isFunc = tag == funcTag || tag == genTag;
2286 if (isBuffer(value)) {
2287 return cloneBuffer(value, isDeep);
2289 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2290 if (isHostObject(value)) {
2291 return object ? value : {};
2293 result = initCloneObject(isFunc ? {} : value);
2295 return copySymbols(value, baseAssign(result, value));
2298 if (!cloneableTags[tag]) {
2299 return object ? value : {};
2301 result = initCloneByTag(value, tag, baseClone, isDeep);
2304 // Check for circular references and return its corresponding clone.
2305 stack || (stack = new Stack);
2306 var stacked = stack.get(value);
2310 stack.set(value, result);
2313 var props = isFull ? getAllKeys(value) : keys(value);
2315 // Recursively populate clone (susceptible to call stack limits).
2316 arrayEach(props || value, function(subValue, key) {
2319 subValue = value[key];
2321 assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
2327 * The base implementation of `_.conforms` which doesn't clone `source`.
2330 * @param {Object} source The object of property predicates to conform to.
2331 * @returns {Function} Returns the new function.
2333 function baseConforms(source) {
2334 var props = keys(source),
2335 length = props.length;
2337 return function(object) {
2338 if (object == null) {
2343 var key = props[index],
2344 predicate = source[key],
2345 value = object[key];
2347 if ((value === undefined &&
2348 !(key in Object(object))) || !predicate(value)) {
2357 * The base implementation of `_.create` without support for assigning
2358 * properties to the created object.
2361 * @param {Object} prototype The object to inherit from.
2362 * @returns {Object} Returns the new object.
2364 function baseCreate(proto) {
2365 return isObject(proto) ? objectCreate(proto) : {};
2369 * The base implementation of `_.delay` and `_.defer` which accepts an array
2370 * of `func` arguments.
2373 * @param {Function} func The function to delay.
2374 * @param {number} wait The number of milliseconds to delay invocation.
2375 * @param {Object} args The arguments to provide to `func`.
2376 * @returns {number} Returns the timer id.
2378 function baseDelay(func, wait, args) {
2379 if (typeof func != 'function') {
2380 throw new TypeError(FUNC_ERROR_TEXT);
2382 return setTimeout(function() { func.apply(undefined, args); }, wait);
2386 * The base implementation of methods like `_.difference` without support
2387 * for excluding multiple arrays or iteratee shorthands.
2390 * @param {Array} array The array to inspect.
2391 * @param {Array} values The values to exclude.
2392 * @param {Function} [iteratee] The iteratee invoked per element.
2393 * @param {Function} [comparator] The comparator invoked per element.
2394 * @returns {Array} Returns the new array of filtered values.
2396 function baseDifference(array, values, iteratee, comparator) {
2398 includes = arrayIncludes,
2400 length = array.length,
2402 valuesLength = values.length;
2408 values = arrayMap(values, baseUnary(iteratee));
2411 includes = arrayIncludesWith;
2414 else if (values.length >= LARGE_ARRAY_SIZE) {
2415 includes = cacheHas;
2417 values = new SetCache(values);
2420 while (++index < length) {
2421 var value = array[index],
2422 computed = iteratee ? iteratee(value) : value;
2424 value = (comparator || value !== 0) ? value : 0;
2425 if (isCommon && computed === computed) {
2426 var valuesIndex = valuesLength;
2427 while (valuesIndex--) {
2428 if (values[valuesIndex] === computed) {
2434 else if (!includes(values, computed, comparator)) {
2442 * The base implementation of `_.forEach` without support for iteratee shorthands.
2445 * @param {Array|Object} collection The collection to iterate over.
2446 * @param {Function} iteratee The function invoked per iteration.
2447 * @returns {Array|Object} Returns `collection`.
2449 var baseEach = createBaseEach(baseForOwn);
2452 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2455 * @param {Array|Object} collection The collection to iterate over.
2456 * @param {Function} iteratee The function invoked per iteration.
2457 * @returns {Array|Object} Returns `collection`.
2459 var baseEachRight = createBaseEach(baseForOwnRight, true);
2462 * The base implementation of `_.every` without support for iteratee shorthands.
2465 * @param {Array|Object} collection The collection to iterate over.
2466 * @param {Function} predicate The function invoked per iteration.
2467 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2470 function baseEvery(collection, predicate) {
2472 baseEach(collection, function(value, index, collection) {
2473 result = !!predicate(value, index, collection);
2480 * The base implementation of methods like `_.max` and `_.min` which accepts a
2481 * `comparator` to determine the extremum value.
2484 * @param {Array} array The array to iterate over.
2485 * @param {Function} iteratee The iteratee invoked per iteration.
2486 * @param {Function} comparator The comparator used to compare values.
2487 * @returns {*} Returns the extremum value.
2489 function baseExtremum(array, iteratee, comparator) {
2491 length = array.length;
2493 while (++index < length) {
2494 var value = array[index],
2495 current = iteratee(value);
2497 if (current != null && (computed === undefined
2498 ? (current === current && !isSymbol(current))
2499 : comparator(current, computed)
2501 var computed = current,
2509 * The base implementation of `_.fill` without an iteratee call guard.
2512 * @param {Array} array The array to fill.
2513 * @param {*} value The value to fill `array` with.
2514 * @param {number} [start=0] The start position.
2515 * @param {number} [end=array.length] The end position.
2516 * @returns {Array} Returns `array`.
2518 function baseFill(array, value, start, end) {
2519 var length = array.length;
2521 start = toInteger(start);
2523 start = -start > length ? 0 : (length + start);
2525 end = (end === undefined || end > length) ? length : toInteger(end);
2529 end = start > end ? 0 : toLength(end);
2530 while (start < end) {
2531 array[start++] = value;
2537 * The base implementation of `_.filter` without support for iteratee shorthands.
2540 * @param {Array|Object} collection The collection to iterate over.
2541 * @param {Function} predicate The function invoked per iteration.
2542 * @returns {Array} Returns the new filtered array.
2544 function baseFilter(collection, predicate) {
2546 baseEach(collection, function(value, index, collection) {
2547 if (predicate(value, index, collection)) {
2555 * The base implementation of `_.flatten` with support for restricting flattening.
2558 * @param {Array} array The array to flatten.
2559 * @param {number} depth The maximum recursion depth.
2560 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
2561 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
2562 * @param {Array} [result=[]] The initial result value.
2563 * @returns {Array} Returns the new flattened array.
2565 function baseFlatten(array, depth, predicate, isStrict, result) {
2567 length = array.length;
2569 predicate || (predicate = isFlattenable);
2570 result || (result = []);
2572 while (++index < length) {
2573 var value = array[index];
2574 if (depth > 0 && predicate(value)) {
2576 // Recursively flatten arrays (susceptible to call stack limits).
2577 baseFlatten(value, depth - 1, predicate, isStrict, result);
2579 arrayPush(result, value);
2581 } else if (!isStrict) {
2582 result[result.length] = value;
2589 * The base implementation of `baseForOwn` which iterates over `object`
2590 * properties returned by `keysFunc` and invokes `iteratee` for each property.
2591 * Iteratee functions may exit iteration early by explicitly returning `false`.
2594 * @param {Object} object The object to iterate over.
2595 * @param {Function} iteratee The function invoked per iteration.
2596 * @param {Function} keysFunc The function to get the keys of `object`.
2597 * @returns {Object} Returns `object`.
2599 var baseFor = createBaseFor();
2602 * This function is like `baseFor` except that it iterates over properties
2603 * in the opposite order.
2606 * @param {Object} object The object to iterate over.
2607 * @param {Function} iteratee The function invoked per iteration.
2608 * @param {Function} keysFunc The function to get the keys of `object`.
2609 * @returns {Object} Returns `object`.
2611 var baseForRight = createBaseFor(true);
2614 * The base implementation of `_.forOwn` without support for iteratee shorthands.
2617 * @param {Object} object The object to iterate over.
2618 * @param {Function} iteratee The function invoked per iteration.
2619 * @returns {Object} Returns `object`.
2621 function baseForOwn(object, iteratee) {
2622 return object && baseFor(object, iteratee, keys);
2626 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
2629 * @param {Object} object The object to iterate over.
2630 * @param {Function} iteratee The function invoked per iteration.
2631 * @returns {Object} Returns `object`.
2633 function baseForOwnRight(object, iteratee) {
2634 return object && baseForRight(object, iteratee, keys);
2638 * The base implementation of `_.functions` which creates an array of
2639 * `object` function property names filtered from `props`.
2642 * @param {Object} object The object to inspect.
2643 * @param {Array} props The property names to filter.
2644 * @returns {Array} Returns the new array of filtered property names.
2646 function baseFunctions(object, props) {
2647 return arrayFilter(props, function(key) {
2648 return isFunction(object[key]);
2653 * The base implementation of `_.get` without support for default values.
2656 * @param {Object} object The object to query.
2657 * @param {Array|string} path The path of the property to get.
2658 * @returns {*} Returns the resolved value.
2660 function baseGet(object, path) {
2661 path = isKey(path, object) ? [path] : castPath(path);
2664 length = path.length;
2666 while (object != null && index < length) {
2667 object = object[toKey(path[index++])];
2669 return (index && index == length) ? object : undefined;
2673 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
2674 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
2675 * symbols of `object`.
2678 * @param {Object} object The object to query.
2679 * @param {Function} keysFunc The function to get the keys of `object`.
2680 * @param {Function} symbolsFunc The function to get the symbols of `object`.
2681 * @returns {Array} Returns the array of property names and symbols.
2683 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
2684 var result = keysFunc(object);
2685 return isArray(object)
2687 : arrayPush(result, symbolsFunc(object));
2691 * The base implementation of `_.gt` which doesn't coerce arguments to numbers.
2694 * @param {*} value The value to compare.
2695 * @param {*} other The other value to compare.
2696 * @returns {boolean} Returns `true` if `value` is greater than `other`,
2699 function baseGt(value, other) {
2700 return value > other;
2704 * The base implementation of `_.has` without support for deep paths.
2707 * @param {Object} object The object to query.
2708 * @param {Array|string} key The key to check.
2709 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2711 function baseHas(object, key) {
2712 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
2713 // that are composed entirely of index properties, return `false` for
2714 // `hasOwnProperty` checks of them.
2715 return hasOwnProperty.call(object, key) ||
2716 (typeof object == 'object' && key in object && getPrototype(object) === null);
2720 * The base implementation of `_.hasIn` without support for deep paths.
2723 * @param {Object} object The object to query.
2724 * @param {Array|string} key The key to check.
2725 * @returns {boolean} Returns `true` if `key` exists, else `false`.
2727 function baseHasIn(object, key) {
2728 return key in Object(object);
2732 * The base implementation of `_.inRange` which doesn't coerce arguments to numbers.
2735 * @param {number} number The number to check.
2736 * @param {number} start The start of the range.
2737 * @param {number} end The end of the range.
2738 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
2740 function baseInRange(number, start, end) {
2741 return number >= nativeMin(start, end) && number < nativeMax(start, end);
2745 * The base implementation of methods like `_.intersection`, without support
2746 * for iteratee shorthands, that accepts an array of arrays to inspect.
2749 * @param {Array} arrays The arrays to inspect.
2750 * @param {Function} [iteratee] The iteratee invoked per element.
2751 * @param {Function} [comparator] The comparator invoked per element.
2752 * @returns {Array} Returns the new array of shared values.
2754 function baseIntersection(arrays, iteratee, comparator) {
2755 var includes = comparator ? arrayIncludesWith : arrayIncludes,
2756 length = arrays[0].length,
2757 othLength = arrays.length,
2758 othIndex = othLength,
2759 caches = Array(othLength),
2760 maxLength = Infinity,
2763 while (othIndex--) {
2764 var array = arrays[othIndex];
2765 if (othIndex && iteratee) {
2766 array = arrayMap(array, baseUnary(iteratee));
2768 maxLength = nativeMin(array.length, maxLength);
2769 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
2770 ? new SetCache(othIndex && array)
2779 while (++index < length && result.length < maxLength) {
2780 var value = array[index],
2781 computed = iteratee ? iteratee(value) : value;
2783 value = (comparator || value !== 0) ? value : 0;
2785 ? cacheHas(seen, computed)
2786 : includes(result, computed, comparator)
2788 othIndex = othLength;
2789 while (--othIndex) {
2790 var cache = caches[othIndex];
2792 ? cacheHas(cache, computed)
2793 : includes(arrays[othIndex], computed, comparator))
2799 seen.push(computed);
2808 * The base implementation of `_.invert` and `_.invertBy` which inverts
2809 * `object` with values transformed by `iteratee` and set by `setter`.
2812 * @param {Object} object The object to iterate over.
2813 * @param {Function} setter The function to set `accumulator` values.
2814 * @param {Function} iteratee The iteratee to transform values.
2815 * @param {Object} accumulator The initial inverted object.
2816 * @returns {Function} Returns `accumulator`.
2818 function baseInverter(object, setter, iteratee, accumulator) {
2819 baseForOwn(object, function(value, key, object) {
2820 setter(accumulator, iteratee(value), key, object);
2826 * The base implementation of `_.invoke` without support for individual
2830 * @param {Object} object The object to query.
2831 * @param {Array|string} path The path of the method to invoke.
2832 * @param {Array} args The arguments to invoke the method with.
2833 * @returns {*} Returns the result of the invoked method.
2835 function baseInvoke(object, path, args) {
2836 if (!isKey(path, object)) {
2837 path = castPath(path);
2838 object = parent(object, path);
2841 var func = object == null ? object : object[toKey(path)];
2842 return func == null ? undefined : apply(func, object, args);
2846 * The base implementation of `_.isEqual` which supports partial comparisons
2847 * and tracks traversed objects.
2850 * @param {*} value The value to compare.
2851 * @param {*} other The other value to compare.
2852 * @param {Function} [customizer] The function to customize comparisons.
2853 * @param {boolean} [bitmask] The bitmask of comparison flags.
2854 * The bitmask may be composed of the following flags:
2855 * 1 - Unordered comparison
2856 * 2 - Partial comparison
2857 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
2858 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2860 function baseIsEqual(value, other, customizer, bitmask, stack) {
2861 if (value === other) {
2864 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2865 return value !== value && other !== other;
2867 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
2871 * A specialized version of `baseIsEqual` for arrays and objects which performs
2872 * deep comparisons and tracks traversed objects enabling objects with circular
2873 * references to be compared.
2876 * @param {Object} object The object to compare.
2877 * @param {Object} other The other object to compare.
2878 * @param {Function} equalFunc The function to determine equivalents of values.
2879 * @param {Function} [customizer] The function to customize comparisons.
2880 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
2882 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
2883 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2885 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
2886 var objIsArr = isArray(object),
2887 othIsArr = isArray(other),
2892 objTag = getTag(object);
2893 objTag = objTag == argsTag ? objectTag : objTag;
2896 othTag = getTag(other);
2897 othTag = othTag == argsTag ? objectTag : othTag;
2899 var objIsObj = objTag == objectTag && !isHostObject(object),
2900 othIsObj = othTag == objectTag && !isHostObject(other),
2901 isSameTag = objTag == othTag;
2903 if (isSameTag && !objIsObj) {
2904 stack || (stack = new Stack);
2905 return (objIsArr || isTypedArray(object))
2906 ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
2907 : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
2909 if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
2910 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2911 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2913 if (objIsWrapped || othIsWrapped) {
2914 var objUnwrapped = objIsWrapped ? object.value() : object,
2915 othUnwrapped = othIsWrapped ? other.value() : other;
2917 stack || (stack = new Stack);
2918 return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
2924 stack || (stack = new Stack);
2925 return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
2929 * The base implementation of `_.isMatch` without support for iteratee shorthands.
2932 * @param {Object} object The object to inspect.
2933 * @param {Object} source The object of property values to match.
2934 * @param {Array} matchData The property names, values, and compare flags to match.
2935 * @param {Function} [customizer] The function to customize comparisons.
2936 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2938 function baseIsMatch(object, source, matchData, customizer) {
2939 var index = matchData.length,
2941 noCustomizer = !customizer;
2943 if (object == null) {
2946 object = Object(object);
2948 var data = matchData[index];
2949 if ((noCustomizer && data[2])
2950 ? data[1] !== object[data[0]]
2951 : !(data[0] in object)
2956 while (++index < length) {
2957 data = matchData[index];
2959 objValue = object[key],
2962 if (noCustomizer && data[2]) {
2963 if (objValue === undefined && !(key in object)) {
2967 var stack = new Stack;
2969 var result = customizer(objValue, srcValue, key, object, source, stack);
2971 if (!(result === undefined
2972 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
2983 * The base implementation of `_.iteratee`.
2986 * @param {*} [value=_.identity] The value to convert to an iteratee.
2987 * @returns {Function} Returns the iteratee.
2989 function baseIteratee(value) {
2990 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
2991 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
2992 if (typeof value == 'function') {
2995 if (value == null) {
2998 if (typeof value == 'object') {
2999 return isArray(value)
3000 ? baseMatchesProperty(value[0], value[1])
3001 : baseMatches(value);
3003 return property(value);
3007 * The base implementation of `_.keys` which doesn't skip the constructor
3008 * property of prototypes or treat sparse arrays as dense.
3011 * @param {Object} object The object to query.
3012 * @returns {Array} Returns the array of property names.
3014 function baseKeys(object) {
3015 return nativeKeys(Object(object));
3019 * The base implementation of `_.keysIn` which doesn't skip the constructor
3020 * property of prototypes or treat sparse arrays as dense.
3023 * @param {Object} object The object to query.
3024 * @returns {Array} Returns the array of property names.
3026 function baseKeysIn(object) {
3027 object = object == null ? object : Object(object);
3030 for (var key in object) {
3036 // Fallback for IE < 9 with es6-shim.
3037 if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
3038 baseKeysIn = function(object) {
3039 return iteratorToArray(enumerate(object));
3044 * The base implementation of `_.lt` which doesn't coerce arguments to numbers.
3047 * @param {*} value The value to compare.
3048 * @param {*} other The other value to compare.
3049 * @returns {boolean} Returns `true` if `value` is less than `other`,
3052 function baseLt(value, other) {
3053 return value < other;
3057 * The base implementation of `_.map` without support for iteratee shorthands.
3060 * @param {Array|Object} collection The collection to iterate over.
3061 * @param {Function} iteratee The function invoked per iteration.
3062 * @returns {Array} Returns the new mapped array.
3064 function baseMap(collection, iteratee) {
3066 result = isArrayLike(collection) ? Array(collection.length) : [];
3068 baseEach(collection, function(value, key, collection) {
3069 result[++index] = iteratee(value, key, collection);
3075 * The base implementation of `_.matches` which doesn't clone `source`.
3078 * @param {Object} source The object of property values to match.
3079 * @returns {Function} Returns the new function.
3081 function baseMatches(source) {
3082 var matchData = getMatchData(source);
3083 if (matchData.length == 1 && matchData[0][2]) {
3084 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3086 return function(object) {
3087 return object === source || baseIsMatch(object, source, matchData);
3092 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3095 * @param {string} path The path of the property to get.
3096 * @param {*} srcValue The value to match.
3097 * @returns {Function} Returns the new function.
3099 function baseMatchesProperty(path, srcValue) {
3100 if (isKey(path) && isStrictComparable(srcValue)) {
3101 return matchesStrictComparable(toKey(path), srcValue);
3103 return function(object) {
3104 var objValue = get(object, path);
3105 return (objValue === undefined && objValue === srcValue)
3106 ? hasIn(object, path)
3107 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
3112 * The base implementation of `_.merge` without support for multiple sources.
3115 * @param {Object} object The destination object.
3116 * @param {Object} source The source object.
3117 * @param {number} srcIndex The index of `source`.
3118 * @param {Function} [customizer] The function to customize merged values.
3119 * @param {Object} [stack] Tracks traversed source values and their merged
3122 function baseMerge(object, source, srcIndex, customizer, stack) {
3123 if (object === source) {
3126 if (!(isArray(source) || isTypedArray(source))) {
3127 var props = keysIn(source);
3129 arrayEach(props || source, function(srcValue, key) {
3132 srcValue = source[key];
3134 if (isObject(srcValue)) {
3135 stack || (stack = new Stack);
3136 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3139 var newValue = customizer
3140 ? customizer(object[key], srcValue, (key + ''), object, source, stack)
3143 if (newValue === undefined) {
3144 newValue = srcValue;
3146 assignMergeValue(object, key, newValue);
3152 * A specialized version of `baseMerge` for arrays and objects which performs
3153 * deep merges and tracks traversed objects enabling objects with circular
3154 * references to be merged.
3157 * @param {Object} object The destination object.
3158 * @param {Object} source The source object.
3159 * @param {string} key The key of the value to merge.
3160 * @param {number} srcIndex The index of `source`.
3161 * @param {Function} mergeFunc The function to merge values.
3162 * @param {Function} [customizer] The function to customize assigned values.
3163 * @param {Object} [stack] Tracks traversed source values and their merged
3166 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3167 var objValue = object[key],
3168 srcValue = source[key],
3169 stacked = stack.get(srcValue);
3172 assignMergeValue(object, key, stacked);
3175 var newValue = customizer
3176 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3179 var isCommon = newValue === undefined;
3182 newValue = srcValue;
3183 if (isArray(srcValue) || isTypedArray(srcValue)) {
3184 if (isArray(objValue)) {
3185 newValue = objValue;
3187 else if (isArrayLikeObject(objValue)) {
3188 newValue = copyArray(objValue);
3192 newValue = baseClone(srcValue, true);
3195 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3196 if (isArguments(objValue)) {
3197 newValue = toPlainObject(objValue);
3199 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3201 newValue = baseClone(srcValue, true);
3204 newValue = objValue;
3211 stack.set(srcValue, newValue);
3214 // Recursively merge objects and arrays (susceptible to call stack limits).
3215 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3217 stack['delete'](srcValue);
3218 assignMergeValue(object, key, newValue);
3222 * The base implementation of `_.nth` which doesn't coerce `n` to an integer.
3225 * @param {Array} array The array to query.
3226 * @param {number} n The index of the element to return.
3227 * @returns {*} Returns the nth element of `array`.
3229 function baseNth(array, n) {
3230 var length = array.length;
3234 n += n < 0 ? length : 0;
3235 return isIndex(n, length) ? array[n] : undefined;
3239 * The base implementation of `_.orderBy` without param guards.
3242 * @param {Array|Object} collection The collection to iterate over.
3243 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3244 * @param {string[]} orders The sort orders of `iteratees`.
3245 * @returns {Array} Returns the new sorted array.
3247 function baseOrderBy(collection, iteratees, orders) {
3249 iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
3251 var result = baseMap(collection, function(value, key, collection) {
3252 var criteria = arrayMap(iteratees, function(iteratee) {
3253 return iteratee(value);
3255 return { 'criteria': criteria, 'index': ++index, 'value': value };
3258 return baseSortBy(result, function(object, other) {
3259 return compareMultiple(object, other, orders);
3264 * The base implementation of `_.pick` without support for individual
3265 * property identifiers.
3268 * @param {Object} object The source object.
3269 * @param {string[]} props The property identifiers to pick.
3270 * @returns {Object} Returns the new object.
3272 function basePick(object, props) {
3273 object = Object(object);
3274 return arrayReduce(props, function(result, key) {
3275 if (key in object) {
3276 result[key] = object[key];
3283 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3286 * @param {Object} object The source object.
3287 * @param {Function} predicate The function invoked per property.
3288 * @returns {Object} Returns the new object.
3290 function basePickBy(object, predicate) {
3292 props = getAllKeysIn(object),
3293 length = props.length,
3296 while (++index < length) {
3297 var key = props[index],
3298 value = object[key];
3300 if (predicate(value, key)) {
3301 result[key] = value;
3308 * The base implementation of `_.property` without support for deep paths.
3311 * @param {string} key The key of the property to get.
3312 * @returns {Function} Returns the new function.
3314 function baseProperty(key) {
3315 return function(object) {
3316 return object == null ? undefined : object[key];
3321 * A specialized version of `baseProperty` which supports deep paths.
3324 * @param {Array|string} path The path of the property to get.
3325 * @returns {Function} Returns the new function.
3327 function basePropertyDeep(path) {
3328 return function(object) {
3329 return baseGet(object, path);
3334 * The base implementation of `_.pullAllBy` without support for iteratee
3338 * @param {Array} array The array to modify.
3339 * @param {Array} values The values to remove.
3340 * @param {Function} [iteratee] The iteratee invoked per element.
3341 * @param {Function} [comparator] The comparator invoked per element.
3342 * @returns {Array} Returns `array`.
3344 function basePullAll(array, values, iteratee, comparator) {
3345 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3347 length = values.length,
3351 seen = arrayMap(array, baseUnary(iteratee));
3353 while (++index < length) {
3355 value = values[index],
3356 computed = iteratee ? iteratee(value) : value;
3358 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3359 if (seen !== array) {
3360 splice.call(seen, fromIndex, 1);
3362 splice.call(array, fromIndex, 1);
3369 * The base implementation of `_.pullAt` without support for individual
3370 * indexes or capturing the removed elements.
3373 * @param {Array} array The array to modify.
3374 * @param {number[]} indexes The indexes of elements to remove.
3375 * @returns {Array} Returns `array`.
3377 function basePullAt(array, indexes) {
3378 var length = array ? indexes.length : 0,
3379 lastIndex = length - 1;
3382 var index = indexes[length];
3383 if (length == lastIndex || index !== previous) {
3384 var previous = index;
3385 if (isIndex(index)) {
3386 splice.call(array, index, 1);
3388 else if (!isKey(index, array)) {
3389 var path = castPath(index),
3390 object = parent(array, path);
3392 if (object != null) {
3393 delete object[toKey(last(path))];
3397 delete array[toKey(index)];
3405 * The base implementation of `_.random` without support for returning
3406 * floating-point numbers.
3409 * @param {number} lower The lower bound.
3410 * @param {number} upper The upper bound.
3411 * @returns {number} Returns the random number.
3413 function baseRandom(lower, upper) {
3414 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3418 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3419 * coerce arguments to numbers.
3422 * @param {number} start The start of the range.
3423 * @param {number} end The end of the range.
3424 * @param {number} step The value to increment or decrement by.
3425 * @param {boolean} [fromRight] Specify iterating from right to left.
3426 * @returns {Array} Returns the new array of numbers.
3428 function baseRange(start, end, step, fromRight) {
3430 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3431 result = Array(length);
3434 result[fromRight ? length : ++index] = start;
3441 * The base implementation of `_.repeat` which doesn't coerce arguments.
3444 * @param {string} string The string to repeat.
3445 * @param {number} n The number of times to repeat the string.
3446 * @returns {string} Returns the repeated string.
3448 function baseRepeat(string, n) {
3450 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3453 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3454 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3459 n = nativeFloor(n / 2);
3469 * The base implementation of `_.set`.
3472 * @param {Object} object The object to query.
3473 * @param {Array|string} path The path of the property to set.
3474 * @param {*} value The value to set.
3475 * @param {Function} [customizer] The function to customize path creation.
3476 * @returns {Object} Returns `object`.
3478 function baseSet(object, path, value, customizer) {
3479 path = isKey(path, object) ? [path] : castPath(path);
3482 length = path.length,
3483 lastIndex = length - 1,
3486 while (nested != null && ++index < length) {
3487 var key = toKey(path[index]);
3488 if (isObject(nested)) {
3489 var newValue = value;
3490 if (index != lastIndex) {
3491 var objValue = nested[key];
3492 newValue = customizer ? customizer(objValue, key, nested) : undefined;
3493 if (newValue === undefined) {
3494 newValue = objValue == null
3495 ? (isIndex(path[index + 1]) ? [] : {})
3499 assignValue(nested, key, newValue);
3501 nested = nested[key];
3507 * The base implementation of `setData` without support for hot loop detection.
3510 * @param {Function} func The function to associate metadata with.
3511 * @param {*} data The metadata.
3512 * @returns {Function} Returns `func`.
3514 var baseSetData = !metaMap ? identity : function(func, data) {
3515 metaMap.set(func, data);
3520 * The base implementation of `_.slice` without an iteratee call guard.
3523 * @param {Array} array The array to slice.
3524 * @param {number} [start=0] The start position.
3525 * @param {number} [end=array.length] The end position.
3526 * @returns {Array} Returns the slice of `array`.
3528 function baseSlice(array, start, end) {
3530 length = array.length;
3533 start = -start > length ? 0 : (length + start);
3535 end = end > length ? length : end;
3539 length = start > end ? 0 : ((end - start) >>> 0);
3542 var result = Array(length);
3543 while (++index < length) {
3544 result[index] = array[index + start];
3550 * The base implementation of `_.some` without support for iteratee shorthands.
3553 * @param {Array|Object} collection The collection to iterate over.
3554 * @param {Function} predicate The function invoked per iteration.
3555 * @returns {boolean} Returns `true` if any element passes the predicate check,
3558 function baseSome(collection, predicate) {
3561 baseEach(collection, function(value, index, collection) {
3562 result = predicate(value, index, collection);
3569 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
3570 * performs a binary search of `array` to determine the index at which `value`
3571 * should be inserted into `array` in order to maintain its sort order.
3574 * @param {Array} array The sorted array to inspect.
3575 * @param {*} value The value to evaluate.
3576 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3577 * @returns {number} Returns the index at which `value` should be inserted
3580 function baseSortedIndex(array, value, retHighest) {
3582 high = array ? array.length : low;
3584 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
3585 while (low < high) {
3586 var mid = (low + high) >>> 1,
3587 computed = array[mid];
3589 if (computed !== null && !isSymbol(computed) &&
3590 (retHighest ? (computed <= value) : (computed < value))) {
3598 return baseSortedIndexBy(array, value, identity, retHighest);
3602 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
3603 * which invokes `iteratee` for `value` and each element of `array` to compute
3604 * their sort ranking. The iteratee is invoked with one argument; (value).
3607 * @param {Array} array The sorted array to inspect.
3608 * @param {*} value The value to evaluate.
3609 * @param {Function} iteratee The iteratee invoked per element.
3610 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3611 * @returns {number} Returns the index at which `value` should be inserted
3614 function baseSortedIndexBy(array, value, iteratee, retHighest) {
3615 value = iteratee(value);
3618 high = array ? array.length : 0,
3619 valIsNaN = value !== value,
3620 valIsNull = value === null,
3621 valIsSymbol = isSymbol(value),
3622 valIsUndefined = value === undefined;
3624 while (low < high) {
3625 var mid = nativeFloor((low + high) / 2),
3626 computed = iteratee(array[mid]),
3627 othIsDefined = computed !== undefined,
3628 othIsNull = computed === null,
3629 othIsReflexive = computed === computed,
3630 othIsSymbol = isSymbol(computed);
3633 var setLow = retHighest || othIsReflexive;
3634 } else if (valIsUndefined) {
3635 setLow = othIsReflexive && (retHighest || othIsDefined);
3636 } else if (valIsNull) {
3637 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
3638 } else if (valIsSymbol) {
3639 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
3640 } else if (othIsNull || othIsSymbol) {
3643 setLow = retHighest ? (computed <= value) : (computed < value);
3651 return nativeMin(high, MAX_ARRAY_INDEX);
3655 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
3656 * support for iteratee shorthands.
3659 * @param {Array} array The array to inspect.
3660 * @param {Function} [iteratee] The iteratee invoked per element.
3661 * @returns {Array} Returns the new duplicate free array.
3663 function baseSortedUniq(array, iteratee) {
3665 length = array.length,
3669 while (++index < length) {
3670 var value = array[index],
3671 computed = iteratee ? iteratee(value) : value;
3673 if (!index || !eq(computed, seen)) {
3674 var seen = computed;
3675 result[resIndex++] = value === 0 ? 0 : value;
3682 * The base implementation of `_.toNumber` which doesn't ensure correct
3683 * conversions of binary, hexadecimal, or octal string values.
3686 * @param {*} value The value to process.
3687 * @returns {number} Returns the number.
3689 function baseToNumber(value) {
3690 if (typeof value == 'number') {
3693 if (isSymbol(value)) {
3700 * The base implementation of `_.toString` which doesn't convert nullish
3701 * values to empty strings.
3704 * @param {*} value The value to process.
3705 * @returns {string} Returns the string.
3707 function baseToString(value) {
3708 // Exit early for strings to avoid a performance hit in some environments.
3709 if (typeof value == 'string') {
3712 if (isSymbol(value)) {
3713 return symbolToString ? symbolToString.call(value) : '';
3715 var result = (value + '');
3716 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
3720 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
3723 * @param {Array} array The array to inspect.
3724 * @param {Function} [iteratee] The iteratee invoked per element.
3725 * @param {Function} [comparator] The comparator invoked per element.
3726 * @returns {Array} Returns the new duplicate free array.
3728 function baseUniq(array, iteratee, comparator) {
3730 includes = arrayIncludes,
3731 length = array.length,
3738 includes = arrayIncludesWith;
3740 else if (length >= LARGE_ARRAY_SIZE) {
3741 var set = iteratee ? null : createSet(array);
3743 return setToArray(set);
3746 includes = cacheHas;
3747 seen = new SetCache;
3750 seen = iteratee ? [] : result;
3753 while (++index < length) {
3754 var value = array[index],
3755 computed = iteratee ? iteratee(value) : value;
3757 value = (comparator || value !== 0) ? value : 0;
3758 if (isCommon && computed === computed) {
3759 var seenIndex = seen.length;
3760 while (seenIndex--) {
3761 if (seen[seenIndex] === computed) {
3766 seen.push(computed);
3770 else if (!includes(seen, computed, comparator)) {
3771 if (seen !== result) {
3772 seen.push(computed);
3781 * The base implementation of `_.unset`.
3784 * @param {Object} object The object to modify.
3785 * @param {Array|string} path The path of the property to unset.
3786 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
3788 function baseUnset(object, path) {
3789 path = isKey(path, object) ? [path] : castPath(path);
3790 object = parent(object, path);
3792 var key = toKey(last(path));
3793 return !(object != null && baseHas(object, key)) || delete object[key];
3797 * The base implementation of `_.update`.
3800 * @param {Object} object The object to query.
3801 * @param {Array|string} path The path of the property to update.
3802 * @param {Function} updater The function to produce the updated value.
3803 * @param {Function} [customizer] The function to customize path creation.
3804 * @returns {Object} Returns `object`.
3806 function baseUpdate(object, path, updater, customizer) {
3807 return baseSet(object, path, updater(baseGet(object, path)), customizer);
3811 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
3812 * without support for iteratee shorthands.
3815 * @param {Array} array The array to query.
3816 * @param {Function} predicate The function invoked per iteration.
3817 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
3818 * @param {boolean} [fromRight] Specify iterating from right to left.
3819 * @returns {Array} Returns the slice of `array`.
3821 function baseWhile(array, predicate, isDrop, fromRight) {
3822 var length = array.length,
3823 index = fromRight ? length : -1;
3825 while ((fromRight ? index-- : ++index < length) &&
3826 predicate(array[index], index, array)) {}
3829 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
3830 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
3834 * The base implementation of `wrapperValue` which returns the result of
3835 * performing a sequence of actions on the unwrapped `value`, where each
3836 * successive action is supplied the return value of the previous.
3839 * @param {*} value The unwrapped value.
3840 * @param {Array} actions Actions to perform to resolve the unwrapped value.
3841 * @returns {*} Returns the resolved value.
3843 function baseWrapperValue(value, actions) {
3845 if (result instanceof LazyWrapper) {
3846 result = result.value();
3848 return arrayReduce(actions, function(result, action) {
3849 return action.func.apply(action.thisArg, arrayPush([result], action.args));
3854 * The base implementation of methods like `_.xor`, without support for
3855 * iteratee shorthands, that accepts an array of arrays to inspect.
3858 * @param {Array} arrays The arrays to inspect.
3859 * @param {Function} [iteratee] The iteratee invoked per element.
3860 * @param {Function} [comparator] The comparator invoked per element.
3861 * @returns {Array} Returns the new array of values.
3863 function baseXor(arrays, iteratee, comparator) {
3865 length = arrays.length;
3867 while (++index < length) {
3870 baseDifference(result, arrays[index], iteratee, comparator),
3871 baseDifference(arrays[index], result, iteratee, comparator)
3875 return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
3879 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
3882 * @param {Array} props The property identifiers.
3883 * @param {Array} values The property values.
3884 * @param {Function} assignFunc The function to assign values.
3885 * @returns {Object} Returns the new object.
3887 function baseZipObject(props, values, assignFunc) {
3889 length = props.length,
3890 valsLength = values.length,
3893 while (++index < length) {
3894 var value = index < valsLength ? values[index] : undefined;
3895 assignFunc(result, props[index], value);
3901 * Casts `value` to an empty array if it's not an array like object.
3904 * @param {*} value The value to inspect.
3905 * @returns {Array|Object} Returns the cast array-like object.
3907 function castArrayLikeObject(value) {
3908 return isArrayLikeObject(value) ? value : [];
3912 * Casts `value` to `identity` if it's not a function.
3915 * @param {*} value The value to inspect.
3916 * @returns {Function} Returns cast function.
3918 function castFunction(value) {
3919 return typeof value == 'function' ? value : identity;
3923 * Casts `value` to a path array if it's not one.
3926 * @param {*} value The value to inspect.
3927 * @returns {Array} Returns the cast property path array.
3929 function castPath(value) {
3930 return isArray(value) ? value : stringToPath(value);
3934 * Casts `array` to a slice if it's needed.
3937 * @param {Array} array The array to inspect.
3938 * @param {number} start The start position.
3939 * @param {number} [end=array.length] The end position.
3940 * @returns {Array} Returns the cast slice.
3942 function castSlice(array, start, end) {
3943 var length = array.length;
3944 end = end === undefined ? length : end;
3945 return (!start && end >= length) ? array : baseSlice(array, start, end);
3949 * Creates a clone of `buffer`.
3952 * @param {Buffer} buffer The buffer to clone.
3953 * @param {boolean} [isDeep] Specify a deep clone.
3954 * @returns {Buffer} Returns the cloned buffer.
3956 function cloneBuffer(buffer, isDeep) {
3958 return buffer.slice();
3960 var result = new buffer.constructor(buffer.length);
3961 buffer.copy(result);
3966 * Creates a clone of `arrayBuffer`.
3969 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
3970 * @returns {ArrayBuffer} Returns the cloned array buffer.
3972 function cloneArrayBuffer(arrayBuffer) {
3973 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
3974 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
3979 * Creates a clone of `dataView`.
3982 * @param {Object} dataView The data view to clone.
3983 * @param {boolean} [isDeep] Specify a deep clone.
3984 * @returns {Object} Returns the cloned data view.
3986 function cloneDataView(dataView, isDeep) {
3987 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
3988 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
3992 * Creates a clone of `map`.
3995 * @param {Object} map The map to clone.
3996 * @param {Function} cloneFunc The function to clone values.
3997 * @param {boolean} [isDeep] Specify a deep clone.
3998 * @returns {Object} Returns the cloned map.
4000 function cloneMap(map, isDeep, cloneFunc) {
4001 var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
4002 return arrayReduce(array, addMapEntry, new map.constructor);
4006 * Creates a clone of `regexp`.
4009 * @param {Object} regexp The regexp to clone.
4010 * @returns {Object} Returns the cloned regexp.
4012 function cloneRegExp(regexp) {
4013 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4014 result.lastIndex = regexp.lastIndex;
4019 * Creates a clone of `set`.
4022 * @param {Object} set The set to clone.
4023 * @param {Function} cloneFunc The function to clone values.
4024 * @param {boolean} [isDeep] Specify a deep clone.
4025 * @returns {Object} Returns the cloned set.
4027 function cloneSet(set, isDeep, cloneFunc) {
4028 var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
4029 return arrayReduce(array, addSetEntry, new set.constructor);
4033 * Creates a clone of the `symbol` object.
4036 * @param {Object} symbol The symbol object to clone.
4037 * @returns {Object} Returns the cloned symbol object.
4039 function cloneSymbol(symbol) {
4040 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4044 * Creates a clone of `typedArray`.
4047 * @param {Object} typedArray The typed array to clone.
4048 * @param {boolean} [isDeep] Specify a deep clone.
4049 * @returns {Object} Returns the cloned typed array.
4051 function cloneTypedArray(typedArray, isDeep) {
4052 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4053 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4057 * Compares values to sort them in ascending order.
4060 * @param {*} value The value to compare.
4061 * @param {*} other The other value to compare.
4062 * @returns {number} Returns the sort order indicator for `value`.
4064 function compareAscending(value, other) {
4065 if (value !== other) {
4066 var valIsDefined = value !== undefined,
4067 valIsNull = value === null,
4068 valIsReflexive = value === value,
4069 valIsSymbol = isSymbol(value);
4071 var othIsDefined = other !== undefined,
4072 othIsNull = other === null,
4073 othIsReflexive = other === other,
4074 othIsSymbol = isSymbol(other);
4076 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4077 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4078 (valIsNull && othIsDefined && othIsReflexive) ||
4079 (!valIsDefined && othIsReflexive) ||
4083 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4084 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4085 (othIsNull && valIsDefined && valIsReflexive) ||
4086 (!othIsDefined && valIsReflexive) ||
4095 * Used by `_.orderBy` to compare multiple properties of a value to another
4096 * and stable sort them.
4098 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4099 * specify an order of "desc" for descending or "asc" for ascending sort order
4100 * of corresponding values.
4103 * @param {Object} object The object to compare.
4104 * @param {Object} other The other object to compare.
4105 * @param {boolean[]|string[]} orders The order to sort by for each property.
4106 * @returns {number} Returns the sort order indicator for `object`.
4108 function compareMultiple(object, other, orders) {
4110 objCriteria = object.criteria,
4111 othCriteria = other.criteria,
4112 length = objCriteria.length,
4113 ordersLength = orders.length;
4115 while (++index < length) {
4116 var result = compareAscending(objCriteria[index], othCriteria[index]);
4118 if (index >= ordersLength) {
4121 var order = orders[index];
4122 return result * (order == 'desc' ? -1 : 1);
4125 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4126 // that causes it, under certain circumstances, to provide the same value for
4127 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4128 // for more details.
4130 // This also ensures a stable sort in V8 and other engines.
4131 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4132 return object.index - other.index;
4136 * Creates an array that is the composition of partially applied arguments,
4137 * placeholders, and provided arguments into a single array of arguments.
4140 * @param {Array|Object} args The provided arguments.
4141 * @param {Array} partials The arguments to prepend to those provided.
4142 * @param {Array} holders The `partials` placeholder indexes.
4143 * @params {boolean} [isCurried] Specify composing for a curried function.
4144 * @returns {Array} Returns the new array of composed arguments.
4146 function composeArgs(args, partials, holders, isCurried) {
4148 argsLength = args.length,
4149 holdersLength = holders.length,
4151 leftLength = partials.length,
4152 rangeLength = nativeMax(argsLength - holdersLength, 0),
4153 result = Array(leftLength + rangeLength),
4154 isUncurried = !isCurried;
4156 while (++leftIndex < leftLength) {
4157 result[leftIndex] = partials[leftIndex];
4159 while (++argsIndex < holdersLength) {
4160 if (isUncurried || argsIndex < argsLength) {
4161 result[holders[argsIndex]] = args[argsIndex];
4164 while (rangeLength--) {
4165 result[leftIndex++] = args[argsIndex++];
4171 * This function is like `composeArgs` except that the arguments composition
4172 * is tailored for `_.partialRight`.
4175 * @param {Array|Object} args The provided arguments.
4176 * @param {Array} partials The arguments to append to those provided.
4177 * @param {Array} holders The `partials` placeholder indexes.
4178 * @params {boolean} [isCurried] Specify composing for a curried function.
4179 * @returns {Array} Returns the new array of composed arguments.
4181 function composeArgsRight(args, partials, holders, isCurried) {
4183 argsLength = args.length,
4185 holdersLength = holders.length,
4187 rightLength = partials.length,
4188 rangeLength = nativeMax(argsLength - holdersLength, 0),
4189 result = Array(rangeLength + rightLength),
4190 isUncurried = !isCurried;
4192 while (++argsIndex < rangeLength) {
4193 result[argsIndex] = args[argsIndex];
4195 var offset = argsIndex;
4196 while (++rightIndex < rightLength) {
4197 result[offset + rightIndex] = partials[rightIndex];
4199 while (++holdersIndex < holdersLength) {
4200 if (isUncurried || argsIndex < argsLength) {
4201 result[offset + holders[holdersIndex]] = args[argsIndex++];
4208 * Copies the values of `source` to `array`.
4211 * @param {Array} source The array to copy values from.
4212 * @param {Array} [array=[]] The array to copy values to.
4213 * @returns {Array} Returns `array`.
4215 function copyArray(source, array) {
4217 length = source.length;
4219 array || (array = Array(length));
4220 while (++index < length) {
4221 array[index] = source[index];
4227 * Copies properties of `source` to `object`.
4230 * @param {Object} source The object to copy properties from.
4231 * @param {Array} props The property identifiers to copy.
4232 * @param {Object} [object={}] The object to copy properties to.
4233 * @param {Function} [customizer] The function to customize copied values.
4234 * @returns {Object} Returns `object`.
4236 function copyObject(source, props, object, customizer) {
4237 object || (object = {});
4240 length = props.length;
4242 while (++index < length) {
4243 var key = props[index];
4245 var newValue = customizer
4246 ? customizer(object[key], source[key], key, object, source)
4249 assignValue(object, key, newValue);
4255 * Copies own symbol properties of `source` to `object`.
4258 * @param {Object} source The object to copy symbols from.
4259 * @param {Object} [object={}] The object to copy symbols to.
4260 * @returns {Object} Returns `object`.
4262 function copySymbols(source, object) {
4263 return copyObject(source, getSymbols(source), object);
4267 * Creates a function like `_.groupBy`.
4270 * @param {Function} setter The function to set accumulator values.
4271 * @param {Function} [initializer] The accumulator object initializer.
4272 * @returns {Function} Returns the new aggregator function.
4274 function createAggregator(setter, initializer) {
4275 return function(collection, iteratee) {
4276 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4277 accumulator = initializer ? initializer() : {};
4279 return func(collection, setter, getIteratee(iteratee), accumulator);
4284 * Creates a function like `_.assign`.
4287 * @param {Function} assigner The function to assign values.
4288 * @returns {Function} Returns the new assigner function.
4290 function createAssigner(assigner) {
4291 return rest(function(object, sources) {
4293 length = sources.length,
4294 customizer = length > 1 ? sources[length - 1] : undefined,
4295 guard = length > 2 ? sources[2] : undefined;
4297 customizer = typeof customizer == 'function'
4298 ? (length--, customizer)
4301 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4302 customizer = length < 3 ? undefined : customizer;
4305 object = Object(object);
4306 while (++index < length) {
4307 var source = sources[index];
4309 assigner(object, source, index, customizer);
4317 * Creates a `baseEach` or `baseEachRight` function.
4320 * @param {Function} eachFunc The function to iterate over a collection.
4321 * @param {boolean} [fromRight] Specify iterating from right to left.
4322 * @returns {Function} Returns the new base function.
4324 function createBaseEach(eachFunc, fromRight) {
4325 return function(collection, iteratee) {
4326 if (collection == null) {
4329 if (!isArrayLike(collection)) {
4330 return eachFunc(collection, iteratee);
4332 var length = collection.length,
4333 index = fromRight ? length : -1,
4334 iterable = Object(collection);
4336 while ((fromRight ? index-- : ++index < length)) {
4337 if (iteratee(iterable[index], index, iterable) === false) {
4346 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4349 * @param {boolean} [fromRight] Specify iterating from right to left.
4350 * @returns {Function} Returns the new base function.
4352 function createBaseFor(fromRight) {
4353 return function(object, iteratee, keysFunc) {
4355 iterable = Object(object),
4356 props = keysFunc(object),
4357 length = props.length;
4360 var key = props[fromRight ? length : ++index];
4361 if (iteratee(iterable[key], key, iterable) === false) {
4370 * Creates a function that wraps `func` to invoke it with the optional `this`
4371 * binding of `thisArg`.
4374 * @param {Function} func The function to wrap.
4375 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4377 * @param {*} [thisArg] The `this` binding of `func`.
4378 * @returns {Function} Returns the new wrapped function.
4380 function createBaseWrapper(func, bitmask, thisArg) {
4381 var isBind = bitmask & BIND_FLAG,
4382 Ctor = createCtorWrapper(func);
4384 function wrapper() {
4385 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4386 return fn.apply(isBind ? thisArg : this, arguments);
4392 * Creates a function like `_.lowerFirst`.
4395 * @param {string} methodName The name of the `String` case method to use.
4396 * @returns {Function} Returns the new function.
4398 function createCaseFirst(methodName) {
4399 return function(string) {
4400 string = toString(string);
4402 var strSymbols = reHasComplexSymbol.test(string)
4403 ? stringToArray(string)
4406 var chr = strSymbols
4410 var trailing = strSymbols
4411 ? castSlice(strSymbols, 1).join('')
4414 return chr[methodName]() + trailing;
4419 * Creates a function like `_.camelCase`.
4422 * @param {Function} callback The function to combine each word.
4423 * @returns {Function} Returns the new compounder function.
4425 function createCompounder(callback) {
4426 return function(string) {
4427 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
4432 * Creates a function that produces an instance of `Ctor` regardless of
4433 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
4436 * @param {Function} Ctor The constructor to wrap.
4437 * @returns {Function} Returns the new wrapped function.
4439 function createCtorWrapper(Ctor) {
4441 // Use a `switch` statement to work with class constructors. See
4442 // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
4443 // for more details.
4444 var args = arguments;
4445 switch (args.length) {
4446 case 0: return new Ctor;
4447 case 1: return new Ctor(args[0]);
4448 case 2: return new Ctor(args[0], args[1]);
4449 case 3: return new Ctor(args[0], args[1], args[2]);
4450 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
4451 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
4452 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
4453 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
4455 var thisBinding = baseCreate(Ctor.prototype),
4456 result = Ctor.apply(thisBinding, args);
4458 // Mimic the constructor's `return` behavior.
4459 // See https://es5.github.io/#x13.2.2 for more details.
4460 return isObject(result) ? result : thisBinding;
4465 * Creates a function that wraps `func` to enable currying.
4468 * @param {Function} func The function to wrap.
4469 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4471 * @param {number} arity The arity of `func`.
4472 * @returns {Function} Returns the new wrapped function.
4474 function createCurryWrapper(func, bitmask, arity) {
4475 var Ctor = createCtorWrapper(func);
4477 function wrapper() {
4478 var length = arguments.length,
4479 args = Array(length),
4481 placeholder = getPlaceholder(wrapper);
4484 args[index] = arguments[index];
4486 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
4488 : replaceHolders(args, placeholder);
4490 length -= holders.length;
4491 if (length < arity) {
4492 return createRecurryWrapper(
4493 func, bitmask, createHybridWrapper, wrapper.placeholder, undefined,
4494 args, holders, undefined, undefined, arity - length);
4496 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4497 return apply(fn, this, args);
4503 * Creates a `_.flow` or `_.flowRight` function.
4506 * @param {boolean} [fromRight] Specify iterating from right to left.
4507 * @returns {Function} Returns the new flow function.
4509 function createFlow(fromRight) {
4510 return rest(function(funcs) {
4511 funcs = baseFlatten(funcs, 1);
4513 var length = funcs.length,
4515 prereq = LodashWrapper.prototype.thru;
4521 var func = funcs[index];
4522 if (typeof func != 'function') {
4523 throw new TypeError(FUNC_ERROR_TEXT);
4525 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
4526 var wrapper = new LodashWrapper([], true);
4529 index = wrapper ? index : length;
4530 while (++index < length) {
4531 func = funcs[index];
4533 var funcName = getFuncName(func),
4534 data = funcName == 'wrapper' ? getData(func) : undefined;
4536 if (data && isLaziable(data[0]) &&
4537 data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
4538 !data[4].length && data[9] == 1
4540 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
4542 wrapper = (func.length == 1 && isLaziable(func))
4543 ? wrapper[funcName]()
4544 : wrapper.thru(func);
4548 var args = arguments,
4551 if (wrapper && args.length == 1 &&
4552 isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
4553 return wrapper.plant(value).value();
4556 result = length ? funcs[index].apply(this, args) : value;
4558 while (++index < length) {
4559 result = funcs[index].call(this, result);
4567 * Creates a function that wraps `func` to invoke it with optional `this`
4568 * binding of `thisArg`, partial application, and currying.
4571 * @param {Function|string} func The function or method name to wrap.
4572 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4574 * @param {*} [thisArg] The `this` binding of `func`.
4575 * @param {Array} [partials] The arguments to prepend to those provided to
4577 * @param {Array} [holders] The `partials` placeholder indexes.
4578 * @param {Array} [partialsRight] The arguments to append to those provided
4579 * to the new function.
4580 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
4581 * @param {Array} [argPos] The argument positions of the new function.
4582 * @param {number} [ary] The arity cap of `func`.
4583 * @param {number} [arity] The arity of `func`.
4584 * @returns {Function} Returns the new wrapped function.
4586 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
4587 var isAry = bitmask & ARY_FLAG,
4588 isBind = bitmask & BIND_FLAG,
4589 isBindKey = bitmask & BIND_KEY_FLAG,
4590 isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
4591 isFlip = bitmask & FLIP_FLAG,
4592 Ctor = isBindKey ? undefined : createCtorWrapper(func);
4594 function wrapper() {
4595 var length = arguments.length,
4597 args = Array(length);
4600 args[index] = arguments[index];
4603 var placeholder = getPlaceholder(wrapper),
4604 holdersCount = countHolders(args, placeholder);
4607 args = composeArgs(args, partials, holders, isCurried);
4609 if (partialsRight) {
4610 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
4612 length -= holdersCount;
4613 if (isCurried && length < arity) {
4614 var newHolders = replaceHolders(args, placeholder);
4615 return createRecurryWrapper(
4616 func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg,
4617 args, newHolders, argPos, ary, arity - length
4620 var thisBinding = isBind ? thisArg : this,
4621 fn = isBindKey ? thisBinding[func] : func;
4623 length = args.length;
4625 args = reorder(args, argPos);
4626 } else if (isFlip && length > 1) {
4629 if (isAry && ary < length) {
4632 if (this && this !== root && this instanceof wrapper) {
4633 fn = Ctor || createCtorWrapper(fn);
4635 return fn.apply(thisBinding, args);
4641 * Creates a function like `_.invertBy`.
4644 * @param {Function} setter The function to set accumulator values.
4645 * @param {Function} toIteratee The function to resolve iteratees.
4646 * @returns {Function} Returns the new inverter function.
4648 function createInverter(setter, toIteratee) {
4649 return function(object, iteratee) {
4650 return baseInverter(object, setter, toIteratee(iteratee), {});
4655 * Creates a function that performs a mathematical operation on two values.
4658 * @param {Function} operator The function to perform the operation.
4659 * @returns {Function} Returns the new mathematical operation function.
4661 function createMathOperation(operator) {
4662 return function(value, other) {
4664 if (value === undefined && other === undefined) {
4667 if (value !== undefined) {
4670 if (other !== undefined) {
4671 if (result === undefined) {
4674 if (typeof value == 'string' || typeof other == 'string') {
4675 value = baseToString(value);
4676 other = baseToString(other);
4678 value = baseToNumber(value);
4679 other = baseToNumber(other);
4681 result = operator(value, other);
4688 * Creates a function like `_.over`.
4691 * @param {Function} arrayFunc The function to iterate over iteratees.
4692 * @returns {Function} Returns the new invoker function.
4694 function createOver(arrayFunc) {
4695 return rest(function(iteratees) {
4696 iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
4697 ? arrayMap(iteratees[0], baseUnary(getIteratee()))
4698 : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(getIteratee()));
4700 return rest(function(args) {
4702 return arrayFunc(iteratees, function(iteratee) {
4703 return apply(iteratee, thisArg, args);
4710 * Creates the padding for `string` based on `length`. The `chars` string
4711 * is truncated if the number of characters exceeds `length`.
4714 * @param {number} length The padding length.
4715 * @param {string} [chars=' '] The string used as padding.
4716 * @returns {string} Returns the padding for `string`.
4718 function createPadding(length, chars) {
4719 chars = chars === undefined ? ' ' : baseToString(chars);
4721 var charsLength = chars.length;
4722 if (charsLength < 2) {
4723 return charsLength ? baseRepeat(chars, length) : chars;
4725 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
4726 return reHasComplexSymbol.test(chars)
4727 ? castSlice(stringToArray(result), 0, length).join('')
4728 : result.slice(0, length);
4732 * Creates a function that wraps `func` to invoke it with the `this` binding
4733 * of `thisArg` and `partials` prepended to the arguments it receives.
4736 * @param {Function} func The function to wrap.
4737 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4739 * @param {*} thisArg The `this` binding of `func`.
4740 * @param {Array} partials The arguments to prepend to those provided to
4742 * @returns {Function} Returns the new wrapped function.
4744 function createPartialWrapper(func, bitmask, thisArg, partials) {
4745 var isBind = bitmask & BIND_FLAG,
4746 Ctor = createCtorWrapper(func);
4748 function wrapper() {
4750 argsLength = arguments.length,
4752 leftLength = partials.length,
4753 args = Array(leftLength + argsLength),
4754 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4756 while (++leftIndex < leftLength) {
4757 args[leftIndex] = partials[leftIndex];
4759 while (argsLength--) {
4760 args[leftIndex++] = arguments[++argsIndex];
4762 return apply(fn, isBind ? thisArg : this, args);
4768 * Creates a `_.range` or `_.rangeRight` function.
4771 * @param {boolean} [fromRight] Specify iterating from right to left.
4772 * @returns {Function} Returns the new range function.
4774 function createRange(fromRight) {
4775 return function(start, end, step) {
4776 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
4777 end = step = undefined;
4779 // Ensure the sign of `-0` is preserved.
4780 start = toNumber(start);
4781 start = start === start ? start : 0;
4782 if (end === undefined) {
4786 end = toNumber(end) || 0;
4788 step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
4789 return baseRange(start, end, step, fromRight);
4794 * Creates a function that performs a relational operation on two values.
4797 * @param {Function} operator The function to perform the operation.
4798 * @returns {Function} Returns the new relational operation function.
4800 function createRelationalOperation(operator) {
4801 return function(value, other) {
4802 if (!(typeof value == 'string' && typeof other == 'string')) {
4803 value = toNumber(value);
4804 other = toNumber(other);
4806 return operator(value, other);
4811 * Creates a function that wraps `func` to continue currying.
4814 * @param {Function} func The function to wrap.
4815 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
4817 * @param {Function} wrapFunc The function to create the `func` wrapper.
4818 * @param {*} placeholder The placeholder value.
4819 * @param {*} [thisArg] The `this` binding of `func`.
4820 * @param {Array} [partials] The arguments to prepend to those provided to
4822 * @param {Array} [holders] The `partials` placeholder indexes.
4823 * @param {Array} [argPos] The argument positions of the new function.
4824 * @param {number} [ary] The arity cap of `func`.
4825 * @param {number} [arity] The arity of `func`.
4826 * @returns {Function} Returns the new wrapped function.
4828 function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
4829 var isCurry = bitmask & CURRY_FLAG,
4830 newHolders = isCurry ? holders : undefined,
4831 newHoldersRight = isCurry ? undefined : holders,
4832 newPartials = isCurry ? partials : undefined,
4833 newPartialsRight = isCurry ? undefined : partials;
4835 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
4836 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
4838 if (!(bitmask & CURRY_BOUND_FLAG)) {
4839 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
4842 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
4843 newHoldersRight, argPos, ary, arity
4846 var result = wrapFunc.apply(undefined, newData);
4847 if (isLaziable(func)) {
4848 setData(result, newData);
4850 result.placeholder = placeholder;
4855 * Creates a function like `_.round`.
4858 * @param {string} methodName The name of the `Math` method to use when rounding.
4859 * @returns {Function} Returns the new round function.
4861 function createRound(methodName) {
4862 var func = Math[methodName];
4863 return function(number, precision) {
4864 number = toNumber(number);
4865 precision = toInteger(precision);
4867 // Shift with exponential notation to avoid floating-point issues.
4868 // See [MDN](https://mdn.io/round#Examples) for more details.
4869 var pair = (toString(number) + 'e').split('e'),
4870 value = func(pair[0] + 'e' + (+pair[1] + precision));
4872 pair = (toString(value) + 'e').split('e');
4873 return +(pair[0] + 'e' + (+pair[1] - precision));
4875 return func(number);
4880 * Creates a set of `values`.
4883 * @param {Array} values The values to add to the set.
4884 * @returns {Object} Returns the new set.
4886 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
4887 return new Set(values);
4891 * Creates a function that either curries or invokes `func` with optional
4892 * `this` binding and partially applied arguments.
4895 * @param {Function|string} func The function or method name to wrap.
4896 * @param {number} bitmask The bitmask of wrapper flags.
4897 * The bitmask may be composed of the following flags:
4900 * 4 - `_.curry` or `_.curryRight` of a bound function
4902 * 16 - `_.curryRight`
4904 * 64 - `_.partialRight`
4907 * @param {*} [thisArg] The `this` binding of `func`.
4908 * @param {Array} [partials] The arguments to be partially applied.
4909 * @param {Array} [holders] The `partials` placeholder indexes.
4910 * @param {Array} [argPos] The argument positions of the new function.
4911 * @param {number} [ary] The arity cap of `func`.
4912 * @param {number} [arity] The arity of `func`.
4913 * @returns {Function} Returns the new wrapped function.
4915 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
4916 var isBindKey = bitmask & BIND_KEY_FLAG;
4917 if (!isBindKey && typeof func != 'function') {
4918 throw new TypeError(FUNC_ERROR_TEXT);
4920 var length = partials ? partials.length : 0;
4922 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
4923 partials = holders = undefined;
4925 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
4926 arity = arity === undefined ? arity : toInteger(arity);
4927 length -= holders ? holders.length : 0;
4929 if (bitmask & PARTIAL_RIGHT_FLAG) {
4930 var partialsRight = partials,
4931 holdersRight = holders;
4933 partials = holders = undefined;
4935 var data = isBindKey ? undefined : getData(func);
4938 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
4943 mergeData(newData, data);
4946 bitmask = newData[1];
4947 thisArg = newData[2];
4948 partials = newData[3];
4949 holders = newData[4];
4950 arity = newData[9] = newData[9] == null
4951 ? (isBindKey ? 0 : func.length)
4952 : nativeMax(newData[9] - length, 0);
4954 if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
4955 bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
4957 if (!bitmask || bitmask == BIND_FLAG) {
4958 var result = createBaseWrapper(func, bitmask, thisArg);
4959 } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
4960 result = createCurryWrapper(func, bitmask, arity);
4961 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
4962 result = createPartialWrapper(func, bitmask, thisArg, partials);
4964 result = createHybridWrapper.apply(undefined, newData);
4966 var setter = data ? baseSetData : setData;
4967 return setter(result, newData);
4971 * A specialized version of `baseIsEqualDeep` for arrays with support for
4972 * partial deep comparisons.
4975 * @param {Array} array The array to compare.
4976 * @param {Array} other The other array to compare.
4977 * @param {Function} equalFunc The function to determine equivalents of values.
4978 * @param {Function} customizer The function to customize comparisons.
4979 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
4981 * @param {Object} stack Tracks traversed `array` and `other` objects.
4982 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
4984 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
4986 isPartial = bitmask & PARTIAL_COMPARE_FLAG,
4987 isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
4988 arrLength = array.length,
4989 othLength = other.length;
4991 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
4994 // Assume cyclic values are equal.
4995 var stacked = stack.get(array);
4997 return stacked == other;
5000 stack.set(array, other);
5002 // Ignore non-index properties.
5003 while (++index < arrLength) {
5004 var arrValue = array[index],
5005 othValue = other[index];
5008 var compared = isPartial
5009 ? customizer(othValue, arrValue, index, other, array, stack)
5010 : customizer(arrValue, othValue, index, array, other, stack);
5012 if (compared !== undefined) {
5019 // Recursively compare arrays (susceptible to call stack limits).
5021 if (!arraySome(other, function(othValue) {
5022 return arrValue === othValue ||
5023 equalFunc(arrValue, othValue, customizer, bitmask, stack);
5029 arrValue === othValue ||
5030 equalFunc(arrValue, othValue, customizer, bitmask, stack)
5036 stack['delete'](array);
5041 * A specialized version of `baseIsEqualDeep` for comparing objects of
5042 * the same `toStringTag`.
5044 * **Note:** This function only supports comparing values with tags of
5045 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5048 * @param {Object} object The object to compare.
5049 * @param {Object} other The other object to compare.
5050 * @param {string} tag The `toStringTag` of the objects to compare.
5051 * @param {Function} equalFunc The function to determine equivalents of values.
5052 * @param {Function} customizer The function to customize comparisons.
5053 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5055 * @param {Object} stack Tracks traversed `object` and `other` objects.
5056 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5058 function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
5061 if ((object.byteLength != other.byteLength) ||
5062 (object.byteOffset != other.byteOffset)) {
5065 object = object.buffer;
5066 other = other.buffer;
5068 case arrayBufferTag:
5069 if ((object.byteLength != other.byteLength) ||
5070 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5077 // Coerce dates and booleans to numbers, dates to milliseconds and
5078 // booleans to `1` or `0` treating invalid dates coerced to `NaN` as
5080 return +object == +other;
5083 return object.name == other.name && object.message == other.message;
5086 // Treat `NaN` vs. `NaN` as equal.
5087 return (object != +object) ? other != +other : object == +other;
5091 // Coerce regexes to strings and treat strings, primitives and objects,
5092 // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
5093 // for more details.
5094 return object == (other + '');
5097 var convert = mapToArray;
5100 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
5101 convert || (convert = setToArray);
5103 if (object.size != other.size && !isPartial) {
5106 // Assume cyclic values are equal.
5107 var stacked = stack.get(object);
5109 return stacked == other;
5111 bitmask |= UNORDERED_COMPARE_FLAG;
5112 stack.set(object, other);
5114 // Recursively compare objects (susceptible to call stack limits).
5115 return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
5118 if (symbolValueOf) {
5119 return symbolValueOf.call(object) == symbolValueOf.call(other);
5126 * A specialized version of `baseIsEqualDeep` for objects with support for
5127 * partial deep comparisons.
5130 * @param {Object} object The object to compare.
5131 * @param {Object} other The other object to compare.
5132 * @param {Function} equalFunc The function to determine equivalents of values.
5133 * @param {Function} customizer The function to customize comparisons.
5134 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5136 * @param {Object} stack Tracks traversed `object` and `other` objects.
5137 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5139 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
5140 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
5141 objProps = keys(object),
5142 objLength = objProps.length,
5143 othProps = keys(other),
5144 othLength = othProps.length;
5146 if (objLength != othLength && !isPartial) {
5149 var index = objLength;
5151 var key = objProps[index];
5152 if (!(isPartial ? key in other : baseHas(other, key))) {
5156 // Assume cyclic values are equal.
5157 var stacked = stack.get(object);
5159 return stacked == other;
5162 stack.set(object, other);
5164 var skipCtor = isPartial;
5165 while (++index < objLength) {
5166 key = objProps[index];
5167 var objValue = object[key],
5168 othValue = other[key];
5171 var compared = isPartial
5172 ? customizer(othValue, objValue, key, other, object, stack)
5173 : customizer(objValue, othValue, key, object, other, stack);
5175 // Recursively compare objects (susceptible to call stack limits).
5176 if (!(compared === undefined
5177 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
5183 skipCtor || (skipCtor = key == 'constructor');
5185 if (result && !skipCtor) {
5186 var objCtor = object.constructor,
5187 othCtor = other.constructor;
5189 // Non `Object` object instances with different constructors are not equal.
5190 if (objCtor != othCtor &&
5191 ('constructor' in object && 'constructor' in other) &&
5192 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5193 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5197 stack['delete'](object);
5202 * Creates an array of own enumerable property names and symbols of `object`.
5205 * @param {Object} object The object to query.
5206 * @returns {Array} Returns the array of property names and symbols.
5208 function getAllKeys(object) {
5209 return baseGetAllKeys(object, keys, getSymbols);
5213 * Creates an array of own and inherited enumerable property names and
5214 * symbols of `object`.
5217 * @param {Object} object The object to query.
5218 * @returns {Array} Returns the array of property names and symbols.
5220 function getAllKeysIn(object) {
5221 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5225 * Gets metadata for `func`.
5228 * @param {Function} func The function to query.
5229 * @returns {*} Returns the metadata for `func`.
5231 var getData = !metaMap ? noop : function(func) {
5232 return metaMap.get(func);
5236 * Gets the name of `func`.
5239 * @param {Function} func The function to query.
5240 * @returns {string} Returns the function name.
5242 function getFuncName(func) {
5243 var result = (func.name + ''),
5244 array = realNames[result],
5245 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5248 var data = array[length],
5249 otherFunc = data.func;
5250 if (otherFunc == null || otherFunc == func) {
5258 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
5259 * this function returns the custom method, otherwise it returns `baseIteratee`.
5260 * If arguments are provided, the chosen function is invoked with them and
5261 * its result is returned.
5264 * @param {*} [value] The value to convert to an iteratee.
5265 * @param {number} [arity] The arity of the created iteratee.
5266 * @returns {Function} Returns the chosen function or its result.
5268 function getIteratee() {
5269 var result = lodash.iteratee || iteratee;
5270 result = result === iteratee ? baseIteratee : result;
5271 return arguments.length ? result(arguments[0], arguments[1]) : result;
5275 * Gets the "length" property value of `object`.
5277 * **Note:** This function is used to avoid a
5278 * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
5279 * Safari on at least iOS 8.1-8.3 ARM64.
5282 * @param {Object} object The object to query.
5283 * @returns {*} Returns the "length" value.
5285 var getLength = baseProperty('length');
5288 * Gets the property names, values, and compare flags of `object`.
5291 * @param {Object} object The object to query.
5292 * @returns {Array} Returns the match data of `object`.
5294 function getMatchData(object) {
5295 var result = toPairs(object),
5296 length = result.length;
5299 result[length][2] = isStrictComparable(result[length][1]);
5305 * Gets the native function at `key` of `object`.
5308 * @param {Object} object The object to query.
5309 * @param {string} key The key of the method to get.
5310 * @returns {*} Returns the function if it's native, else `undefined`.
5312 function getNative(object, key) {
5313 var value = object[key];
5314 return isNative(value) ? value : undefined;
5318 * Gets the argument placeholder value for `func`.
5321 * @param {Function} func The function to inspect.
5322 * @returns {*} Returns the placeholder value.
5324 function getPlaceholder(func) {
5325 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
5326 return object.placeholder;
5330 * Gets the `[[Prototype]]` of `value`.
5333 * @param {*} value The value to query.
5334 * @returns {null|Object} Returns the `[[Prototype]]`.
5336 function getPrototype(value) {
5337 return nativeGetPrototype(Object(value));
5341 * Creates an array of the own enumerable symbol properties of `object`.
5344 * @param {Object} object The object to query.
5345 * @returns {Array} Returns the array of symbols.
5347 function getSymbols(object) {
5348 // Coerce `object` to an object to avoid non-object errors in V8.
5349 // See https://bugs.chromium.org/p/v8/issues/detail?id=3443 for more details.
5350 return getOwnPropertySymbols(Object(object));
5353 // Fallback for IE < 11.
5354 if (!getOwnPropertySymbols) {
5355 getSymbols = function() {
5361 * Creates an array of the own and inherited enumerable symbol properties
5365 * @param {Object} object The object to query.
5366 * @returns {Array} Returns the array of symbols.
5368 var getSymbolsIn = !getOwnPropertySymbols ? getSymbols : function(object) {
5371 arrayPush(result, getSymbols(object));
5372 object = getPrototype(object);
5378 * Gets the `toStringTag` of `value`.
5381 * @param {*} value The value to query.
5382 * @returns {string} Returns the `toStringTag`.
5384 function getTag(value) {
5385 return objectToString.call(value);
5388 // Fallback for data views, maps, sets, and weak maps in IE 11,
5389 // for data views in Edge, and promises in Node.js.
5390 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
5391 (Map && getTag(new Map) != mapTag) ||
5392 (Promise && getTag(Promise.resolve()) != promiseTag) ||
5393 (Set && getTag(new Set) != setTag) ||
5394 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
5395 getTag = function(value) {
5396 var result = objectToString.call(value),
5397 Ctor = result == objectTag ? value.constructor : undefined,
5398 ctorString = Ctor ? toSource(Ctor) : undefined;
5401 switch (ctorString) {
5402 case dataViewCtorString: return dataViewTag;
5403 case mapCtorString: return mapTag;
5404 case promiseCtorString: return promiseTag;
5405 case setCtorString: return setTag;
5406 case weakMapCtorString: return weakMapTag;
5414 * Gets the view, applying any `transforms` to the `start` and `end` positions.
5417 * @param {number} start The start of the view.
5418 * @param {number} end The end of the view.
5419 * @param {Array} transforms The transformations to apply to the view.
5420 * @returns {Object} Returns an object containing the `start` and `end`
5421 * positions of the view.
5423 function getView(start, end, transforms) {
5425 length = transforms.length;
5427 while (++index < length) {
5428 var data = transforms[index],
5431 switch (data.type) {
5432 case 'drop': start += size; break;
5433 case 'dropRight': end -= size; break;
5434 case 'take': end = nativeMin(end, start + size); break;
5435 case 'takeRight': start = nativeMax(start, end - size); break;
5438 return { 'start': start, 'end': end };
5442 * Checks if `path` exists on `object`.
5445 * @param {Object} object The object to query.
5446 * @param {Array|string} path The path to check.
5447 * @param {Function} hasFunc The function to check properties.
5448 * @returns {boolean} Returns `true` if `path` exists, else `false`.
5450 function hasPath(object, path, hasFunc) {
5451 path = isKey(path, object) ? [path] : castPath(path);
5455 length = path.length;
5457 while (++index < length) {
5458 var key = toKey(path[index]);
5459 if (!(result = object != null && hasFunc(object, key))) {
5462 object = object[key];
5467 var length = object ? object.length : 0;
5468 return !!length && isLength(length) && isIndex(key, length) &&
5469 (isArray(object) || isString(object) || isArguments(object));
5473 * Initializes an array clone.
5476 * @param {Array} array The array to clone.
5477 * @returns {Array} Returns the initialized clone.
5479 function initCloneArray(array) {
5480 var length = array.length,
5481 result = array.constructor(length);
5483 // Add properties assigned by `RegExp#exec`.
5484 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
5485 result.index = array.index;
5486 result.input = array.input;
5492 * Initializes an object clone.
5495 * @param {Object} object The object to clone.
5496 * @returns {Object} Returns the initialized clone.
5498 function initCloneObject(object) {
5499 return (typeof object.constructor == 'function' && !isPrototype(object))
5500 ? baseCreate(getPrototype(object))
5505 * Initializes an object clone based on its `toStringTag`.
5507 * **Note:** This function only supports cloning values with tags of
5508 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5511 * @param {Object} object The object to clone.
5512 * @param {string} tag The `toStringTag` of the object to clone.
5513 * @param {Function} cloneFunc The function to clone values.
5514 * @param {boolean} [isDeep] Specify a deep clone.
5515 * @returns {Object} Returns the initialized clone.
5517 function initCloneByTag(object, tag, cloneFunc, isDeep) {
5518 var Ctor = object.constructor;
5520 case arrayBufferTag:
5521 return cloneArrayBuffer(object);
5525 return new Ctor(+object);
5528 return cloneDataView(object, isDeep);
5530 case float32Tag: case float64Tag:
5531 case int8Tag: case int16Tag: case int32Tag:
5532 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
5533 return cloneTypedArray(object, isDeep);
5536 return cloneMap(object, isDeep, cloneFunc);
5540 return new Ctor(object);
5543 return cloneRegExp(object);
5546 return cloneSet(object, isDeep, cloneFunc);
5549 return cloneSymbol(object);
5554 * Creates an array of index keys for `object` values of arrays,
5555 * `arguments` objects, and strings, otherwise `null` is returned.
5558 * @param {Object} object The object to query.
5559 * @returns {Array|null} Returns index keys, else `null`.
5561 function indexKeys(object) {
5562 var length = object ? object.length : undefined;
5563 if (isLength(length) &&
5564 (isArray(object) || isString(object) || isArguments(object))) {
5565 return baseTimes(length, String);
5571 * Checks if `value` is a flattenable `arguments` object or array.
5574 * @param {*} value The value to check.
5575 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
5577 function isFlattenable(value) {
5578 return isArrayLikeObject(value) && (isArray(value) || isArguments(value));
5582 * Checks if `value` is a flattenable array and not a `_.matchesProperty`
5583 * iteratee shorthand.
5586 * @param {*} value The value to check.
5587 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
5589 function isFlattenableIteratee(value) {
5590 return isArray(value) && !(value.length == 2 && !isFunction(value[0]));
5594 * Checks if `value` is a valid array-like index.
5597 * @param {*} value The value to check.
5598 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
5599 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
5601 function isIndex(value, length) {
5602 length = length == null ? MAX_SAFE_INTEGER : length;
5604 (typeof value == 'number' || reIsUint.test(value)) &&
5605 (value > -1 && value % 1 == 0 && value < length);
5609 * Checks if the given arguments are from an iteratee call.
5612 * @param {*} value The potential iteratee value argument.
5613 * @param {*} index The potential iteratee index or key argument.
5614 * @param {*} object The potential iteratee object argument.
5615 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
5618 function isIterateeCall(value, index, object) {
5619 if (!isObject(object)) {
5622 var type = typeof index;
5623 if (type == 'number'
5624 ? (isArrayLike(object) && isIndex(index, object.length))
5625 : (type == 'string' && index in object)
5627 return eq(object[index], value);
5633 * Checks if `value` is a property name and not a property path.
5636 * @param {*} value The value to check.
5637 * @param {Object} [object] The object to query keys on.
5638 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
5640 function isKey(value, object) {
5641 if (isArray(value)) {
5644 var type = typeof value;
5645 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
5646 value == null || isSymbol(value)) {
5649 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
5650 (object != null && value in Object(object));
5654 * Checks if `value` is suitable for use as unique object key.
5657 * @param {*} value The value to check.
5658 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
5660 function isKeyable(value) {
5661 var type = typeof value;
5662 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
5663 ? (value !== '__proto__')
5668 * Checks if `func` has a lazy counterpart.
5671 * @param {Function} func The function to check.
5672 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
5675 function isLaziable(func) {
5676 var funcName = getFuncName(func),
5677 other = lodash[funcName];
5679 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
5682 if (func === other) {
5685 var data = getData(other);
5686 return !!data && func === data[0];
5690 * Checks if `value` is likely a prototype object.
5693 * @param {*} value The value to check.
5694 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
5696 function isPrototype(value) {
5697 var Ctor = value && value.constructor,
5698 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
5700 return value === proto;
5704 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
5707 * @param {*} value The value to check.
5708 * @returns {boolean} Returns `true` if `value` if suitable for strict
5709 * equality comparisons, else `false`.
5711 function isStrictComparable(value) {
5712 return value === value && !isObject(value);
5716 * A specialized version of `matchesProperty` for source values suitable
5717 * for strict equality comparisons, i.e. `===`.
5720 * @param {string} key The key of the property to get.
5721 * @param {*} srcValue The value to match.
5722 * @returns {Function} Returns the new function.
5724 function matchesStrictComparable(key, srcValue) {
5725 return function(object) {
5726 if (object == null) {
5729 return object[key] === srcValue &&
5730 (srcValue !== undefined || (key in Object(object)));
5735 * Merges the function metadata of `source` into `data`.
5737 * Merging metadata reduces the number of wrappers used to invoke a function.
5738 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
5739 * may be applied regardless of execution order. Methods like `_.ary` and
5740 * `_.rearg` modify function arguments, making the order in which they are
5741 * executed important, preventing the merging of metadata. However, we make
5742 * an exception for a safe combined case where curried functions have `_.ary`
5743 * and or `_.rearg` applied.
5746 * @param {Array} data The destination metadata.
5747 * @param {Array} source The source metadata.
5748 * @returns {Array} Returns `data`.
5750 function mergeData(data, source) {
5751 var bitmask = data[1],
5752 srcBitmask = source[1],
5753 newBitmask = bitmask | srcBitmask,
5754 isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
5757 ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
5758 ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
5759 ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
5761 // Exit early if metadata can't be merged.
5762 if (!(isCommon || isCombo)) {
5765 // Use source `thisArg` if available.
5766 if (srcBitmask & BIND_FLAG) {
5767 data[2] = source[2];
5768 // Set when currying a bound function.
5769 newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
5771 // Compose partial arguments.
5772 var value = source[3];
5774 var partials = data[3];
5775 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
5776 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
5778 // Compose partial right arguments.
5782 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
5783 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
5785 // Use source `argPos` if available.
5790 // Use source `ary` if it's smaller.
5791 if (srcBitmask & ARY_FLAG) {
5792 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
5794 // Use source `arity` if one is not provided.
5795 if (data[9] == null) {
5796 data[9] = source[9];
5798 // Use source `func` and merge bitmasks.
5799 data[0] = source[0];
5800 data[1] = newBitmask;
5806 * Used by `_.defaultsDeep` to customize its `_.merge` use.
5809 * @param {*} objValue The destination value.
5810 * @param {*} srcValue The source value.
5811 * @param {string} key The key of the property to merge.
5812 * @param {Object} object The parent object of `objValue`.
5813 * @param {Object} source The parent object of `srcValue`.
5814 * @param {Object} [stack] Tracks traversed source values and their merged
5816 * @returns {*} Returns the value to assign.
5818 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
5819 if (isObject(objValue) && isObject(srcValue)) {
5820 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
5826 * Gets the parent value at `path` of `object`.
5829 * @param {Object} object The object to query.
5830 * @param {Array} path The path to get the parent value of.
5831 * @returns {*} Returns the parent value.
5833 function parent(object, path) {
5834 return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
5838 * Reorder `array` according to the specified indexes where the element at
5839 * the first index is assigned as the first element, the element at
5840 * the second index is assigned as the second element, and so on.
5843 * @param {Array} array The array to reorder.
5844 * @param {Array} indexes The arranged array indexes.
5845 * @returns {Array} Returns `array`.
5847 function reorder(array, indexes) {
5848 var arrLength = array.length,
5849 length = nativeMin(indexes.length, arrLength),
5850 oldArray = copyArray(array);
5853 var index = indexes[length];
5854 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
5860 * Sets metadata for `func`.
5862 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
5863 * period of time, it will trip its breaker and transition to an identity
5864 * function to avoid garbage collection pauses in V8. See
5865 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
5869 * @param {Function} func The function to associate metadata with.
5870 * @param {*} data The metadata.
5871 * @returns {Function} Returns `func`.
5873 var setData = (function() {
5877 return function(key, value) {
5879 remaining = HOT_SPAN - (stamp - lastCalled);
5882 if (remaining > 0) {
5883 if (++count >= HOT_COUNT) {
5889 return baseSetData(key, value);
5894 * Converts `string` to a property path array.
5897 * @param {string} string The string to convert.
5898 * @returns {Array} Returns the property path array.
5900 var stringToPath = memoize(function(string) {
5902 toString(string).replace(rePropName, function(match, number, quote, string) {
5903 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
5909 * Converts `value` to a string key if it's not a string or symbol.
5912 * @param {*} value The value to inspect.
5913 * @returns {string|symbol} Returns the key.
5915 function toKey(value) {
5916 if (typeof value == 'string' || isSymbol(value)) {
5919 var result = (value + '');
5920 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
5924 * Converts `func` to its source code.
5927 * @param {Function} func The function to process.
5928 * @returns {string} Returns the source code.
5930 function toSource(func) {
5933 return funcToString.call(func);
5943 * Creates a clone of `wrapper`.
5946 * @param {Object} wrapper The wrapper to clone.
5947 * @returns {Object} Returns the cloned wrapper.
5949 function wrapperClone(wrapper) {
5950 if (wrapper instanceof LazyWrapper) {
5951 return wrapper.clone();
5953 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
5954 result.__actions__ = copyArray(wrapper.__actions__);
5955 result.__index__ = wrapper.__index__;
5956 result.__values__ = wrapper.__values__;
5960 /*------------------------------------------------------------------------*/
5963 * Creates an array of elements split into groups the length of `size`.
5964 * If `array` can't be split evenly, the final chunk will be the remaining
5971 * @param {Array} array The array to process.
5972 * @param {number} [size=1] The length of each chunk
5973 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
5974 * @returns {Array} Returns the new array containing chunks.
5977 * _.chunk(['a', 'b', 'c', 'd'], 2);
5978 * // => [['a', 'b'], ['c', 'd']]
5980 * _.chunk(['a', 'b', 'c', 'd'], 3);
5981 * // => [['a', 'b', 'c'], ['d']]
5983 function chunk(array, size, guard) {
5984 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
5987 size = nativeMax(toInteger(size), 0);
5989 var length = array ? array.length : 0;
5990 if (!length || size < 1) {
5995 result = Array(nativeCeil(length / size));
5997 while (index < length) {
5998 result[resIndex++] = baseSlice(array, index, (index += size));
6004 * Creates an array with all falsey values removed. The values `false`, `null`,
6005 * `0`, `""`, `undefined`, and `NaN` are falsey.
6011 * @param {Array} array The array to compact.
6012 * @returns {Array} Returns the new array of filtered values.
6015 * _.compact([0, 1, false, 2, '', 3]);
6018 function compact(array) {
6020 length = array ? array.length : 0,
6024 while (++index < length) {
6025 var value = array[index];
6027 result[resIndex++] = value;
6034 * Creates a new array concatenating `array` with any additional arrays
6041 * @param {Array} array The array to concatenate.
6042 * @param {...*} [values] The values to concatenate.
6043 * @returns {Array} Returns the new concatenated array.
6047 * var other = _.concat(array, 2, [3], [[4]]);
6049 * console.log(other);
6050 * // => [1, 2, 3, [4]]
6052 * console.log(array);
6056 var length = arguments.length,
6057 array = castArray(arguments[0]);
6060 return length ? copyArray(array) : [];
6062 var args = Array(length - 1);
6064 args[length - 1] = arguments[length];
6066 return arrayConcat(array, baseFlatten(args, 1));
6070 * Creates an array of unique `array` values not included in the other given
6071 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6072 * for equality comparisons. The order of result values is determined by the
6073 * order they occur in the first array.
6079 * @param {Array} array The array to inspect.
6080 * @param {...Array} [values] The values to exclude.
6081 * @returns {Array} Returns the new array of filtered values.
6082 * @see _.without, _.xor
6085 * _.difference([3, 2, 1], [4, 2]);
6088 var difference = rest(function(array, values) {
6089 return isArrayLikeObject(array)
6090 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
6095 * This method is like `_.difference` except that it accepts `iteratee` which
6096 * is invoked for each element of `array` and `values` to generate the criterion
6097 * by which they're compared. Result values are chosen from the first array.
6098 * The iteratee is invoked with one argument: (value).
6104 * @param {Array} array The array to inspect.
6105 * @param {...Array} [values] The values to exclude.
6106 * @param {Array|Function|Object|string} [iteratee=_.identity]
6107 * The iteratee invoked per element.
6108 * @returns {Array} Returns the new array of filtered values.
6111 * _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
6114 * // The `_.property` iteratee shorthand.
6115 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
6116 * // => [{ 'x': 2 }]
6118 var differenceBy = rest(function(array, values) {
6119 var iteratee = last(values);
6120 if (isArrayLikeObject(iteratee)) {
6121 iteratee = undefined;
6123 return isArrayLikeObject(array)
6124 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee))
6129 * This method is like `_.difference` except that it accepts `comparator`
6130 * which is invoked to compare elements of `array` to `values`. Result values
6131 * are chosen from the first array. The comparator is invoked with two arguments:
6138 * @param {Array} array The array to inspect.
6139 * @param {...Array} [values] The values to exclude.
6140 * @param {Function} [comparator] The comparator invoked per element.
6141 * @returns {Array} Returns the new array of filtered values.
6144 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6146 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
6147 * // => [{ 'x': 2, 'y': 1 }]
6149 var differenceWith = rest(function(array, values) {
6150 var comparator = last(values);
6151 if (isArrayLikeObject(comparator)) {
6152 comparator = undefined;
6154 return isArrayLikeObject(array)
6155 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
6160 * Creates a slice of `array` with `n` elements dropped from the beginning.
6166 * @param {Array} array The array to query.
6167 * @param {number} [n=1] The number of elements to drop.
6168 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6169 * @returns {Array} Returns the slice of `array`.
6172 * _.drop([1, 2, 3]);
6175 * _.drop([1, 2, 3], 2);
6178 * _.drop([1, 2, 3], 5);
6181 * _.drop([1, 2, 3], 0);
6184 function drop(array, n, guard) {
6185 var length = array ? array.length : 0;
6189 n = (guard || n === undefined) ? 1 : toInteger(n);
6190 return baseSlice(array, n < 0 ? 0 : n, length);
6194 * Creates a slice of `array` with `n` elements dropped from the end.
6200 * @param {Array} array The array to query.
6201 * @param {number} [n=1] The number of elements to drop.
6202 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6203 * @returns {Array} Returns the slice of `array`.
6206 * _.dropRight([1, 2, 3]);
6209 * _.dropRight([1, 2, 3], 2);
6212 * _.dropRight([1, 2, 3], 5);
6215 * _.dropRight([1, 2, 3], 0);
6218 function dropRight(array, n, guard) {
6219 var length = array ? array.length : 0;
6223 n = (guard || n === undefined) ? 1 : toInteger(n);
6225 return baseSlice(array, 0, n < 0 ? 0 : n);
6229 * Creates a slice of `array` excluding elements dropped from the end.
6230 * Elements are dropped until `predicate` returns falsey. The predicate is
6231 * invoked with three arguments: (value, index, array).
6237 * @param {Array} array The array to query.
6238 * @param {Array|Function|Object|string} [predicate=_.identity]
6239 * The function invoked per iteration.
6240 * @returns {Array} Returns the slice of `array`.
6244 * { 'user': 'barney', 'active': true },
6245 * { 'user': 'fred', 'active': false },
6246 * { 'user': 'pebbles', 'active': false }
6249 * _.dropRightWhile(users, function(o) { return !o.active; });
6250 * // => objects for ['barney']
6252 * // The `_.matches` iteratee shorthand.
6253 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
6254 * // => objects for ['barney', 'fred']
6256 * // The `_.matchesProperty` iteratee shorthand.
6257 * _.dropRightWhile(users, ['active', false]);
6258 * // => objects for ['barney']
6260 * // The `_.property` iteratee shorthand.
6261 * _.dropRightWhile(users, 'active');
6262 * // => objects for ['barney', 'fred', 'pebbles']
6264 function dropRightWhile(array, predicate) {
6265 return (array && array.length)
6266 ? baseWhile(array, getIteratee(predicate, 3), true, true)
6271 * Creates a slice of `array` excluding elements dropped from the beginning.
6272 * Elements are dropped until `predicate` returns falsey. The predicate is
6273 * invoked with three arguments: (value, index, array).
6279 * @param {Array} array The array to query.
6280 * @param {Array|Function|Object|string} [predicate=_.identity]
6281 * The function invoked per iteration.
6282 * @returns {Array} Returns the slice of `array`.
6286 * { 'user': 'barney', 'active': false },
6287 * { 'user': 'fred', 'active': false },
6288 * { 'user': 'pebbles', 'active': true }
6291 * _.dropWhile(users, function(o) { return !o.active; });
6292 * // => objects for ['pebbles']
6294 * // The `_.matches` iteratee shorthand.
6295 * _.dropWhile(users, { 'user': 'barney', 'active': false });
6296 * // => objects for ['fred', 'pebbles']
6298 * // The `_.matchesProperty` iteratee shorthand.
6299 * _.dropWhile(users, ['active', false]);
6300 * // => objects for ['pebbles']
6302 * // The `_.property` iteratee shorthand.
6303 * _.dropWhile(users, 'active');
6304 * // => objects for ['barney', 'fred', 'pebbles']
6306 function dropWhile(array, predicate) {
6307 return (array && array.length)
6308 ? baseWhile(array, getIteratee(predicate, 3), true)
6313 * Fills elements of `array` with `value` from `start` up to, but not
6316 * **Note:** This method mutates `array`.
6322 * @param {Array} array The array to fill.
6323 * @param {*} value The value to fill `array` with.
6324 * @param {number} [start=0] The start position.
6325 * @param {number} [end=array.length] The end position.
6326 * @returns {Array} Returns `array`.
6329 * var array = [1, 2, 3];
6331 * _.fill(array, 'a');
6332 * console.log(array);
6333 * // => ['a', 'a', 'a']
6335 * _.fill(Array(3), 2);
6338 * _.fill([4, 6, 8, 10], '*', 1, 3);
6339 * // => [4, '*', '*', 10]
6341 function fill(array, value, start, end) {
6342 var length = array ? array.length : 0;
6346 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
6350 return baseFill(array, value, start, end);
6354 * This method is like `_.find` except that it returns the index of the first
6355 * element `predicate` returns truthy for instead of the element itself.
6361 * @param {Array} array The array to search.
6362 * @param {Array|Function|Object|string} [predicate=_.identity]
6363 * The function invoked per iteration.
6364 * @returns {number} Returns the index of the found element, else `-1`.
6368 * { 'user': 'barney', 'active': false },
6369 * { 'user': 'fred', 'active': false },
6370 * { 'user': 'pebbles', 'active': true }
6373 * _.findIndex(users, function(o) { return o.user == 'barney'; });
6376 * // The `_.matches` iteratee shorthand.
6377 * _.findIndex(users, { 'user': 'fred', 'active': false });
6380 * // The `_.matchesProperty` iteratee shorthand.
6381 * _.findIndex(users, ['active', false]);
6384 * // The `_.property` iteratee shorthand.
6385 * _.findIndex(users, 'active');
6388 function findIndex(array, predicate) {
6389 return (array && array.length)
6390 ? baseFindIndex(array, getIteratee(predicate, 3))
6395 * This method is like `_.findIndex` except that it iterates over elements
6396 * of `collection` from right to left.
6402 * @param {Array} array The array to search.
6403 * @param {Array|Function|Object|string} [predicate=_.identity]
6404 * The function invoked per iteration.
6405 * @returns {number} Returns the index of the found element, else `-1`.
6409 * { 'user': 'barney', 'active': true },
6410 * { 'user': 'fred', 'active': false },
6411 * { 'user': 'pebbles', 'active': false }
6414 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
6417 * // The `_.matches` iteratee shorthand.
6418 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
6421 * // The `_.matchesProperty` iteratee shorthand.
6422 * _.findLastIndex(users, ['active', false]);
6425 * // The `_.property` iteratee shorthand.
6426 * _.findLastIndex(users, 'active');
6429 function findLastIndex(array, predicate) {
6430 return (array && array.length)
6431 ? baseFindIndex(array, getIteratee(predicate, 3), true)
6436 * Flattens `array` a single level deep.
6442 * @param {Array} array The array to flatten.
6443 * @returns {Array} Returns the new flattened array.
6446 * _.flatten([1, [2, [3, [4]], 5]]);
6447 * // => [1, 2, [3, [4]], 5]
6449 function flatten(array) {
6450 var length = array ? array.length : 0;
6451 return length ? baseFlatten(array, 1) : [];
6455 * Recursively flattens `array`.
6461 * @param {Array} array The array to flatten.
6462 * @returns {Array} Returns the new flattened array.
6465 * _.flattenDeep([1, [2, [3, [4]], 5]]);
6466 * // => [1, 2, 3, 4, 5]
6468 function flattenDeep(array) {
6469 var length = array ? array.length : 0;
6470 return length ? baseFlatten(array, INFINITY) : [];
6474 * Recursively flatten `array` up to `depth` times.
6480 * @param {Array} array The array to flatten.
6481 * @param {number} [depth=1] The maximum recursion depth.
6482 * @returns {Array} Returns the new flattened array.
6485 * var array = [1, [2, [3, [4]], 5]];
6487 * _.flattenDepth(array, 1);
6488 * // => [1, 2, [3, [4]], 5]
6490 * _.flattenDepth(array, 2);
6491 * // => [1, 2, 3, [4], 5]
6493 function flattenDepth(array, depth) {
6494 var length = array ? array.length : 0;
6498 depth = depth === undefined ? 1 : toInteger(depth);
6499 return baseFlatten(array, depth);
6503 * The inverse of `_.toPairs`; this method returns an object composed
6504 * from key-value `pairs`.
6510 * @param {Array} pairs The key-value pairs.
6511 * @returns {Object} Returns the new object.
6514 * _.fromPairs([['fred', 30], ['barney', 40]]);
6515 * // => { 'fred': 30, 'barney': 40 }
6517 function fromPairs(pairs) {
6519 length = pairs ? pairs.length : 0,
6522 while (++index < length) {
6523 var pair = pairs[index];
6524 result[pair[0]] = pair[1];
6530 * Gets the first element of `array`.
6537 * @param {Array} array The array to query.
6538 * @returns {*} Returns the first element of `array`.
6541 * _.head([1, 2, 3]);
6547 function head(array) {
6548 return (array && array.length) ? array[0] : undefined;
6552 * Gets the index at which the first occurrence of `value` is found in `array`
6553 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6554 * for equality comparisons. If `fromIndex` is negative, it's used as the
6555 * offset from the end of `array`.
6561 * @param {Array} array The array to search.
6562 * @param {*} value The value to search for.
6563 * @param {number} [fromIndex=0] The index to search from.
6564 * @returns {number} Returns the index of the matched value, else `-1`.
6567 * _.indexOf([1, 2, 1, 2], 2);
6570 * // Search from the `fromIndex`.
6571 * _.indexOf([1, 2, 1, 2], 2, 2);
6574 function indexOf(array, value, fromIndex) {
6575 var length = array ? array.length : 0;
6579 fromIndex = toInteger(fromIndex);
6580 if (fromIndex < 0) {
6581 fromIndex = nativeMax(length + fromIndex, 0);
6583 return baseIndexOf(array, value, fromIndex);
6587 * Gets all but the last element of `array`.
6593 * @param {Array} array The array to query.
6594 * @returns {Array} Returns the slice of `array`.
6597 * _.initial([1, 2, 3]);
6600 function initial(array) {
6601 return dropRight(array, 1);
6605 * Creates an array of unique values that are included in all given arrays
6606 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6607 * for equality comparisons. The order of result values is determined by the
6608 * order they occur in the first array.
6614 * @param {...Array} [arrays] The arrays to inspect.
6615 * @returns {Array} Returns the new array of intersecting values.
6618 * _.intersection([2, 1], [4, 2], [1, 2]);
6621 var intersection = rest(function(arrays) {
6622 var mapped = arrayMap(arrays, castArrayLikeObject);
6623 return (mapped.length && mapped[0] === arrays[0])
6624 ? baseIntersection(mapped)
6629 * This method is like `_.intersection` except that it accepts `iteratee`
6630 * which is invoked for each element of each `arrays` to generate the criterion
6631 * by which they're compared. Result values are chosen from the first array.
6632 * The iteratee is invoked with one argument: (value).
6638 * @param {...Array} [arrays] The arrays to inspect.
6639 * @param {Array|Function|Object|string} [iteratee=_.identity]
6640 * The iteratee invoked per element.
6641 * @returns {Array} Returns the new array of intersecting values.
6644 * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
6647 * // The `_.property` iteratee shorthand.
6648 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
6649 * // => [{ 'x': 1 }]
6651 var intersectionBy = rest(function(arrays) {
6652 var iteratee = last(arrays),
6653 mapped = arrayMap(arrays, castArrayLikeObject);
6655 if (iteratee === last(mapped)) {
6656 iteratee = undefined;
6660 return (mapped.length && mapped[0] === arrays[0])
6661 ? baseIntersection(mapped, getIteratee(iteratee))
6666 * This method is like `_.intersection` except that it accepts `comparator`
6667 * which is invoked to compare elements of `arrays`. Result values are chosen
6668 * from the first array. The comparator is invoked with two arguments:
6675 * @param {...Array} [arrays] The arrays to inspect.
6676 * @param {Function} [comparator] The comparator invoked per element.
6677 * @returns {Array} Returns the new array of intersecting values.
6680 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6681 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
6683 * _.intersectionWith(objects, others, _.isEqual);
6684 * // => [{ 'x': 1, 'y': 2 }]
6686 var intersectionWith = rest(function(arrays) {
6687 var comparator = last(arrays),
6688 mapped = arrayMap(arrays, castArrayLikeObject);
6690 if (comparator === last(mapped)) {
6691 comparator = undefined;
6695 return (mapped.length && mapped[0] === arrays[0])
6696 ? baseIntersection(mapped, undefined, comparator)
6701 * Converts all elements in `array` into a string separated by `separator`.
6707 * @param {Array} array The array to convert.
6708 * @param {string} [separator=','] The element separator.
6709 * @returns {string} Returns the joined string.
6712 * _.join(['a', 'b', 'c'], '~');
6715 function join(array, separator) {
6716 return array ? nativeJoin.call(array, separator) : '';
6720 * Gets the last element of `array`.
6726 * @param {Array} array The array to query.
6727 * @returns {*} Returns the last element of `array`.
6730 * _.last([1, 2, 3]);
6733 function last(array) {
6734 var length = array ? array.length : 0;
6735 return length ? array[length - 1] : undefined;
6739 * This method is like `_.indexOf` except that it iterates over elements of
6740 * `array` from right to left.
6746 * @param {Array} array The array to search.
6747 * @param {*} value The value to search for.
6748 * @param {number} [fromIndex=array.length-1] The index to search from.
6749 * @returns {number} Returns the index of the matched value, else `-1`.
6752 * _.lastIndexOf([1, 2, 1, 2], 2);
6755 * // Search from the `fromIndex`.
6756 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
6759 function lastIndexOf(array, value, fromIndex) {
6760 var length = array ? array.length : 0;
6765 if (fromIndex !== undefined) {
6766 index = toInteger(fromIndex);
6769 ? nativeMax(length + index, 0)
6770 : nativeMin(index, length - 1)
6773 if (value !== value) {
6774 return indexOfNaN(array, index, true);
6777 if (array[index] === value) {
6785 * Gets the nth element of `array`. If `n` is negative, the nth element
6786 * from the end is returned.
6792 * @param {Array} array The array to query.
6793 * @param {number} [n=0] The index of the element to return.
6794 * @returns {*} Returns the nth element of `array`.
6797 * var array = ['a', 'b', 'c', 'd'];
6805 function nth(array, n) {
6806 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
6810 * Removes all given values from `array` using
6811 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6812 * for equality comparisons.
6814 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
6815 * to remove elements from an array by predicate.
6821 * @param {Array} array The array to modify.
6822 * @param {...*} [values] The values to remove.
6823 * @returns {Array} Returns `array`.
6826 * var array = [1, 2, 3, 1, 2, 3];
6828 * _.pull(array, 2, 3);
6829 * console.log(array);
6832 var pull = rest(pullAll);
6835 * This method is like `_.pull` except that it accepts an array of values to remove.
6837 * **Note:** Unlike `_.difference`, this method mutates `array`.
6843 * @param {Array} array The array to modify.
6844 * @param {Array} values The values to remove.
6845 * @returns {Array} Returns `array`.
6848 * var array = [1, 2, 3, 1, 2, 3];
6850 * _.pullAll(array, [2, 3]);
6851 * console.log(array);
6854 function pullAll(array, values) {
6855 return (array && array.length && values && values.length)
6856 ? basePullAll(array, values)
6861 * This method is like `_.pullAll` except that it accepts `iteratee` which is
6862 * invoked for each element of `array` and `values` to generate the criterion
6863 * by which they're compared. The iteratee is invoked with one argument: (value).
6865 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
6871 * @param {Array} array The array to modify.
6872 * @param {Array} values The values to remove.
6873 * @param {Array|Function|Object|string} [iteratee=_.identity]
6874 * The iteratee invoked per element.
6875 * @returns {Array} Returns `array`.
6878 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
6880 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
6881 * console.log(array);
6882 * // => [{ 'x': 2 }]
6884 function pullAllBy(array, values, iteratee) {
6885 return (array && array.length && values && values.length)
6886 ? basePullAll(array, values, getIteratee(iteratee))
6891 * This method is like `_.pullAll` except that it accepts `comparator` which
6892 * is invoked to compare elements of `array` to `values`. The comparator is
6893 * invoked with two arguments: (arrVal, othVal).
6895 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
6901 * @param {Array} array The array to modify.
6902 * @param {Array} values The values to remove.
6903 * @param {Function} [comparator] The comparator invoked per element.
6904 * @returns {Array} Returns `array`.
6907 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
6909 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
6910 * console.log(array);
6911 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
6913 function pullAllWith(array, values, comparator) {
6914 return (array && array.length && values && values.length)
6915 ? basePullAll(array, values, undefined, comparator)
6920 * Removes elements from `array` corresponding to `indexes` and returns an
6921 * array of removed elements.
6923 * **Note:** Unlike `_.at`, this method mutates `array`.
6929 * @param {Array} array The array to modify.
6930 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
6931 * @returns {Array} Returns the new array of removed elements.
6934 * var array = [5, 10, 15, 20];
6935 * var evens = _.pullAt(array, 1, 3);
6937 * console.log(array);
6940 * console.log(evens);
6943 var pullAt = rest(function(array, indexes) {
6944 indexes = baseFlatten(indexes, 1);
6946 var length = array ? array.length : 0,
6947 result = baseAt(array, indexes);
6949 basePullAt(array, arrayMap(indexes, function(index) {
6950 return isIndex(index, length) ? +index : index;
6951 }).sort(compareAscending));
6957 * Removes all elements from `array` that `predicate` returns truthy for
6958 * and returns an array of the removed elements. The predicate is invoked
6959 * with three arguments: (value, index, array).
6961 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
6962 * to pull elements from an array by value.
6968 * @param {Array} array The array to modify.
6969 * @param {Array|Function|Object|string} [predicate=_.identity]
6970 * The function invoked per iteration.
6971 * @returns {Array} Returns the new array of removed elements.
6974 * var array = [1, 2, 3, 4];
6975 * var evens = _.remove(array, function(n) {
6976 * return n % 2 == 0;
6979 * console.log(array);
6982 * console.log(evens);
6985 function remove(array, predicate) {
6987 if (!(array && array.length)) {
6992 length = array.length;
6994 predicate = getIteratee(predicate, 3);
6995 while (++index < length) {
6996 var value = array[index];
6997 if (predicate(value, index, array)) {
6999 indexes.push(index);
7002 basePullAt(array, indexes);
7007 * Reverses `array` so that the first element becomes the last, the second
7008 * element becomes the second to last, and so on.
7010 * **Note:** This method mutates `array` and is based on
7011 * [`Array#reverse`](https://mdn.io/Array/reverse).
7017 * @param {Array} array The array to modify.
7018 * @returns {Array} Returns `array`.
7021 * var array = [1, 2, 3];
7026 * console.log(array);
7029 function reverse(array) {
7030 return array ? nativeReverse.call(array) : array;
7034 * Creates a slice of `array` from `start` up to, but not including, `end`.
7036 * **Note:** This method is used instead of
7037 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7044 * @param {Array} array The array to slice.
7045 * @param {number} [start=0] The start position.
7046 * @param {number} [end=array.length] The end position.
7047 * @returns {Array} Returns the slice of `array`.
7049 function slice(array, start, end) {
7050 var length = array ? array.length : 0;
7054 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
7059 start = start == null ? 0 : toInteger(start);
7060 end = end === undefined ? length : toInteger(end);
7062 return baseSlice(array, start, end);
7066 * Uses a binary search to determine the lowest index at which `value`
7067 * should be inserted into `array` in order to maintain its sort order.
7073 * @param {Array} array The sorted array to inspect.
7074 * @param {*} value The value to evaluate.
7075 * @returns {number} Returns the index at which `value` should be inserted
7079 * _.sortedIndex([30, 50], 40);
7082 * _.sortedIndex([4, 5], 4);
7085 function sortedIndex(array, value) {
7086 return baseSortedIndex(array, value);
7090 * This method is like `_.sortedIndex` except that it accepts `iteratee`
7091 * which is invoked for `value` and each element of `array` to compute their
7092 * sort ranking. The iteratee is invoked with one argument: (value).
7098 * @param {Array} array The sorted array to inspect.
7099 * @param {*} value The value to evaluate.
7100 * @param {Array|Function|Object|string} [iteratee=_.identity]
7101 * The iteratee invoked per element.
7102 * @returns {number} Returns the index at which `value` should be inserted
7106 * var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 };
7108 * _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict));
7111 * // The `_.property` iteratee shorthand.
7112 * _.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
7115 function sortedIndexBy(array, value, iteratee) {
7116 return baseSortedIndexBy(array, value, getIteratee(iteratee));
7120 * This method is like `_.indexOf` except that it performs a binary
7121 * search on a sorted `array`.
7127 * @param {Array} array The array to search.
7128 * @param {*} value The value to search for.
7129 * @returns {number} Returns the index of the matched value, else `-1`.
7132 * _.sortedIndexOf([1, 1, 2, 2], 2);
7135 function sortedIndexOf(array, value) {
7136 var length = array ? array.length : 0;
7138 var index = baseSortedIndex(array, value);
7139 if (index < length && eq(array[index], value)) {
7147 * This method is like `_.sortedIndex` except that it returns the highest
7148 * index at which `value` should be inserted into `array` in order to
7149 * maintain its sort order.
7155 * @param {Array} array The sorted array to inspect.
7156 * @param {*} value The value to evaluate.
7157 * @returns {number} Returns the index at which `value` should be inserted
7161 * _.sortedLastIndex([4, 5], 4);
7164 function sortedLastIndex(array, value) {
7165 return baseSortedIndex(array, value, true);
7169 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
7170 * which is invoked for `value` and each element of `array` to compute their
7171 * sort ranking. The iteratee is invoked with one argument: (value).
7177 * @param {Array} array The sorted array to inspect.
7178 * @param {*} value The value to evaluate.
7179 * @param {Array|Function|Object|string} [iteratee=_.identity]
7180 * The iteratee invoked per element.
7181 * @returns {number} Returns the index at which `value` should be inserted
7185 * // The `_.property` iteratee shorthand.
7186 * _.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x');
7189 function sortedLastIndexBy(array, value, iteratee) {
7190 return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
7194 * This method is like `_.lastIndexOf` except that it performs a binary
7195 * search on a sorted `array`.
7201 * @param {Array} array The array to search.
7202 * @param {*} value The value to search for.
7203 * @returns {number} Returns the index of the matched value, else `-1`.
7206 * _.sortedLastIndexOf([1, 1, 2, 2], 2);
7209 function sortedLastIndexOf(array, value) {
7210 var length = array ? array.length : 0;
7212 var index = baseSortedIndex(array, value, true) - 1;
7213 if (eq(array[index], value)) {
7221 * This method is like `_.uniq` except that it's designed and optimized
7222 * for sorted arrays.
7228 * @param {Array} array The array to inspect.
7229 * @returns {Array} Returns the new duplicate free array.
7232 * _.sortedUniq([1, 1, 2]);
7235 function sortedUniq(array) {
7236 return (array && array.length)
7237 ? baseSortedUniq(array)
7242 * This method is like `_.uniqBy` except that it's designed and optimized
7243 * for sorted arrays.
7249 * @param {Array} array The array to inspect.
7250 * @param {Function} [iteratee] The iteratee invoked per element.
7251 * @returns {Array} Returns the new duplicate free array.
7254 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
7257 function sortedUniqBy(array, iteratee) {
7258 return (array && array.length)
7259 ? baseSortedUniq(array, getIteratee(iteratee))
7264 * Gets all but the first element of `array`.
7270 * @param {Array} array The array to query.
7271 * @returns {Array} Returns the slice of `array`.
7274 * _.tail([1, 2, 3]);
7277 function tail(array) {
7278 return drop(array, 1);
7282 * Creates a slice of `array` with `n` elements taken from the beginning.
7288 * @param {Array} array The array to query.
7289 * @param {number} [n=1] The number of elements to take.
7290 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7291 * @returns {Array} Returns the slice of `array`.
7294 * _.take([1, 2, 3]);
7297 * _.take([1, 2, 3], 2);
7300 * _.take([1, 2, 3], 5);
7303 * _.take([1, 2, 3], 0);
7306 function take(array, n, guard) {
7307 if (!(array && array.length)) {
7310 n = (guard || n === undefined) ? 1 : toInteger(n);
7311 return baseSlice(array, 0, n < 0 ? 0 : n);
7315 * Creates a slice of `array` with `n` elements taken from the end.
7321 * @param {Array} array The array to query.
7322 * @param {number} [n=1] The number of elements to take.
7323 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7324 * @returns {Array} Returns the slice of `array`.
7327 * _.takeRight([1, 2, 3]);
7330 * _.takeRight([1, 2, 3], 2);
7333 * _.takeRight([1, 2, 3], 5);
7336 * _.takeRight([1, 2, 3], 0);
7339 function takeRight(array, n, guard) {
7340 var length = array ? array.length : 0;
7344 n = (guard || n === undefined) ? 1 : toInteger(n);
7346 return baseSlice(array, n < 0 ? 0 : n, length);
7350 * Creates a slice of `array` with elements taken from the end. Elements are
7351 * taken until `predicate` returns falsey. The predicate is invoked with
7352 * three arguments: (value, index, array).
7358 * @param {Array} array The array to query.
7359 * @param {Array|Function|Object|string} [predicate=_.identity]
7360 * The function invoked per iteration.
7361 * @returns {Array} Returns the slice of `array`.
7365 * { 'user': 'barney', 'active': true },
7366 * { 'user': 'fred', 'active': false },
7367 * { 'user': 'pebbles', 'active': false }
7370 * _.takeRightWhile(users, function(o) { return !o.active; });
7371 * // => objects for ['fred', 'pebbles']
7373 * // The `_.matches` iteratee shorthand.
7374 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
7375 * // => objects for ['pebbles']
7377 * // The `_.matchesProperty` iteratee shorthand.
7378 * _.takeRightWhile(users, ['active', false]);
7379 * // => objects for ['fred', 'pebbles']
7381 * // The `_.property` iteratee shorthand.
7382 * _.takeRightWhile(users, 'active');
7385 function takeRightWhile(array, predicate) {
7386 return (array && array.length)
7387 ? baseWhile(array, getIteratee(predicate, 3), false, true)
7392 * Creates a slice of `array` with elements taken from the beginning. Elements
7393 * are taken until `predicate` returns falsey. The predicate is invoked with
7394 * three arguments: (value, index, array).
7400 * @param {Array} array The array to query.
7401 * @param {Array|Function|Object|string} [predicate=_.identity]
7402 * The function invoked per iteration.
7403 * @returns {Array} Returns the slice of `array`.
7407 * { 'user': 'barney', 'active': false },
7408 * { 'user': 'fred', 'active': false},
7409 * { 'user': 'pebbles', 'active': true }
7412 * _.takeWhile(users, function(o) { return !o.active; });
7413 * // => objects for ['barney', 'fred']
7415 * // The `_.matches` iteratee shorthand.
7416 * _.takeWhile(users, { 'user': 'barney', 'active': false });
7417 * // => objects for ['barney']
7419 * // The `_.matchesProperty` iteratee shorthand.
7420 * _.takeWhile(users, ['active', false]);
7421 * // => objects for ['barney', 'fred']
7423 * // The `_.property` iteratee shorthand.
7424 * _.takeWhile(users, 'active');
7427 function takeWhile(array, predicate) {
7428 return (array && array.length)
7429 ? baseWhile(array, getIteratee(predicate, 3))
7434 * Creates an array of unique values, in order, from all given arrays using
7435 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7436 * for equality comparisons.
7442 * @param {...Array} [arrays] The arrays to inspect.
7443 * @returns {Array} Returns the new array of combined values.
7446 * _.union([2, 1], [4, 2], [1, 2]);
7449 var union = rest(function(arrays) {
7450 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
7454 * This method is like `_.union` except that it accepts `iteratee` which is
7455 * invoked for each element of each `arrays` to generate the criterion by
7456 * which uniqueness is computed. The iteratee is invoked with one argument:
7463 * @param {...Array} [arrays] The arrays to inspect.
7464 * @param {Array|Function|Object|string} [iteratee=_.identity]
7465 * The iteratee invoked per element.
7466 * @returns {Array} Returns the new array of combined values.
7469 * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
7470 * // => [2.1, 1.2, 4.3]
7472 * // The `_.property` iteratee shorthand.
7473 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7474 * // => [{ 'x': 1 }, { 'x': 2 }]
7476 var unionBy = rest(function(arrays) {
7477 var iteratee = last(arrays);
7478 if (isArrayLikeObject(iteratee)) {
7479 iteratee = undefined;
7481 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee));
7485 * This method is like `_.union` except that it accepts `comparator` which
7486 * is invoked to compare elements of `arrays`. The comparator is invoked
7487 * with two arguments: (arrVal, othVal).
7493 * @param {...Array} [arrays] The arrays to inspect.
7494 * @param {Function} [comparator] The comparator invoked per element.
7495 * @returns {Array} Returns the new array of combined values.
7498 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7499 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7501 * _.unionWith(objects, others, _.isEqual);
7502 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
7504 var unionWith = rest(function(arrays) {
7505 var comparator = last(arrays);
7506 if (isArrayLikeObject(comparator)) {
7507 comparator = undefined;
7509 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
7513 * Creates a duplicate-free version of an array, using
7514 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7515 * for equality comparisons, in which only the first occurrence of each
7522 * @param {Array} array The array to inspect.
7523 * @returns {Array} Returns the new duplicate free array.
7526 * _.uniq([2, 1, 2]);
7529 function uniq(array) {
7530 return (array && array.length)
7536 * This method is like `_.uniq` except that it accepts `iteratee` which is
7537 * invoked for each element in `array` to generate the criterion by which
7538 * uniqueness is computed. The iteratee is invoked with one argument: (value).
7544 * @param {Array} array The array to inspect.
7545 * @param {Array|Function|Object|string} [iteratee=_.identity]
7546 * The iteratee invoked per element.
7547 * @returns {Array} Returns the new duplicate free array.
7550 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
7553 * // The `_.property` iteratee shorthand.
7554 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
7555 * // => [{ 'x': 1 }, { 'x': 2 }]
7557 function uniqBy(array, iteratee) {
7558 return (array && array.length)
7559 ? baseUniq(array, getIteratee(iteratee))
7564 * This method is like `_.uniq` except that it accepts `comparator` which
7565 * is invoked to compare elements of `array`. The comparator is invoked with
7566 * two arguments: (arrVal, othVal).
7572 * @param {Array} array The array to inspect.
7573 * @param {Function} [comparator] The comparator invoked per element.
7574 * @returns {Array} Returns the new duplicate free array.
7577 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
7579 * _.uniqWith(objects, _.isEqual);
7580 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
7582 function uniqWith(array, comparator) {
7583 return (array && array.length)
7584 ? baseUniq(array, undefined, comparator)
7589 * This method is like `_.zip` except that it accepts an array of grouped
7590 * elements and creates an array regrouping the elements to their pre-zip
7597 * @param {Array} array The array of grouped elements to process.
7598 * @returns {Array} Returns the new array of regrouped elements.
7601 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
7602 * // => [['fred', 30, true], ['barney', 40, false]]
7605 * // => [['fred', 'barney'], [30, 40], [true, false]]
7607 function unzip(array) {
7608 if (!(array && array.length)) {
7612 array = arrayFilter(array, function(group) {
7613 if (isArrayLikeObject(group)) {
7614 length = nativeMax(group.length, length);
7618 return baseTimes(length, function(index) {
7619 return arrayMap(array, baseProperty(index));
7624 * This method is like `_.unzip` except that it accepts `iteratee` to specify
7625 * how regrouped values should be combined. The iteratee is invoked with the
7626 * elements of each group: (...group).
7632 * @param {Array} array The array of grouped elements to process.
7633 * @param {Function} [iteratee=_.identity] The function to combine
7635 * @returns {Array} Returns the new array of regrouped elements.
7638 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
7639 * // => [[1, 10, 100], [2, 20, 200]]
7641 * _.unzipWith(zipped, _.add);
7642 * // => [3, 30, 300]
7644 function unzipWith(array, iteratee) {
7645 if (!(array && array.length)) {
7648 var result = unzip(array);
7649 if (iteratee == null) {
7652 return arrayMap(result, function(group) {
7653 return apply(iteratee, undefined, group);
7658 * Creates an array excluding all given values using
7659 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
7660 * for equality comparisons.
7666 * @param {Array} array The array to filter.
7667 * @param {...*} [values] The values to exclude.
7668 * @returns {Array} Returns the new array of filtered values.
7669 * @see _.difference, _.xor
7672 * _.without([1, 2, 1, 3], 1, 2);
7675 var without = rest(function(array, values) {
7676 return isArrayLikeObject(array)
7677 ? baseDifference(array, values)
7682 * Creates an array of unique values that is the
7683 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
7684 * of the given arrays. The order of result values is determined by the order
7685 * they occur in the arrays.
7691 * @param {...Array} [arrays] The arrays to inspect.
7692 * @returns {Array} Returns the new array of values.
7693 * @see _.difference, _.without
7696 * _.xor([2, 1], [4, 2]);
7699 var xor = rest(function(arrays) {
7700 return baseXor(arrayFilter(arrays, isArrayLikeObject));
7704 * This method is like `_.xor` except that it accepts `iteratee` which is
7705 * invoked for each element of each `arrays` to generate the criterion by
7706 * which by which they're compared. The iteratee is invoked with one argument:
7713 * @param {...Array} [arrays] The arrays to inspect.
7714 * @param {Array|Function|Object|string} [iteratee=_.identity]
7715 * The iteratee invoked per element.
7716 * @returns {Array} Returns the new array of values.
7719 * _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor);
7722 * // The `_.property` iteratee shorthand.
7723 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7724 * // => [{ 'x': 2 }]
7726 var xorBy = rest(function(arrays) {
7727 var iteratee = last(arrays);
7728 if (isArrayLikeObject(iteratee)) {
7729 iteratee = undefined;
7731 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
7735 * This method is like `_.xor` except that it accepts `comparator` which is
7736 * invoked to compare elements of `arrays`. The comparator is invoked with
7737 * two arguments: (arrVal, othVal).
7743 * @param {...Array} [arrays] The arrays to inspect.
7744 * @param {Function} [comparator] The comparator invoked per element.
7745 * @returns {Array} Returns the new array of values.
7748 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7749 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7751 * _.xorWith(objects, others, _.isEqual);
7752 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
7754 var xorWith = rest(function(arrays) {
7755 var comparator = last(arrays);
7756 if (isArrayLikeObject(comparator)) {
7757 comparator = undefined;
7759 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
7763 * Creates an array of grouped elements, the first of which contains the
7764 * first elements of the given arrays, the second of which contains the
7765 * second elements of the given arrays, and so on.
7771 * @param {...Array} [arrays] The arrays to process.
7772 * @returns {Array} Returns the new array of grouped elements.
7775 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
7776 * // => [['fred', 30, true], ['barney', 40, false]]
7778 var zip = rest(unzip);
7781 * This method is like `_.fromPairs` except that it accepts two arrays,
7782 * one of property identifiers and one of corresponding values.
7788 * @param {Array} [props=[]] The property identifiers.
7789 * @param {Array} [values=[]] The property values.
7790 * @returns {Object} Returns the new object.
7793 * _.zipObject(['a', 'b'], [1, 2]);
7794 * // => { 'a': 1, 'b': 2 }
7796 function zipObject(props, values) {
7797 return baseZipObject(props || [], values || [], assignValue);
7801 * This method is like `_.zipObject` except that it supports property paths.
7807 * @param {Array} [props=[]] The property identifiers.
7808 * @param {Array} [values=[]] The property values.
7809 * @returns {Object} Returns the new object.
7812 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
7813 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
7815 function zipObjectDeep(props, values) {
7816 return baseZipObject(props || [], values || [], baseSet);
7820 * This method is like `_.zip` except that it accepts `iteratee` to specify
7821 * how grouped values should be combined. The iteratee is invoked with the
7822 * elements of each group: (...group).
7828 * @param {...Array} [arrays] The arrays to process.
7829 * @param {Function} [iteratee=_.identity] The function to combine grouped values.
7830 * @returns {Array} Returns the new array of grouped elements.
7833 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
7838 var zipWith = rest(function(arrays) {
7839 var length = arrays.length,
7840 iteratee = length > 1 ? arrays[length - 1] : undefined;
7842 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
7843 return unzipWith(arrays, iteratee);
7846 /*------------------------------------------------------------------------*/
7849 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
7850 * chain sequences enabled. The result of such sequences must be unwrapped
7857 * @param {*} value The value to wrap.
7858 * @returns {Object} Returns the new `lodash` wrapper instance.
7862 * { 'user': 'barney', 'age': 36 },
7863 * { 'user': 'fred', 'age': 40 },
7864 * { 'user': 'pebbles', 'age': 1 }
7870 * .map(function(o) {
7871 * return o.user + ' is ' + o.age;
7875 * // => 'pebbles is 1'
7877 function chain(value) {
7878 var result = lodash(value);
7879 result.__chain__ = true;
7884 * This method invokes `interceptor` and returns `value`. The interceptor
7885 * is invoked with one argument; (value). The purpose of this method is to
7886 * "tap into" a method chain sequence in order to modify intermediate results.
7892 * @param {*} value The value to provide to `interceptor`.
7893 * @param {Function} interceptor The function to invoke.
7894 * @returns {*} Returns `value`.
7898 * .tap(function(array) {
7899 * // Mutate input array.
7906 function tap(value, interceptor) {
7912 * This method is like `_.tap` except that it returns the result of `interceptor`.
7913 * The purpose of this method is to "pass thru" values replacing intermediate
7914 * results in a method chain sequence.
7920 * @param {*} value The value to provide to `interceptor`.
7921 * @param {Function} interceptor The function to invoke.
7922 * @returns {*} Returns the result of `interceptor`.
7928 * .thru(function(value) {
7934 function thru(value, interceptor) {
7935 return interceptor(value);
7939 * This method is the wrapper version of `_.at`.
7945 * @param {...(string|string[])} [paths] The property paths of elements to pick.
7946 * @returns {Object} Returns the new `lodash` wrapper instance.
7949 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
7951 * _(object).at(['a[0].b.c', 'a[1]']).value();
7954 * _(['a', 'b', 'c']).at(0, 2).value();
7957 var wrapperAt = rest(function(paths) {
7958 paths = baseFlatten(paths, 1);
7959 var length = paths.length,
7960 start = length ? paths[0] : 0,
7961 value = this.__wrapped__,
7962 interceptor = function(object) { return baseAt(object, paths); };
7964 if (length > 1 || this.__actions__.length ||
7965 !(value instanceof LazyWrapper) || !isIndex(start)) {
7966 return this.thru(interceptor);
7968 value = value.slice(start, +start + (length ? 1 : 0));
7969 value.__actions__.push({
7971 'args': [interceptor],
7972 'thisArg': undefined
7974 return new LodashWrapper(value, this.__chain__).thru(function(array) {
7975 if (length && !array.length) {
7976 array.push(undefined);
7983 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
7989 * @returns {Object} Returns the new `lodash` wrapper instance.
7993 * { 'user': 'barney', 'age': 36 },
7994 * { 'user': 'fred', 'age': 40 }
7997 * // A sequence without explicit chaining.
7999 * // => { 'user': 'barney', 'age': 36 }
8001 * // A sequence with explicit chaining.
8007 * // => { 'user': 'barney' }
8009 function wrapperChain() {
8014 * Executes the chain sequence and returns the wrapped result.
8020 * @returns {Object} Returns the new `lodash` wrapper instance.
8023 * var array = [1, 2];
8024 * var wrapped = _(array).push(3);
8026 * console.log(array);
8029 * wrapped = wrapped.commit();
8030 * console.log(array);
8036 * console.log(array);
8039 function wrapperCommit() {
8040 return new LodashWrapper(this.value(), this.__chain__);
8044 * Gets the next value on a wrapped object following the
8045 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8051 * @returns {Object} Returns the next iterator value.
8054 * var wrapped = _([1, 2]);
8057 * // => { 'done': false, 'value': 1 }
8060 * // => { 'done': false, 'value': 2 }
8063 * // => { 'done': true, 'value': undefined }
8065 function wrapperNext() {
8066 if (this.__values__ === undefined) {
8067 this.__values__ = toArray(this.value());
8069 var done = this.__index__ >= this.__values__.length,
8070 value = done ? undefined : this.__values__[this.__index__++];
8072 return { 'done': done, 'value': value };
8076 * Enables the wrapper to be iterable.
8078 * @name Symbol.iterator
8082 * @returns {Object} Returns the wrapper object.
8085 * var wrapped = _([1, 2]);
8087 * wrapped[Symbol.iterator]() === wrapped;
8090 * Array.from(wrapped);
8093 function wrapperToIterator() {
8098 * Creates a clone of the chain sequence planting `value` as the wrapped value.
8104 * @param {*} value The value to plant.
8105 * @returns {Object} Returns the new `lodash` wrapper instance.
8108 * function square(n) {
8112 * var wrapped = _([1, 2]).map(square);
8113 * var other = wrapped.plant([3, 4]);
8121 function wrapperPlant(value) {
8125 while (parent instanceof baseLodash) {
8126 var clone = wrapperClone(parent);
8127 clone.__index__ = 0;
8128 clone.__values__ = undefined;
8130 previous.__wrapped__ = clone;
8134 var previous = clone;
8135 parent = parent.__wrapped__;
8137 previous.__wrapped__ = value;
8142 * This method is the wrapper version of `_.reverse`.
8144 * **Note:** This method mutates the wrapped array.
8150 * @returns {Object} Returns the new `lodash` wrapper instance.
8153 * var array = [1, 2, 3];
8155 * _(array).reverse().value()
8158 * console.log(array);
8161 function wrapperReverse() {
8162 var value = this.__wrapped__;
8163 if (value instanceof LazyWrapper) {
8164 var wrapped = value;
8165 if (this.__actions__.length) {
8166 wrapped = new LazyWrapper(this);
8168 wrapped = wrapped.reverse();
8169 wrapped.__actions__.push({
8172 'thisArg': undefined
8174 return new LodashWrapper(wrapped, this.__chain__);
8176 return this.thru(reverse);
8180 * Executes the chain sequence to resolve the unwrapped value.
8185 * @alias toJSON, valueOf
8187 * @returns {*} Returns the resolved unwrapped value.
8190 * _([1, 2, 3]).value();
8193 function wrapperValue() {
8194 return baseWrapperValue(this.__wrapped__, this.__actions__);
8197 /*------------------------------------------------------------------------*/
8200 * Creates an object composed of keys generated from the results of running
8201 * each element of `collection` thru `iteratee`. The corresponding value of
8202 * each key is the number of times the key was returned by `iteratee`. The
8203 * iteratee is invoked with one argument: (value).
8208 * @category Collection
8209 * @param {Array|Object} collection The collection to iterate over.
8210 * @param {Array|Function|Object|string} [iteratee=_.identity]
8211 * The iteratee to transform keys.
8212 * @returns {Object} Returns the composed aggregate object.
8215 * _.countBy([6.1, 4.2, 6.3], Math.floor);
8216 * // => { '4': 1, '6': 2 }
8218 * _.countBy(['one', 'two', 'three'], 'length');
8219 * // => { '3': 2, '5': 1 }
8221 var countBy = createAggregator(function(result, value, key) {
8222 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
8226 * Checks if `predicate` returns truthy for **all** elements of `collection`.
8227 * Iteration is stopped once `predicate` returns falsey. The predicate is
8228 * invoked with three arguments: (value, index|key, collection).
8233 * @category Collection
8234 * @param {Array|Object} collection The collection to iterate over.
8235 * @param {Array|Function|Object|string} [predicate=_.identity]
8236 * The function invoked per iteration.
8237 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8238 * @returns {boolean} Returns `true` if all elements pass the predicate check,
8242 * _.every([true, 1, null, 'yes'], Boolean);
8246 * { 'user': 'barney', 'age': 36, 'active': false },
8247 * { 'user': 'fred', 'age': 40, 'active': false }
8250 * // The `_.matches` iteratee shorthand.
8251 * _.every(users, { 'user': 'barney', 'active': false });
8254 * // The `_.matchesProperty` iteratee shorthand.
8255 * _.every(users, ['active', false]);
8258 * // The `_.property` iteratee shorthand.
8259 * _.every(users, 'active');
8262 function every(collection, predicate, guard) {
8263 var func = isArray(collection) ? arrayEvery : baseEvery;
8264 if (guard && isIterateeCall(collection, predicate, guard)) {
8265 predicate = undefined;
8267 return func(collection, getIteratee(predicate, 3));
8271 * Iterates over elements of `collection`, returning an array of all elements
8272 * `predicate` returns truthy for. The predicate is invoked with three
8273 * arguments: (value, index|key, collection).
8278 * @category Collection
8279 * @param {Array|Object} collection The collection to iterate over.
8280 * @param {Array|Function|Object|string} [predicate=_.identity]
8281 * The function invoked per iteration.
8282 * @returns {Array} Returns the new filtered array.
8287 * { 'user': 'barney', 'age': 36, 'active': true },
8288 * { 'user': 'fred', 'age': 40, 'active': false }
8291 * _.filter(users, function(o) { return !o.active; });
8292 * // => objects for ['fred']
8294 * // The `_.matches` iteratee shorthand.
8295 * _.filter(users, { 'age': 36, 'active': true });
8296 * // => objects for ['barney']
8298 * // The `_.matchesProperty` iteratee shorthand.
8299 * _.filter(users, ['active', false]);
8300 * // => objects for ['fred']
8302 * // The `_.property` iteratee shorthand.
8303 * _.filter(users, 'active');
8304 * // => objects for ['barney']
8306 function filter(collection, predicate) {
8307 var func = isArray(collection) ? arrayFilter : baseFilter;
8308 return func(collection, getIteratee(predicate, 3));
8312 * Iterates over elements of `collection`, returning the first element
8313 * `predicate` returns truthy for. The predicate is invoked with three
8314 * arguments: (value, index|key, collection).
8319 * @category Collection
8320 * @param {Array|Object} collection The collection to search.
8321 * @param {Array|Function|Object|string} [predicate=_.identity]
8322 * The function invoked per iteration.
8323 * @returns {*} Returns the matched element, else `undefined`.
8327 * { 'user': 'barney', 'age': 36, 'active': true },
8328 * { 'user': 'fred', 'age': 40, 'active': false },
8329 * { 'user': 'pebbles', 'age': 1, 'active': true }
8332 * _.find(users, function(o) { return o.age < 40; });
8333 * // => object for 'barney'
8335 * // The `_.matches` iteratee shorthand.
8336 * _.find(users, { 'age': 1, 'active': true });
8337 * // => object for 'pebbles'
8339 * // The `_.matchesProperty` iteratee shorthand.
8340 * _.find(users, ['active', false]);
8341 * // => object for 'fred'
8343 * // The `_.property` iteratee shorthand.
8344 * _.find(users, 'active');
8345 * // => object for 'barney'
8347 function find(collection, predicate) {
8348 predicate = getIteratee(predicate, 3);
8349 if (isArray(collection)) {
8350 var index = baseFindIndex(collection, predicate);
8351 return index > -1 ? collection[index] : undefined;
8353 return baseFind(collection, predicate, baseEach);
8357 * This method is like `_.find` except that it iterates over elements of
8358 * `collection` from right to left.
8363 * @category Collection
8364 * @param {Array|Object} collection The collection to search.
8365 * @param {Array|Function|Object|string} [predicate=_.identity]
8366 * The function invoked per iteration.
8367 * @returns {*} Returns the matched element, else `undefined`.
8370 * _.findLast([1, 2, 3, 4], function(n) {
8371 * return n % 2 == 1;
8375 function findLast(collection, predicate) {
8376 predicate = getIteratee(predicate, 3);
8377 if (isArray(collection)) {
8378 var index = baseFindIndex(collection, predicate, true);
8379 return index > -1 ? collection[index] : undefined;
8381 return baseFind(collection, predicate, baseEachRight);
8385 * Creates a flattened array of values by running each element in `collection`
8386 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
8387 * with three arguments: (value, index|key, collection).
8392 * @category Collection
8393 * @param {Array|Object} collection The collection to iterate over.
8394 * @param {Array|Function|Object|string} [iteratee=_.identity]
8395 * The function invoked per iteration.
8396 * @returns {Array} Returns the new flattened array.
8399 * function duplicate(n) {
8403 * _.flatMap([1, 2], duplicate);
8404 * // => [1, 1, 2, 2]
8406 function flatMap(collection, iteratee) {
8407 return baseFlatten(map(collection, iteratee), 1);
8411 * This method is like `_.flatMap` except that it recursively flattens the
8417 * @category Collection
8418 * @param {Array|Object} collection The collection to iterate over.
8419 * @param {Array|Function|Object|string} [iteratee=_.identity]
8420 * The function invoked per iteration.
8421 * @returns {Array} Returns the new flattened array.
8424 * function duplicate(n) {
8425 * return [[[n, n]]];
8428 * _.flatMapDeep([1, 2], duplicate);
8429 * // => [1, 1, 2, 2]
8431 function flatMapDeep(collection, iteratee) {
8432 return baseFlatten(map(collection, iteratee), INFINITY);
8436 * This method is like `_.flatMap` except that it recursively flattens the
8437 * mapped results up to `depth` times.
8442 * @category Collection
8443 * @param {Array|Object} collection The collection to iterate over.
8444 * @param {Array|Function|Object|string} [iteratee=_.identity]
8445 * The function invoked per iteration.
8446 * @param {number} [depth=1] The maximum recursion depth.
8447 * @returns {Array} Returns the new flattened array.
8450 * function duplicate(n) {
8451 * return [[[n, n]]];
8454 * _.flatMapDepth([1, 2], duplicate, 2);
8455 * // => [[1, 1], [2, 2]]
8457 function flatMapDepth(collection, iteratee, depth) {
8458 depth = depth === undefined ? 1 : toInteger(depth);
8459 return baseFlatten(map(collection, iteratee), depth);
8463 * Iterates over elements of `collection` and invokes `iteratee` for each element.
8464 * The iteratee is invoked with three arguments: (value, index|key, collection).
8465 * Iteratee functions may exit iteration early by explicitly returning `false`.
8467 * **Note:** As with other "Collections" methods, objects with a "length"
8468 * property are iterated like arrays. To avoid this behavior use `_.forIn`
8469 * or `_.forOwn` for object iteration.
8475 * @category Collection
8476 * @param {Array|Object} collection The collection to iterate over.
8477 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8478 * @returns {Array|Object} Returns `collection`.
8479 * @see _.forEachRight
8482 * _([1, 2]).forEach(function(value) {
8483 * console.log(value);
8485 * // => Logs `1` then `2`.
8487 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
8490 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
8492 function forEach(collection, iteratee) {
8493 return (typeof iteratee == 'function' && isArray(collection))
8494 ? arrayEach(collection, iteratee)
8495 : baseEach(collection, getIteratee(iteratee));
8499 * This method is like `_.forEach` except that it iterates over elements of
8500 * `collection` from right to left.
8506 * @category Collection
8507 * @param {Array|Object} collection The collection to iterate over.
8508 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8509 * @returns {Array|Object} Returns `collection`.
8513 * _.forEachRight([1, 2], function(value) {
8514 * console.log(value);
8516 * // => Logs `2` then `1`.
8518 function forEachRight(collection, iteratee) {
8519 return (typeof iteratee == 'function' && isArray(collection))
8520 ? arrayEachRight(collection, iteratee)
8521 : baseEachRight(collection, getIteratee(iteratee));
8525 * Creates an object composed of keys generated from the results of running
8526 * each element of `collection` thru `iteratee`. The order of grouped values
8527 * is determined by the order they occur in `collection`. The corresponding
8528 * value of each key is an array of elements responsible for generating the
8529 * key. The iteratee is invoked with one argument: (value).
8534 * @category Collection
8535 * @param {Array|Object} collection The collection to iterate over.
8536 * @param {Array|Function|Object|string} [iteratee=_.identity]
8537 * The iteratee to transform keys.
8538 * @returns {Object} Returns the composed aggregate object.
8541 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
8542 * // => { '4': [4.2], '6': [6.1, 6.3] }
8544 * // The `_.property` iteratee shorthand.
8545 * _.groupBy(['one', 'two', 'three'], 'length');
8546 * // => { '3': ['one', 'two'], '5': ['three'] }
8548 var groupBy = createAggregator(function(result, value, key) {
8549 if (hasOwnProperty.call(result, key)) {
8550 result[key].push(value);
8552 result[key] = [value];
8557 * Checks if `value` is in `collection`. If `collection` is a string, it's
8558 * checked for a substring of `value`, otherwise
8559 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
8560 * is used for equality comparisons. If `fromIndex` is negative, it's used as
8561 * the offset from the end of `collection`.
8566 * @category Collection
8567 * @param {Array|Object|string} collection The collection to search.
8568 * @param {*} value The value to search for.
8569 * @param {number} [fromIndex=0] The index to search from.
8570 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
8571 * @returns {boolean} Returns `true` if `value` is found, else `false`.
8574 * _.includes([1, 2, 3], 1);
8577 * _.includes([1, 2, 3], 1, 2);
8580 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
8583 * _.includes('pebbles', 'eb');
8586 function includes(collection, value, fromIndex, guard) {
8587 collection = isArrayLike(collection) ? collection : values(collection);
8588 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
8590 var length = collection.length;
8591 if (fromIndex < 0) {
8592 fromIndex = nativeMax(length + fromIndex, 0);
8594 return isString(collection)
8595 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
8596 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
8600 * Invokes the method at `path` of each element in `collection`, returning
8601 * an array of the results of each invoked method. Any additional arguments
8602 * are provided to each invoked method. If `methodName` is a function, it's
8603 * invoked for and `this` bound to, each element in `collection`.
8608 * @category Collection
8609 * @param {Array|Object} collection The collection to iterate over.
8610 * @param {Array|Function|string} path The path of the method to invoke or
8611 * the function invoked per iteration.
8612 * @param {...*} [args] The arguments to invoke each method with.
8613 * @returns {Array} Returns the array of results.
8616 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
8617 * // => [[1, 5, 7], [1, 2, 3]]
8619 * _.invokeMap([123, 456], String.prototype.split, '');
8620 * // => [['1', '2', '3'], ['4', '5', '6']]
8622 var invokeMap = rest(function(collection, path, args) {
8624 isFunc = typeof path == 'function',
8625 isProp = isKey(path),
8626 result = isArrayLike(collection) ? Array(collection.length) : [];
8628 baseEach(collection, function(value) {
8629 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
8630 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
8636 * Creates an object composed of keys generated from the results of running
8637 * each element of `collection` thru `iteratee`. The corresponding value of
8638 * each key is the last element responsible for generating the key. The
8639 * iteratee is invoked with one argument: (value).
8644 * @category Collection
8645 * @param {Array|Object} collection The collection to iterate over.
8646 * @param {Array|Function|Object|string} [iteratee=_.identity]
8647 * The iteratee to transform keys.
8648 * @returns {Object} Returns the composed aggregate object.
8652 * { 'dir': 'left', 'code': 97 },
8653 * { 'dir': 'right', 'code': 100 }
8656 * _.keyBy(array, function(o) {
8657 * return String.fromCharCode(o.code);
8659 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
8661 * _.keyBy(array, 'dir');
8662 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
8664 var keyBy = createAggregator(function(result, value, key) {
8665 result[key] = value;
8669 * Creates an array of values by running each element in `collection` thru
8670 * `iteratee`. The iteratee is invoked with three arguments:
8671 * (value, index|key, collection).
8673 * Many lodash methods are guarded to work as iteratees for methods like
8674 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
8676 * The guarded methods are:
8677 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
8678 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
8679 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
8680 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
8685 * @category Collection
8686 * @param {Array|Object} collection The collection to iterate over.
8687 * @param {Array|Function|Object|string} [iteratee=_.identity]
8688 * The function invoked per iteration.
8689 * @returns {Array} Returns the new mapped array.
8692 * function square(n) {
8696 * _.map([4, 8], square);
8699 * _.map({ 'a': 4, 'b': 8 }, square);
8700 * // => [16, 64] (iteration order is not guaranteed)
8703 * { 'user': 'barney' },
8704 * { 'user': 'fred' }
8707 * // The `_.property` iteratee shorthand.
8708 * _.map(users, 'user');
8709 * // => ['barney', 'fred']
8711 function map(collection, iteratee) {
8712 var func = isArray(collection) ? arrayMap : baseMap;
8713 return func(collection, getIteratee(iteratee, 3));
8717 * This method is like `_.sortBy` except that it allows specifying the sort
8718 * orders of the iteratees to sort by. If `orders` is unspecified, all values
8719 * are sorted in ascending order. Otherwise, specify an order of "desc" for
8720 * descending or "asc" for ascending sort order of corresponding values.
8725 * @category Collection
8726 * @param {Array|Object} collection The collection to iterate over.
8727 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
8728 * The iteratees to sort by.
8729 * @param {string[]} [orders] The sort orders of `iteratees`.
8730 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
8731 * @returns {Array} Returns the new sorted array.
8735 * { 'user': 'fred', 'age': 48 },
8736 * { 'user': 'barney', 'age': 34 },
8737 * { 'user': 'fred', 'age': 40 },
8738 * { 'user': 'barney', 'age': 36 }
8741 * // Sort by `user` in ascending order and by `age` in descending order.
8742 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
8743 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
8745 function orderBy(collection, iteratees, orders, guard) {
8746 if (collection == null) {
8749 if (!isArray(iteratees)) {
8750 iteratees = iteratees == null ? [] : [iteratees];
8752 orders = guard ? undefined : orders;
8753 if (!isArray(orders)) {
8754 orders = orders == null ? [] : [orders];
8756 return baseOrderBy(collection, iteratees, orders);
8760 * Creates an array of elements split into two groups, the first of which
8761 * contains elements `predicate` returns truthy for, the second of which
8762 * contains elements `predicate` returns falsey for. The predicate is
8763 * invoked with one argument: (value).
8768 * @category Collection
8769 * @param {Array|Object} collection The collection to iterate over.
8770 * @param {Array|Function|Object|string} [predicate=_.identity]
8771 * The function invoked per iteration.
8772 * @returns {Array} Returns the array of grouped elements.
8776 * { 'user': 'barney', 'age': 36, 'active': false },
8777 * { 'user': 'fred', 'age': 40, 'active': true },
8778 * { 'user': 'pebbles', 'age': 1, 'active': false }
8781 * _.partition(users, function(o) { return o.active; });
8782 * // => objects for [['fred'], ['barney', 'pebbles']]
8784 * // The `_.matches` iteratee shorthand.
8785 * _.partition(users, { 'age': 1, 'active': false });
8786 * // => objects for [['pebbles'], ['barney', 'fred']]
8788 * // The `_.matchesProperty` iteratee shorthand.
8789 * _.partition(users, ['active', false]);
8790 * // => objects for [['barney', 'pebbles'], ['fred']]
8792 * // The `_.property` iteratee shorthand.
8793 * _.partition(users, 'active');
8794 * // => objects for [['fred'], ['barney', 'pebbles']]
8796 var partition = createAggregator(function(result, value, key) {
8797 result[key ? 0 : 1].push(value);
8798 }, function() { return [[], []]; });
8801 * Reduces `collection` to a value which is the accumulated result of running
8802 * each element in `collection` thru `iteratee`, where each successive
8803 * invocation is supplied the return value of the previous. If `accumulator`
8804 * is not given, the first element of `collection` is used as the initial
8805 * value. The iteratee is invoked with four arguments:
8806 * (accumulator, value, index|key, collection).
8808 * Many lodash methods are guarded to work as iteratees for methods like
8809 * `_.reduce`, `_.reduceRight`, and `_.transform`.
8811 * The guarded methods are:
8812 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
8818 * @category Collection
8819 * @param {Array|Object} collection The collection to iterate over.
8820 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8821 * @param {*} [accumulator] The initial value.
8822 * @returns {*} Returns the accumulated value.
8823 * @see _.reduceRight
8826 * _.reduce([1, 2], function(sum, n) {
8831 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
8832 * (result[value] || (result[value] = [])).push(key);
8835 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
8837 function reduce(collection, iteratee, accumulator) {
8838 var func = isArray(collection) ? arrayReduce : baseReduce,
8839 initAccum = arguments.length < 3;
8841 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
8845 * This method is like `_.reduce` except that it iterates over elements of
8846 * `collection` from right to left.
8851 * @category Collection
8852 * @param {Array|Object} collection The collection to iterate over.
8853 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
8854 * @param {*} [accumulator] The initial value.
8855 * @returns {*} Returns the accumulated value.
8859 * var array = [[0, 1], [2, 3], [4, 5]];
8861 * _.reduceRight(array, function(flattened, other) {
8862 * return flattened.concat(other);
8864 * // => [4, 5, 2, 3, 0, 1]
8866 function reduceRight(collection, iteratee, accumulator) {
8867 var func = isArray(collection) ? arrayReduceRight : baseReduce,
8868 initAccum = arguments.length < 3;
8870 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
8874 * The opposite of `_.filter`; this method returns the elements of `collection`
8875 * that `predicate` does **not** return truthy for.
8880 * @category Collection
8881 * @param {Array|Object} collection The collection to iterate over.
8882 * @param {Array|Function|Object|string} [predicate=_.identity]
8883 * The function invoked per iteration.
8884 * @returns {Array} Returns the new filtered array.
8889 * { 'user': 'barney', 'age': 36, 'active': false },
8890 * { 'user': 'fred', 'age': 40, 'active': true }
8893 * _.reject(users, function(o) { return !o.active; });
8894 * // => objects for ['fred']
8896 * // The `_.matches` iteratee shorthand.
8897 * _.reject(users, { 'age': 40, 'active': true });
8898 * // => objects for ['barney']
8900 * // The `_.matchesProperty` iteratee shorthand.
8901 * _.reject(users, ['active', false]);
8902 * // => objects for ['fred']
8904 * // The `_.property` iteratee shorthand.
8905 * _.reject(users, 'active');
8906 * // => objects for ['barney']
8908 function reject(collection, predicate) {
8909 var func = isArray(collection) ? arrayFilter : baseFilter;
8910 predicate = getIteratee(predicate, 3);
8911 return func(collection, function(value, index, collection) {
8912 return !predicate(value, index, collection);
8917 * Gets a random element from `collection`.
8922 * @category Collection
8923 * @param {Array|Object} collection The collection to sample.
8924 * @returns {*} Returns the random element.
8927 * _.sample([1, 2, 3, 4]);
8930 function sample(collection) {
8931 var array = isArrayLike(collection) ? collection : values(collection),
8932 length = array.length;
8934 return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
8938 * Gets `n` random elements at unique keys from `collection` up to the
8939 * size of `collection`.
8944 * @category Collection
8945 * @param {Array|Object} collection The collection to sample.
8946 * @param {number} [n=1] The number of elements to sample.
8947 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8948 * @returns {Array} Returns the random elements.
8951 * _.sampleSize([1, 2, 3], 2);
8954 * _.sampleSize([1, 2, 3], 4);
8957 function sampleSize(collection, n, guard) {
8959 result = toArray(collection),
8960 length = result.length,
8961 lastIndex = length - 1;
8963 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
8966 n = baseClamp(toInteger(n), 0, length);
8968 while (++index < n) {
8969 var rand = baseRandom(index, lastIndex),
8970 value = result[rand];
8972 result[rand] = result[index];
8973 result[index] = value;
8980 * Creates an array of shuffled values, using a version of the
8981 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
8986 * @category Collection
8987 * @param {Array|Object} collection The collection to shuffle.
8988 * @returns {Array} Returns the new shuffled array.
8991 * _.shuffle([1, 2, 3, 4]);
8992 * // => [4, 1, 3, 2]
8994 function shuffle(collection) {
8995 return sampleSize(collection, MAX_ARRAY_LENGTH);
8999 * Gets the size of `collection` by returning its length for array-like
9000 * values or the number of own enumerable string keyed properties for objects.
9005 * @category Collection
9006 * @param {Array|Object} collection The collection to inspect.
9007 * @returns {number} Returns the collection size.
9010 * _.size([1, 2, 3]);
9013 * _.size({ 'a': 1, 'b': 2 });
9016 * _.size('pebbles');
9019 function size(collection) {
9020 if (collection == null) {
9023 if (isArrayLike(collection)) {
9024 var result = collection.length;
9025 return (result && isString(collection)) ? stringSize(collection) : result;
9027 if (isObjectLike(collection)) {
9028 var tag = getTag(collection);
9029 if (tag == mapTag || tag == setTag) {
9030 return collection.size;
9033 return keys(collection).length;
9037 * Checks if `predicate` returns truthy for **any** element of `collection`.
9038 * Iteration is stopped once `predicate` returns truthy. The predicate is
9039 * invoked with three arguments: (value, index|key, collection).
9044 * @category Collection
9045 * @param {Array|Object} collection The collection to iterate over.
9046 * @param {Array|Function|Object|string} [predicate=_.identity]
9047 * The function invoked per iteration.
9048 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9049 * @returns {boolean} Returns `true` if any element passes the predicate check,
9053 * _.some([null, 0, 'yes', false], Boolean);
9057 * { 'user': 'barney', 'active': true },
9058 * { 'user': 'fred', 'active': false }
9061 * // The `_.matches` iteratee shorthand.
9062 * _.some(users, { 'user': 'barney', 'active': false });
9065 * // The `_.matchesProperty` iteratee shorthand.
9066 * _.some(users, ['active', false]);
9069 * // The `_.property` iteratee shorthand.
9070 * _.some(users, 'active');
9073 function some(collection, predicate, guard) {
9074 var func = isArray(collection) ? arraySome : baseSome;
9075 if (guard && isIterateeCall(collection, predicate, guard)) {
9076 predicate = undefined;
9078 return func(collection, getIteratee(predicate, 3));
9082 * Creates an array of elements, sorted in ascending order by the results of
9083 * running each element in a collection thru each iteratee. This method
9084 * performs a stable sort, that is, it preserves the original sort order of
9085 * equal elements. The iteratees are invoked with one argument: (value).
9090 * @category Collection
9091 * @param {Array|Object} collection The collection to iterate over.
9092 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
9093 * [iteratees=[_.identity]] The iteratees to sort by.
9094 * @returns {Array} Returns the new sorted array.
9098 * { 'user': 'fred', 'age': 48 },
9099 * { 'user': 'barney', 'age': 36 },
9100 * { 'user': 'fred', 'age': 40 },
9101 * { 'user': 'barney', 'age': 34 }
9104 * _.sortBy(users, function(o) { return o.user; });
9105 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9107 * _.sortBy(users, ['user', 'age']);
9108 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
9110 * _.sortBy(users, 'user', function(o) {
9111 * return Math.floor(o.age / 10);
9113 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9115 var sortBy = rest(function(collection, iteratees) {
9116 if (collection == null) {
9119 var length = iteratees.length;
9120 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
9122 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
9123 iteratees = [iteratees[0]];
9125 iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
9127 : baseFlatten(iteratees, 1, isFlattenableIteratee);
9129 return baseOrderBy(collection, iteratees, []);
9132 /*------------------------------------------------------------------------*/
9135 * Gets the timestamp of the number of milliseconds that have elapsed since
9136 * the Unix epoch (1 January 1970 00:00:00 UTC).
9143 * @returns {number} Returns the timestamp.
9146 * _.defer(function(stamp) {
9147 * console.log(_.now() - stamp);
9149 * // => Logs the number of milliseconds it took for the deferred function to be invoked.
9153 /*------------------------------------------------------------------------*/
9156 * The opposite of `_.before`; this method creates a function that invokes
9157 * `func` once it's called `n` or more times.
9162 * @category Function
9163 * @param {number} n The number of calls before `func` is invoked.
9164 * @param {Function} func The function to restrict.
9165 * @returns {Function} Returns the new restricted function.
9168 * var saves = ['profile', 'settings'];
9170 * var done = _.after(saves.length, function() {
9171 * console.log('done saving!');
9174 * _.forEach(saves, function(type) {
9175 * asyncSave({ 'type': type, 'complete': done });
9177 * // => Logs 'done saving!' after the two async saves have completed.
9179 function after(n, func) {
9180 if (typeof func != 'function') {
9181 throw new TypeError(FUNC_ERROR_TEXT);
9186 return func.apply(this, arguments);
9192 * Creates a function that invokes `func`, with up to `n` arguments,
9193 * ignoring any additional arguments.
9198 * @category Function
9199 * @param {Function} func The function to cap arguments for.
9200 * @param {number} [n=func.length] The arity cap.
9201 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9202 * @returns {Function} Returns the new function.
9205 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
9208 function ary(func, n, guard) {
9209 n = guard ? undefined : n;
9210 n = (func && n == null) ? func.length : n;
9211 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
9215 * Creates a function that invokes `func`, with the `this` binding and arguments
9216 * of the created function, while it's called less than `n` times. Subsequent
9217 * calls to the created function return the result of the last `func` invocation.
9222 * @category Function
9223 * @param {number} n The number of calls at which `func` is no longer invoked.
9224 * @param {Function} func The function to restrict.
9225 * @returns {Function} Returns the new restricted function.
9228 * jQuery(element).on('click', _.before(5, addContactToList));
9229 * // => allows adding up to 4 contacts to the list
9231 function before(n, func) {
9233 if (typeof func != 'function') {
9234 throw new TypeError(FUNC_ERROR_TEXT);
9239 result = func.apply(this, arguments);
9249 * Creates a function that invokes `func` with the `this` binding of `thisArg`
9250 * and `partials` prepended to the arguments it receives.
9252 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
9253 * may be used as a placeholder for partially applied arguments.
9255 * **Note:** Unlike native `Function#bind` this method doesn't set the "length"
9256 * property of bound functions.
9261 * @category Function
9262 * @param {Function} func The function to bind.
9263 * @param {*} thisArg The `this` binding of `func`.
9264 * @param {...*} [partials] The arguments to be partially applied.
9265 * @returns {Function} Returns the new bound function.
9268 * var greet = function(greeting, punctuation) {
9269 * return greeting + ' ' + this.user + punctuation;
9272 * var object = { 'user': 'fred' };
9274 * var bound = _.bind(greet, object, 'hi');
9278 * // Bound with placeholders.
9279 * var bound = _.bind(greet, object, _, '!');
9283 var bind = rest(function(func, thisArg, partials) {
9284 var bitmask = BIND_FLAG;
9285 if (partials.length) {
9286 var holders = replaceHolders(partials, getPlaceholder(bind));
9287 bitmask |= PARTIAL_FLAG;
9289 return createWrapper(func, bitmask, thisArg, partials, holders);
9293 * Creates a function that invokes the method at `object[key]` with `partials`
9294 * prepended to the arguments it receives.
9296 * This method differs from `_.bind` by allowing bound functions to reference
9297 * methods that may be redefined or don't yet exist. See
9298 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
9301 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
9302 * builds, may be used as a placeholder for partially applied arguments.
9307 * @category Function
9308 * @param {Object} object The object to invoke the method on.
9309 * @param {string} key The key of the method.
9310 * @param {...*} [partials] The arguments to be partially applied.
9311 * @returns {Function} Returns the new bound function.
9316 * 'greet': function(greeting, punctuation) {
9317 * return greeting + ' ' + this.user + punctuation;
9321 * var bound = _.bindKey(object, 'greet', 'hi');
9325 * object.greet = function(greeting, punctuation) {
9326 * return greeting + 'ya ' + this.user + punctuation;
9330 * // => 'hiya fred!'
9332 * // Bound with placeholders.
9333 * var bound = _.bindKey(object, 'greet', _, '!');
9335 * // => 'hiya fred!'
9337 var bindKey = rest(function(object, key, partials) {
9338 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
9339 if (partials.length) {
9340 var holders = replaceHolders(partials, getPlaceholder(bindKey));
9341 bitmask |= PARTIAL_FLAG;
9343 return createWrapper(key, bitmask, object, partials, holders);
9347 * Creates a function that accepts arguments of `func` and either invokes
9348 * `func` returning its result, if at least `arity` number of arguments have
9349 * been provided, or returns a function that accepts the remaining `func`
9350 * arguments, and so on. The arity of `func` may be specified if `func.length`
9351 * is not sufficient.
9353 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
9354 * may be used as a placeholder for provided arguments.
9356 * **Note:** This method doesn't set the "length" property of curried functions.
9361 * @category Function
9362 * @param {Function} func The function to curry.
9363 * @param {number} [arity=func.length] The arity of `func`.
9364 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9365 * @returns {Function} Returns the new curried function.
9368 * var abc = function(a, b, c) {
9372 * var curried = _.curry(abc);
9383 * // Curried with placeholders.
9384 * curried(1)(_, 3)(2);
9387 function curry(func, arity, guard) {
9388 arity = guard ? undefined : arity;
9389 var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
9390 result.placeholder = curry.placeholder;
9395 * This method is like `_.curry` except that arguments are applied to `func`
9396 * in the manner of `_.partialRight` instead of `_.partial`.
9398 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
9399 * builds, may be used as a placeholder for provided arguments.
9401 * **Note:** This method doesn't set the "length" property of curried functions.
9406 * @category Function
9407 * @param {Function} func The function to curry.
9408 * @param {number} [arity=func.length] The arity of `func`.
9409 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9410 * @returns {Function} Returns the new curried function.
9413 * var abc = function(a, b, c) {
9417 * var curried = _.curryRight(abc);
9428 * // Curried with placeholders.
9429 * curried(3)(1, _)(2);
9432 function curryRight(func, arity, guard) {
9433 arity = guard ? undefined : arity;
9434 var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
9435 result.placeholder = curryRight.placeholder;
9440 * Creates a debounced function that delays invoking `func` until after `wait`
9441 * milliseconds have elapsed since the last time the debounced function was
9442 * invoked. The debounced function comes with a `cancel` method to cancel
9443 * delayed `func` invocations and a `flush` method to immediately invoke them.
9444 * Provide an options object to indicate whether `func` should be invoked on
9445 * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
9446 * with the last arguments provided to the debounced function. Subsequent calls
9447 * to the debounced function return the result of the last `func` invocation.
9449 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
9450 * on the trailing edge of the timeout only if the debounced function is
9451 * invoked more than once during the `wait` timeout.
9453 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
9454 * for details over the differences between `_.debounce` and `_.throttle`.
9459 * @category Function
9460 * @param {Function} func The function to debounce.
9461 * @param {number} [wait=0] The number of milliseconds to delay.
9462 * @param {Object} [options={}] The options object.
9463 * @param {boolean} [options.leading=false]
9464 * Specify invoking on the leading edge of the timeout.
9465 * @param {number} [options.maxWait]
9466 * The maximum time `func` is allowed to be delayed before it's invoked.
9467 * @param {boolean} [options.trailing=true]
9468 * Specify invoking on the trailing edge of the timeout.
9469 * @returns {Function} Returns the new debounced function.
9472 * // Avoid costly calculations while the window size is in flux.
9473 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
9475 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
9476 * jQuery(element).on('click', _.debounce(sendMail, 300, {
9481 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
9482 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
9483 * var source = new EventSource('/stream');
9484 * jQuery(source).on('message', debounced);
9486 * // Cancel the trailing debounced invocation.
9487 * jQuery(window).on('popstate', debounced.cancel);
9489 function debounce(func, wait, options) {
9501 if (typeof func != 'function') {
9502 throw new TypeError(FUNC_ERROR_TEXT);
9504 wait = toNumber(wait) || 0;
9505 if (isObject(options)) {
9506 leading = !!options.leading;
9507 maxing = 'maxWait' in options;
9508 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
9509 trailing = 'trailing' in options ? !!options.trailing : trailing;
9512 function invokeFunc(time) {
9513 var args = lastArgs,
9516 lastArgs = lastThis = undefined;
9517 lastInvokeTime = time;
9518 result = func.apply(thisArg, args);
9522 function leadingEdge(time) {
9523 // Reset any `maxWait` timer.
9524 lastInvokeTime = time;
9525 // Start the timer for the trailing edge.
9526 timerId = setTimeout(timerExpired, wait);
9527 // Invoke the leading edge.
9528 return leading ? invokeFunc(time) : result;
9531 function remainingWait(time) {
9532 var timeSinceLastCall = time - lastCallTime,
9533 timeSinceLastInvoke = time - lastInvokeTime,
9534 result = wait - timeSinceLastCall;
9536 return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
9539 function shouldInvoke(time) {
9540 var timeSinceLastCall = time - lastCallTime,
9541 timeSinceLastInvoke = time - lastInvokeTime;
9543 // Either this is the first call, activity has stopped and we're at the
9544 // trailing edge, the system time has gone backwards and we're treating
9545 // it as the trailing edge, or we've hit the `maxWait` limit.
9546 return (!lastCallTime || (timeSinceLastCall >= wait) ||
9547 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
9550 function timerExpired() {
9552 if (shouldInvoke(time)) {
9553 return trailingEdge(time);
9555 // Restart the timer.
9556 timerId = setTimeout(timerExpired, remainingWait(time));
9559 function trailingEdge(time) {
9560 clearTimeout(timerId);
9561 timerId = undefined;
9563 // Only invoke if we have `lastArgs` which means `func` has been
9564 // debounced at least once.
9565 if (trailing && lastArgs) {
9566 return invokeFunc(time);
9568 lastArgs = lastThis = undefined;
9573 if (timerId !== undefined) {
9574 clearTimeout(timerId);
9576 lastCallTime = lastInvokeTime = 0;
9577 lastArgs = lastThis = timerId = undefined;
9581 return timerId === undefined ? result : trailingEdge(now());
9584 function debounced() {
9586 isInvoking = shouldInvoke(time);
9588 lastArgs = arguments;
9590 lastCallTime = time;
9593 if (timerId === undefined) {
9594 return leadingEdge(lastCallTime);
9597 // Handle invocations in a tight loop.
9598 clearTimeout(timerId);
9599 timerId = setTimeout(timerExpired, wait);
9600 return invokeFunc(lastCallTime);
9603 if (timerId === undefined) {
9604 timerId = setTimeout(timerExpired, wait);
9608 debounced.cancel = cancel;
9609 debounced.flush = flush;
9614 * Defers invoking the `func` until the current call stack has cleared. Any
9615 * additional arguments are provided to `func` when it's invoked.
9620 * @category Function
9621 * @param {Function} func The function to defer.
9622 * @param {...*} [args] The arguments to invoke `func` with.
9623 * @returns {number} Returns the timer id.
9626 * _.defer(function(text) {
9627 * console.log(text);
9629 * // => Logs 'deferred' after one or more milliseconds.
9631 var defer = rest(function(func, args) {
9632 return baseDelay(func, 1, args);
9636 * Invokes `func` after `wait` milliseconds. Any additional arguments are
9637 * provided to `func` when it's invoked.
9642 * @category Function
9643 * @param {Function} func The function to delay.
9644 * @param {number} wait The number of milliseconds to delay invocation.
9645 * @param {...*} [args] The arguments to invoke `func` with.
9646 * @returns {number} Returns the timer id.
9649 * _.delay(function(text) {
9650 * console.log(text);
9651 * }, 1000, 'later');
9652 * // => Logs 'later' after one second.
9654 var delay = rest(function(func, wait, args) {
9655 return baseDelay(func, toNumber(wait) || 0, args);
9659 * Creates a function that invokes `func` with arguments reversed.
9664 * @category Function
9665 * @param {Function} func The function to flip arguments for.
9666 * @returns {Function} Returns the new function.
9669 * var flipped = _.flip(function() {
9670 * return _.toArray(arguments);
9673 * flipped('a', 'b', 'c', 'd');
9674 * // => ['d', 'c', 'b', 'a']
9676 function flip(func) {
9677 return createWrapper(func, FLIP_FLAG);
9681 * Creates a function that memoizes the result of `func`. If `resolver` is
9682 * provided, it determines the cache key for storing the result based on the
9683 * arguments provided to the memoized function. By default, the first argument
9684 * provided to the memoized function is used as the map cache key. The `func`
9685 * is invoked with the `this` binding of the memoized function.
9687 * **Note:** The cache is exposed as the `cache` property on the memoized
9688 * function. Its creation may be customized by replacing the `_.memoize.Cache`
9689 * constructor with one whose instances implement the
9690 * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
9691 * method interface of `delete`, `get`, `has`, and `set`.
9696 * @category Function
9697 * @param {Function} func The function to have its output memoized.
9698 * @param {Function} [resolver] The function to resolve the cache key.
9699 * @returns {Function} Returns the new memoizing function.
9702 * var object = { 'a': 1, 'b': 2 };
9703 * var other = { 'c': 3, 'd': 4 };
9705 * var values = _.memoize(_.values);
9716 * // Modify the result cache.
9717 * values.cache.set(object, ['a', 'b']);
9721 * // Replace `_.memoize.Cache`.
9722 * _.memoize.Cache = WeakMap;
9724 function memoize(func, resolver) {
9725 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
9726 throw new TypeError(FUNC_ERROR_TEXT);
9728 var memoized = function() {
9729 var args = arguments,
9730 key = resolver ? resolver.apply(this, args) : args[0],
9731 cache = memoized.cache;
9733 if (cache.has(key)) {
9734 return cache.get(key);
9736 var result = func.apply(this, args);
9737 memoized.cache = cache.set(key, result);
9740 memoized.cache = new (memoize.Cache || MapCache);
9744 // Assign cache to `_.memoize`.
9745 memoize.Cache = MapCache;
9748 * Creates a function that negates the result of the predicate `func`. The
9749 * `func` predicate is invoked with the `this` binding and arguments of the
9755 * @category Function
9756 * @param {Function} predicate The predicate to negate.
9757 * @returns {Function} Returns the new function.
9760 * function isEven(n) {
9761 * return n % 2 == 0;
9764 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
9767 function negate(predicate) {
9768 if (typeof predicate != 'function') {
9769 throw new TypeError(FUNC_ERROR_TEXT);
9772 return !predicate.apply(this, arguments);
9777 * Creates a function that is restricted to invoking `func` once. Repeat calls
9778 * to the function return the value of the first invocation. The `func` is
9779 * invoked with the `this` binding and arguments of the created function.
9784 * @category Function
9785 * @param {Function} func The function to restrict.
9786 * @returns {Function} Returns the new restricted function.
9789 * var initialize = _.once(createApplication);
9792 * // `initialize` invokes `createApplication` once
9794 function once(func) {
9795 return before(2, func);
9799 * Creates a function that invokes `func` with arguments transformed by
9800 * corresponding `transforms`.
9805 * @category Function
9806 * @param {Function} func The function to wrap.
9807 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
9808 * [transforms[_.identity]] The functions to transform.
9809 * @returns {Function} Returns the new function.
9812 * function doubled(n) {
9816 * function square(n) {
9820 * var func = _.overArgs(function(x, y) {
9822 * }, square, doubled);
9830 var overArgs = rest(function(func, transforms) {
9831 transforms = (transforms.length == 1 && isArray(transforms[0]))
9832 ? arrayMap(transforms[0], baseUnary(getIteratee()))
9833 : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(getIteratee()));
9835 var funcsLength = transforms.length;
9836 return rest(function(args) {
9838 length = nativeMin(args.length, funcsLength);
9840 while (++index < length) {
9841 args[index] = transforms[index].call(this, args[index]);
9843 return apply(func, this, args);
9848 * Creates a function that invokes `func` with `partials` prepended to the
9849 * arguments it receives. This method is like `_.bind` except it does **not**
9850 * alter the `this` binding.
9852 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
9853 * builds, may be used as a placeholder for partially applied arguments.
9855 * **Note:** This method doesn't set the "length" property of partially
9856 * applied functions.
9861 * @category Function
9862 * @param {Function} func The function to partially apply arguments to.
9863 * @param {...*} [partials] The arguments to be partially applied.
9864 * @returns {Function} Returns the new partially applied function.
9867 * var greet = function(greeting, name) {
9868 * return greeting + ' ' + name;
9871 * var sayHelloTo = _.partial(greet, 'hello');
9872 * sayHelloTo('fred');
9873 * // => 'hello fred'
9875 * // Partially applied with placeholders.
9876 * var greetFred = _.partial(greet, _, 'fred');
9880 var partial = rest(function(func, partials) {
9881 var holders = replaceHolders(partials, getPlaceholder(partial));
9882 return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
9886 * This method is like `_.partial` except that partially applied arguments
9887 * are appended to the arguments it receives.
9889 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
9890 * builds, may be used as a placeholder for partially applied arguments.
9892 * **Note:** This method doesn't set the "length" property of partially
9893 * applied functions.
9898 * @category Function
9899 * @param {Function} func The function to partially apply arguments to.
9900 * @param {...*} [partials] The arguments to be partially applied.
9901 * @returns {Function} Returns the new partially applied function.
9904 * var greet = function(greeting, name) {
9905 * return greeting + ' ' + name;
9908 * var greetFred = _.partialRight(greet, 'fred');
9912 * // Partially applied with placeholders.
9913 * var sayHelloTo = _.partialRight(greet, 'hello', _);
9914 * sayHelloTo('fred');
9915 * // => 'hello fred'
9917 var partialRight = rest(function(func, partials) {
9918 var holders = replaceHolders(partials, getPlaceholder(partialRight));
9919 return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
9923 * Creates a function that invokes `func` with arguments arranged according
9924 * to the specified `indexes` where the argument value at the first index is
9925 * provided as the first argument, the argument value at the second index is
9926 * provided as the second argument, and so on.
9931 * @category Function
9932 * @param {Function} func The function to rearrange arguments for.
9933 * @param {...(number|number[])} indexes The arranged argument indexes.
9934 * @returns {Function} Returns the new function.
9937 * var rearged = _.rearg(function(a, b, c) {
9941 * rearged('b', 'c', 'a')
9942 * // => ['a', 'b', 'c']
9944 var rearg = rest(function(func, indexes) {
9945 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
9949 * Creates a function that invokes `func` with the `this` binding of the
9950 * created function and arguments from `start` and beyond provided as
9953 * **Note:** This method is based on the
9954 * [rest parameter](https://mdn.io/rest_parameters).
9959 * @category Function
9960 * @param {Function} func The function to apply a rest parameter to.
9961 * @param {number} [start=func.length-1] The start position of the rest parameter.
9962 * @returns {Function} Returns the new function.
9965 * var say = _.rest(function(what, names) {
9966 * return what + ' ' + _.initial(names).join(', ') +
9967 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
9970 * say('hello', 'fred', 'barney', 'pebbles');
9971 * // => 'hello fred, barney, & pebbles'
9973 function rest(func, start) {
9974 if (typeof func != 'function') {
9975 throw new TypeError(FUNC_ERROR_TEXT);
9977 start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
9979 var args = arguments,
9981 length = nativeMax(args.length - start, 0),
9982 array = Array(length);
9984 while (++index < length) {
9985 array[index] = args[start + index];
9988 case 0: return func.call(this, array);
9989 case 1: return func.call(this, args[0], array);
9990 case 2: return func.call(this, args[0], args[1], array);
9992 var otherArgs = Array(start + 1);
9994 while (++index < start) {
9995 otherArgs[index] = args[index];
9997 otherArgs[start] = array;
9998 return apply(func, this, otherArgs);
10003 * Creates a function that invokes `func` with the `this` binding of the
10004 * create function and an array of arguments much like
10005 * [`Function#apply`](http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.apply).
10007 * **Note:** This method is based on the
10008 * [spread operator](https://mdn.io/spread_operator).
10013 * @category Function
10014 * @param {Function} func The function to spread arguments over.
10015 * @param {number} [start=0] The start position of the spread.
10016 * @returns {Function} Returns the new function.
10019 * var say = _.spread(function(who, what) {
10020 * return who + ' says ' + what;
10023 * say(['fred', 'hello']);
10024 * // => 'fred says hello'
10026 * var numbers = Promise.all([
10027 * Promise.resolve(40),
10028 * Promise.resolve(36)
10031 * numbers.then(_.spread(function(x, y) {
10034 * // => a Promise of 76
10036 function spread(func, start) {
10037 if (typeof func != 'function') {
10038 throw new TypeError(FUNC_ERROR_TEXT);
10040 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
10041 return rest(function(args) {
10042 var array = args[start],
10043 otherArgs = castSlice(args, 0, start);
10046 arrayPush(otherArgs, array);
10048 return apply(func, this, otherArgs);
10053 * Creates a throttled function that only invokes `func` at most once per
10054 * every `wait` milliseconds. The throttled function comes with a `cancel`
10055 * method to cancel delayed `func` invocations and a `flush` method to
10056 * immediately invoke them. Provide an options object to indicate whether
10057 * `func` should be invoked on the leading and/or trailing edge of the `wait`
10058 * timeout. The `func` is invoked with the last arguments provided to the
10059 * throttled function. Subsequent calls to the throttled function return the
10060 * result of the last `func` invocation.
10062 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10063 * invoked on the trailing edge of the timeout only if the throttled function
10064 * is invoked more than once during the `wait` timeout.
10066 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10067 * for details over the differences between `_.throttle` and `_.debounce`.
10072 * @category Function
10073 * @param {Function} func The function to throttle.
10074 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10075 * @param {Object} [options={}] The options object.
10076 * @param {boolean} [options.leading=true]
10077 * Specify invoking on the leading edge of the timeout.
10078 * @param {boolean} [options.trailing=true]
10079 * Specify invoking on the trailing edge of the timeout.
10080 * @returns {Function} Returns the new throttled function.
10083 * // Avoid excessively updating the position while scrolling.
10084 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10086 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10087 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10088 * jQuery(element).on('click', throttled);
10090 * // Cancel the trailing throttled invocation.
10091 * jQuery(window).on('popstate', throttled.cancel);
10093 function throttle(func, wait, options) {
10094 var leading = true,
10097 if (typeof func != 'function') {
10098 throw new TypeError(FUNC_ERROR_TEXT);
10100 if (isObject(options)) {
10101 leading = 'leading' in options ? !!options.leading : leading;
10102 trailing = 'trailing' in options ? !!options.trailing : trailing;
10104 return debounce(func, wait, {
10105 'leading': leading,
10107 'trailing': trailing
10112 * Creates a function that accepts up to one argument, ignoring any
10113 * additional arguments.
10118 * @category Function
10119 * @param {Function} func The function to cap arguments for.
10120 * @returns {Function} Returns the new function.
10123 * _.map(['6', '8', '10'], _.unary(parseInt));
10126 function unary(func) {
10127 return ary(func, 1);
10131 * Creates a function that provides `value` to the wrapper function as its
10132 * first argument. Any additional arguments provided to the function are
10133 * appended to those provided to the wrapper function. The wrapper is invoked
10134 * with the `this` binding of the created function.
10139 * @category Function
10140 * @param {*} value The value to wrap.
10141 * @param {Function} [wrapper=identity] The wrapper function.
10142 * @returns {Function} Returns the new function.
10145 * var p = _.wrap(_.escape, function(func, text) {
10146 * return '<p>' + func(text) + '</p>';
10149 * p('fred, barney, & pebbles');
10150 * // => '<p>fred, barney, & pebbles</p>'
10152 function wrap(value, wrapper) {
10153 wrapper = wrapper == null ? identity : wrapper;
10154 return partial(wrapper, value);
10157 /*------------------------------------------------------------------------*/
10160 * Casts `value` as an array if it's not one.
10166 * @param {*} value The value to inspect.
10167 * @returns {Array} Returns the cast array.
10173 * _.castArray({ 'a': 1 });
10174 * // => [{ 'a': 1 }]
10176 * _.castArray('abc');
10179 * _.castArray(null);
10182 * _.castArray(undefined);
10183 * // => [undefined]
10188 * var array = [1, 2, 3];
10189 * console.log(_.castArray(array) === array);
10192 function castArray() {
10193 if (!arguments.length) {
10196 var value = arguments[0];
10197 return isArray(value) ? value : [value];
10201 * Creates a shallow clone of `value`.
10203 * **Note:** This method is loosely based on the
10204 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
10205 * and supports cloning arrays, array buffers, booleans, date objects, maps,
10206 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
10207 * arrays. The own enumerable properties of `arguments` objects are cloned
10208 * as plain objects. An empty object is returned for uncloneable values such
10209 * as error objects, functions, DOM nodes, and WeakMaps.
10215 * @param {*} value The value to clone.
10216 * @returns {*} Returns the cloned value.
10220 * var objects = [{ 'a': 1 }, { 'b': 2 }];
10222 * var shallow = _.clone(objects);
10223 * console.log(shallow[0] === objects[0]);
10226 function clone(value) {
10227 return baseClone(value, false, true);
10231 * This method is like `_.clone` except that it accepts `customizer` which
10232 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
10233 * cloning is handled by the method instead. The `customizer` is invoked with
10234 * up to four arguments; (value [, index|key, object, stack]).
10240 * @param {*} value The value to clone.
10241 * @param {Function} [customizer] The function to customize cloning.
10242 * @returns {*} Returns the cloned value.
10243 * @see _.cloneDeepWith
10246 * function customizer(value) {
10247 * if (_.isElement(value)) {
10248 * return value.cloneNode(false);
10252 * var el = _.cloneWith(document.body, customizer);
10254 * console.log(el === document.body);
10256 * console.log(el.nodeName);
10258 * console.log(el.childNodes.length);
10261 function cloneWith(value, customizer) {
10262 return baseClone(value, false, true, customizer);
10266 * This method is like `_.clone` except that it recursively clones `value`.
10272 * @param {*} value The value to recursively clone.
10273 * @returns {*} Returns the deep cloned value.
10277 * var objects = [{ 'a': 1 }, { 'b': 2 }];
10279 * var deep = _.cloneDeep(objects);
10280 * console.log(deep[0] === objects[0]);
10283 function cloneDeep(value) {
10284 return baseClone(value, true, true);
10288 * This method is like `_.cloneWith` except that it recursively clones `value`.
10294 * @param {*} value The value to recursively clone.
10295 * @param {Function} [customizer] The function to customize cloning.
10296 * @returns {*} Returns the deep cloned value.
10300 * function customizer(value) {
10301 * if (_.isElement(value)) {
10302 * return value.cloneNode(true);
10306 * var el = _.cloneDeepWith(document.body, customizer);
10308 * console.log(el === document.body);
10310 * console.log(el.nodeName);
10312 * console.log(el.childNodes.length);
10315 function cloneDeepWith(value, customizer) {
10316 return baseClone(value, true, true, customizer);
10321 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
10322 * comparison between two values to determine if they are equivalent.
10328 * @param {*} value The value to compare.
10329 * @param {*} other The other value to compare.
10330 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
10333 * var object = { 'user': 'fred' };
10334 * var other = { 'user': 'fred' };
10336 * _.eq(object, object);
10339 * _.eq(object, other);
10345 * _.eq('a', Object('a'));
10351 function eq(value, other) {
10352 return value === other || (value !== value && other !== other);
10356 * Checks if `value` is greater than `other`.
10362 * @param {*} value The value to compare.
10363 * @param {*} other The other value to compare.
10364 * @returns {boolean} Returns `true` if `value` is greater than `other`,
10378 var gt = createRelationalOperation(baseGt);
10381 * Checks if `value` is greater than or equal to `other`.
10387 * @param {*} value The value to compare.
10388 * @param {*} other The other value to compare.
10389 * @returns {boolean} Returns `true` if `value` is greater than or equal to
10390 * `other`, else `false`.
10403 var gte = createRelationalOperation(function(value, other) {
10404 return value >= other;
10408 * Checks if `value` is likely an `arguments` object.
10414 * @param {*} value The value to check.
10415 * @returns {boolean} Returns `true` if `value` is correctly classified,
10419 * _.isArguments(function() { return arguments; }());
10422 * _.isArguments([1, 2, 3]);
10425 function isArguments(value) {
10426 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
10427 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
10428 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
10432 * Checks if `value` is classified as an `Array` object.
10439 * @param {*} value The value to check.
10440 * @returns {boolean} Returns `true` if `value` is correctly classified,
10444 * _.isArray([1, 2, 3]);
10447 * _.isArray(document.body.children);
10450 * _.isArray('abc');
10453 * _.isArray(_.noop);
10456 var isArray = Array.isArray;
10459 * Checks if `value` is classified as an `ArrayBuffer` object.
10465 * @param {*} value The value to check.
10466 * @returns {boolean} Returns `true` if `value` is correctly classified,
10470 * _.isArrayBuffer(new ArrayBuffer(2));
10473 * _.isArrayBuffer(new Array(2));
10476 function isArrayBuffer(value) {
10477 return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
10481 * Checks if `value` is array-like. A value is considered array-like if it's
10482 * not a function and has a `value.length` that's an integer greater than or
10483 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
10489 * @param {*} value The value to check.
10490 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
10493 * _.isArrayLike([1, 2, 3]);
10496 * _.isArrayLike(document.body.children);
10499 * _.isArrayLike('abc');
10502 * _.isArrayLike(_.noop);
10505 function isArrayLike(value) {
10506 return value != null && isLength(getLength(value)) && !isFunction(value);
10510 * This method is like `_.isArrayLike` except that it also checks if `value`
10517 * @param {*} value The value to check.
10518 * @returns {boolean} Returns `true` if `value` is an array-like object,
10522 * _.isArrayLikeObject([1, 2, 3]);
10525 * _.isArrayLikeObject(document.body.children);
10528 * _.isArrayLikeObject('abc');
10531 * _.isArrayLikeObject(_.noop);
10534 function isArrayLikeObject(value) {
10535 return isObjectLike(value) && isArrayLike(value);
10539 * Checks if `value` is classified as a boolean primitive or object.
10545 * @param {*} value The value to check.
10546 * @returns {boolean} Returns `true` if `value` is correctly classified,
10550 * _.isBoolean(false);
10553 * _.isBoolean(null);
10556 function isBoolean(value) {
10557 return value === true || value === false ||
10558 (isObjectLike(value) && objectToString.call(value) == boolTag);
10562 * Checks if `value` is a buffer.
10568 * @param {*} value The value to check.
10569 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
10572 * _.isBuffer(new Buffer(2));
10575 * _.isBuffer(new Uint8Array(2));
10578 var isBuffer = !Buffer ? constant(false) : function(value) {
10579 return value instanceof Buffer;
10583 * Checks if `value` is classified as a `Date` object.
10589 * @param {*} value The value to check.
10590 * @returns {boolean} Returns `true` if `value` is correctly classified,
10594 * _.isDate(new Date);
10597 * _.isDate('Mon April 23 2012');
10600 function isDate(value) {
10601 return isObjectLike(value) && objectToString.call(value) == dateTag;
10605 * Checks if `value` is likely a DOM element.
10611 * @param {*} value The value to check.
10612 * @returns {boolean} Returns `true` if `value` is a DOM element,
10616 * _.isElement(document.body);
10619 * _.isElement('<body>');
10622 function isElement(value) {
10623 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
10627 * Checks if `value` is an empty object, collection, map, or set.
10629 * Objects are considered empty if they have no own enumerable string keyed
10632 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
10633 * jQuery-like collections are considered empty if they have a `length` of `0`.
10634 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
10640 * @param {*} value The value to check.
10641 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
10653 * _.isEmpty([1, 2, 3]);
10656 * _.isEmpty({ 'a': 1 });
10659 function isEmpty(value) {
10660 if (isArrayLike(value) &&
10661 (isArray(value) || isString(value) || isFunction(value.splice) ||
10662 isArguments(value) || isBuffer(value))) {
10663 return !value.length;
10665 if (isObjectLike(value)) {
10666 var tag = getTag(value);
10667 if (tag == mapTag || tag == setTag) {
10668 return !value.size;
10671 for (var key in value) {
10672 if (hasOwnProperty.call(value, key)) {
10676 return !(nonEnumShadows && keys(value).length);
10680 * Performs a deep comparison between two values to determine if they are
10683 * **Note:** This method supports comparing arrays, array buffers, booleans,
10684 * date objects, error objects, maps, numbers, `Object` objects, regexes,
10685 * sets, strings, symbols, and typed arrays. `Object` objects are compared
10686 * by their own, not inherited, enumerable properties. Functions and DOM
10687 * nodes are **not** supported.
10693 * @param {*} value The value to compare.
10694 * @param {*} other The other value to compare.
10695 * @returns {boolean} Returns `true` if the values are equivalent,
10699 * var object = { 'user': 'fred' };
10700 * var other = { 'user': 'fred' };
10702 * _.isEqual(object, other);
10705 * object === other;
10708 function isEqual(value, other) {
10709 return baseIsEqual(value, other);
10713 * This method is like `_.isEqual` except that it accepts `customizer` which
10714 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
10715 * are handled by the method instead. The `customizer` is invoked with up to
10716 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
10722 * @param {*} value The value to compare.
10723 * @param {*} other The other value to compare.
10724 * @param {Function} [customizer] The function to customize comparisons.
10725 * @returns {boolean} Returns `true` if the values are equivalent,
10729 * function isGreeting(value) {
10730 * return /^h(?:i|ello)$/.test(value);
10733 * function customizer(objValue, othValue) {
10734 * if (isGreeting(objValue) && isGreeting(othValue)) {
10739 * var array = ['hello', 'goodbye'];
10740 * var other = ['hi', 'goodbye'];
10742 * _.isEqualWith(array, other, customizer);
10745 function isEqualWith(value, other, customizer) {
10746 customizer = typeof customizer == 'function' ? customizer : undefined;
10747 var result = customizer ? customizer(value, other) : undefined;
10748 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
10752 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
10753 * `SyntaxError`, `TypeError`, or `URIError` object.
10759 * @param {*} value The value to check.
10760 * @returns {boolean} Returns `true` if `value` is an error object,
10764 * _.isError(new Error);
10767 * _.isError(Error);
10770 function isError(value) {
10771 if (!isObjectLike(value)) {
10774 return (objectToString.call(value) == errorTag) ||
10775 (typeof value.message == 'string' && typeof value.name == 'string');
10779 * Checks if `value` is a finite primitive number.
10781 * **Note:** This method is based on
10782 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
10788 * @param {*} value The value to check.
10789 * @returns {boolean} Returns `true` if `value` is a finite number,
10796 * _.isFinite(Number.MAX_VALUE);
10799 * _.isFinite(3.14);
10802 * _.isFinite(Infinity);
10805 function isFinite(value) {
10806 return typeof value == 'number' && nativeIsFinite(value);
10810 * Checks if `value` is classified as a `Function` object.
10816 * @param {*} value The value to check.
10817 * @returns {boolean} Returns `true` if `value` is correctly classified,
10824 * _.isFunction(/abc/);
10827 function isFunction(value) {
10828 // The use of `Object#toString` avoids issues with the `typeof` operator
10829 // in Safari 8 which returns 'object' for typed array and weak map constructors,
10830 // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
10831 var tag = isObject(value) ? objectToString.call(value) : '';
10832 return tag == funcTag || tag == genTag;
10836 * Checks if `value` is an integer.
10838 * **Note:** This method is based on
10839 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
10845 * @param {*} value The value to check.
10846 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
10852 * _.isInteger(Number.MIN_VALUE);
10855 * _.isInteger(Infinity);
10858 * _.isInteger('3');
10861 function isInteger(value) {
10862 return typeof value == 'number' && value == toInteger(value);
10866 * Checks if `value` is a valid array-like length.
10868 * **Note:** This function is loosely based on
10869 * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
10875 * @param {*} value The value to check.
10876 * @returns {boolean} Returns `true` if `value` is a valid length,
10883 * _.isLength(Number.MIN_VALUE);
10886 * _.isLength(Infinity);
10892 function isLength(value) {
10893 return typeof value == 'number' &&
10894 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
10898 * Checks if `value` is the
10899 * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
10900 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
10906 * @param {*} value The value to check.
10907 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
10913 * _.isObject([1, 2, 3]);
10916 * _.isObject(_.noop);
10919 * _.isObject(null);
10922 function isObject(value) {
10923 var type = typeof value;
10924 return !!value && (type == 'object' || type == 'function');
10928 * Checks if `value` is object-like. A value is object-like if it's not `null`
10929 * and has a `typeof` result of "object".
10935 * @param {*} value The value to check.
10936 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
10939 * _.isObjectLike({});
10942 * _.isObjectLike([1, 2, 3]);
10945 * _.isObjectLike(_.noop);
10948 * _.isObjectLike(null);
10951 function isObjectLike(value) {
10952 return !!value && typeof value == 'object';
10956 * Checks if `value` is classified as a `Map` object.
10962 * @param {*} value The value to check.
10963 * @returns {boolean} Returns `true` if `value` is correctly classified,
10967 * _.isMap(new Map);
10970 * _.isMap(new WeakMap);
10973 function isMap(value) {
10974 return isObjectLike(value) && getTag(value) == mapTag;
10978 * Performs a partial deep comparison between `object` and `source` to
10979 * determine if `object` contains equivalent property values. This method is
10980 * equivalent to a `_.matches` function when `source` is partially applied.
10982 * **Note:** This method supports comparing the same values as `_.isEqual`.
10988 * @param {Object} object The object to inspect.
10989 * @param {Object} source The object of property values to match.
10990 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
10993 * var object = { 'user': 'fred', 'age': 40 };
10995 * _.isMatch(object, { 'age': 40 });
10998 * _.isMatch(object, { 'age': 36 });
11001 function isMatch(object, source) {
11002 return object === source || baseIsMatch(object, source, getMatchData(source));
11006 * This method is like `_.isMatch` except that it accepts `customizer` which
11007 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11008 * are handled by the method instead. The `customizer` is invoked with five
11009 * arguments: (objValue, srcValue, index|key, object, source).
11015 * @param {Object} object The object to inspect.
11016 * @param {Object} source The object of property values to match.
11017 * @param {Function} [customizer] The function to customize comparisons.
11018 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11021 * function isGreeting(value) {
11022 * return /^h(?:i|ello)$/.test(value);
11025 * function customizer(objValue, srcValue) {
11026 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11031 * var object = { 'greeting': 'hello' };
11032 * var source = { 'greeting': 'hi' };
11034 * _.isMatchWith(object, source, customizer);
11037 function isMatchWith(object, source, customizer) {
11038 customizer = typeof customizer == 'function' ? customizer : undefined;
11039 return baseIsMatch(object, source, getMatchData(source), customizer);
11043 * Checks if `value` is `NaN`.
11045 * **Note:** This method is based on
11046 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11047 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11048 * `undefined` and other non-number values.
11054 * @param {*} value The value to check.
11055 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11061 * _.isNaN(new Number(NaN));
11064 * isNaN(undefined);
11067 * _.isNaN(undefined);
11070 function isNaN(value) {
11071 // An `NaN` primitive is the only value that is not equal to itself.
11072 // Perform the `toStringTag` check first to avoid errors with some
11073 // ActiveX objects in IE.
11074 return isNumber(value) && value != +value;
11078 * Checks if `value` is a native function.
11084 * @param {*} value The value to check.
11085 * @returns {boolean} Returns `true` if `value` is a native function,
11089 * _.isNative(Array.prototype.push);
11095 function isNative(value) {
11096 if (!isObject(value)) {
11099 var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
11100 return pattern.test(toSource(value));
11104 * Checks if `value` is `null`.
11110 * @param {*} value The value to check.
11111 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
11117 * _.isNull(void 0);
11120 function isNull(value) {
11121 return value === null;
11125 * Checks if `value` is `null` or `undefined`.
11131 * @param {*} value The value to check.
11132 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
11144 function isNil(value) {
11145 return value == null;
11149 * Checks if `value` is classified as a `Number` primitive or object.
11151 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
11152 * classified as numbers, use the `_.isFinite` method.
11158 * @param {*} value The value to check.
11159 * @returns {boolean} Returns `true` if `value` is correctly classified,
11166 * _.isNumber(Number.MIN_VALUE);
11169 * _.isNumber(Infinity);
11175 function isNumber(value) {
11176 return typeof value == 'number' ||
11177 (isObjectLike(value) && objectToString.call(value) == numberTag);
11181 * Checks if `value` is a plain object, that is, an object created by the
11182 * `Object` constructor or one with a `[[Prototype]]` of `null`.
11188 * @param {*} value The value to check.
11189 * @returns {boolean} Returns `true` if `value` is a plain object,
11197 * _.isPlainObject(new Foo);
11200 * _.isPlainObject([1, 2, 3]);
11203 * _.isPlainObject({ 'x': 0, 'y': 0 });
11206 * _.isPlainObject(Object.create(null));
11209 function isPlainObject(value) {
11210 if (!isObjectLike(value) ||
11211 objectToString.call(value) != objectTag || isHostObject(value)) {
11214 var proto = getPrototype(value);
11215 if (proto === null) {
11218 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
11219 return (typeof Ctor == 'function' &&
11220 Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
11224 * Checks if `value` is classified as a `RegExp` object.
11230 * @param {*} value The value to check.
11231 * @returns {boolean} Returns `true` if `value` is correctly classified,
11235 * _.isRegExp(/abc/);
11238 * _.isRegExp('/abc/');
11241 function isRegExp(value) {
11242 return isObject(value) && objectToString.call(value) == regexpTag;
11246 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
11247 * double precision number which isn't the result of a rounded unsafe integer.
11249 * **Note:** This method is based on
11250 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
11256 * @param {*} value The value to check.
11257 * @returns {boolean} Returns `true` if `value` is a safe integer,
11261 * _.isSafeInteger(3);
11264 * _.isSafeInteger(Number.MIN_VALUE);
11267 * _.isSafeInteger(Infinity);
11270 * _.isSafeInteger('3');
11273 function isSafeInteger(value) {
11274 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
11278 * Checks if `value` is classified as a `Set` object.
11284 * @param {*} value The value to check.
11285 * @returns {boolean} Returns `true` if `value` is correctly classified,
11289 * _.isSet(new Set);
11292 * _.isSet(new WeakSet);
11295 function isSet(value) {
11296 return isObjectLike(value) && getTag(value) == setTag;
11300 * Checks if `value` is classified as a `String` primitive or object.
11306 * @param {*} value The value to check.
11307 * @returns {boolean} Returns `true` if `value` is correctly classified,
11311 * _.isString('abc');
11317 function isString(value) {
11318 return typeof value == 'string' ||
11319 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
11323 * Checks if `value` is classified as a `Symbol` primitive or object.
11329 * @param {*} value The value to check.
11330 * @returns {boolean} Returns `true` if `value` is correctly classified,
11334 * _.isSymbol(Symbol.iterator);
11337 * _.isSymbol('abc');
11340 function isSymbol(value) {
11341 return typeof value == 'symbol' ||
11342 (isObjectLike(value) && objectToString.call(value) == symbolTag);
11346 * Checks if `value` is classified as a typed array.
11352 * @param {*} value The value to check.
11353 * @returns {boolean} Returns `true` if `value` is correctly classified,
11357 * _.isTypedArray(new Uint8Array);
11360 * _.isTypedArray([]);
11363 function isTypedArray(value) {
11364 return isObjectLike(value) &&
11365 isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
11369 * Checks if `value` is `undefined`.
11375 * @param {*} value The value to check.
11376 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
11379 * _.isUndefined(void 0);
11382 * _.isUndefined(null);
11385 function isUndefined(value) {
11386 return value === undefined;
11390 * Checks if `value` is classified as a `WeakMap` object.
11396 * @param {*} value The value to check.
11397 * @returns {boolean} Returns `true` if `value` is correctly classified,
11401 * _.isWeakMap(new WeakMap);
11404 * _.isWeakMap(new Map);
11407 function isWeakMap(value) {
11408 return isObjectLike(value) && getTag(value) == weakMapTag;
11412 * Checks if `value` is classified as a `WeakSet` object.
11418 * @param {*} value The value to check.
11419 * @returns {boolean} Returns `true` if `value` is correctly classified,
11423 * _.isWeakSet(new WeakSet);
11426 * _.isWeakSet(new Set);
11429 function isWeakSet(value) {
11430 return isObjectLike(value) && objectToString.call(value) == weakSetTag;
11434 * Checks if `value` is less than `other`.
11440 * @param {*} value The value to compare.
11441 * @param {*} other The other value to compare.
11442 * @returns {boolean} Returns `true` if `value` is less than `other`,
11456 var lt = createRelationalOperation(baseLt);
11459 * Checks if `value` is less than or equal to `other`.
11465 * @param {*} value The value to compare.
11466 * @param {*} other The other value to compare.
11467 * @returns {boolean} Returns `true` if `value` is less than or equal to
11468 * `other`, else `false`.
11481 var lte = createRelationalOperation(function(value, other) {
11482 return value <= other;
11486 * Converts `value` to an array.
11492 * @param {*} value The value to convert.
11493 * @returns {Array} Returns the converted array.
11496 * _.toArray({ 'a': 1, 'b': 2 });
11499 * _.toArray('abc');
11500 * // => ['a', 'b', 'c']
11508 function toArray(value) {
11512 if (isArrayLike(value)) {
11513 return isString(value) ? stringToArray(value) : copyArray(value);
11515 if (iteratorSymbol && value[iteratorSymbol]) {
11516 return iteratorToArray(value[iteratorSymbol]());
11518 var tag = getTag(value),
11519 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
11521 return func(value);
11525 * Converts `value` to an integer.
11527 * **Note:** This function is loosely based on
11528 * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
11534 * @param {*} value The value to convert.
11535 * @returns {number} Returns the converted integer.
11541 * _.toInteger(Number.MIN_VALUE);
11544 * _.toInteger(Infinity);
11545 * // => 1.7976931348623157e+308
11547 * _.toInteger('3');
11550 function toInteger(value) {
11552 return value === 0 ? value : 0;
11554 value = toNumber(value);
11555 if (value === INFINITY || value === -INFINITY) {
11556 var sign = (value < 0 ? -1 : 1);
11557 return sign * MAX_INTEGER;
11559 var remainder = value % 1;
11560 return value === value ? (remainder ? value - remainder : value) : 0;
11564 * Converts `value` to an integer suitable for use as the length of an
11565 * array-like object.
11567 * **Note:** This method is based on
11568 * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
11574 * @param {*} value The value to convert.
11575 * @returns {number} Returns the converted integer.
11581 * _.toLength(Number.MIN_VALUE);
11584 * _.toLength(Infinity);
11590 function toLength(value) {
11591 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
11595 * Converts `value` to a number.
11601 * @param {*} value The value to process.
11602 * @returns {number} Returns the number.
11608 * _.toNumber(Number.MIN_VALUE);
11611 * _.toNumber(Infinity);
11617 function toNumber(value) {
11618 if (typeof value == 'number') {
11621 if (isSymbol(value)) {
11624 if (isObject(value)) {
11625 var other = isFunction(value.valueOf) ? value.valueOf() : value;
11626 value = isObject(other) ? (other + '') : other;
11628 if (typeof value != 'string') {
11629 return value === 0 ? value : +value;
11631 value = value.replace(reTrim, '');
11632 var isBinary = reIsBinary.test(value);
11633 return (isBinary || reIsOctal.test(value))
11634 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
11635 : (reIsBadHex.test(value) ? NAN : +value);
11639 * Converts `value` to a plain object flattening inherited enumerable string
11640 * keyed properties of `value` to own properties of the plain object.
11646 * @param {*} value The value to convert.
11647 * @returns {Object} Returns the converted plain object.
11654 * Foo.prototype.c = 3;
11656 * _.assign({ 'a': 1 }, new Foo);
11657 * // => { 'a': 1, 'b': 2 }
11659 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
11660 * // => { 'a': 1, 'b': 2, 'c': 3 }
11662 function toPlainObject(value) {
11663 return copyObject(value, keysIn(value));
11667 * Converts `value` to a safe integer. A safe integer can be compared and
11668 * represented correctly.
11674 * @param {*} value The value to convert.
11675 * @returns {number} Returns the converted integer.
11678 * _.toSafeInteger(3);
11681 * _.toSafeInteger(Number.MIN_VALUE);
11684 * _.toSafeInteger(Infinity);
11685 * // => 9007199254740991
11687 * _.toSafeInteger('3');
11690 function toSafeInteger(value) {
11691 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
11695 * Converts `value` to a string. An empty string is returned for `null`
11696 * and `undefined` values. The sign of `-0` is preserved.
11702 * @param {*} value The value to process.
11703 * @returns {string} Returns the string.
11706 * _.toString(null);
11712 * _.toString([1, 2, 3]);
11715 function toString(value) {
11716 return value == null ? '' : baseToString(value);
11719 /*------------------------------------------------------------------------*/
11722 * Assigns own enumerable string keyed properties of source objects to the
11723 * destination object. Source objects are applied from left to right.
11724 * Subsequent sources overwrite property assignments of previous sources.
11726 * **Note:** This method mutates `object` and is loosely based on
11727 * [`Object.assign`](https://mdn.io/Object/assign).
11733 * @param {Object} object The destination object.
11734 * @param {...Object} [sources] The source objects.
11735 * @returns {Object} Returns `object`.
11747 * Foo.prototype.d = 4;
11748 * Bar.prototype.f = 6;
11750 * _.assign({ 'a': 1 }, new Foo, new Bar);
11751 * // => { 'a': 1, 'c': 3, 'e': 5 }
11753 var assign = createAssigner(function(object, source) {
11754 if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
11755 copyObject(source, keys(source), object);
11758 for (var key in source) {
11759 if (hasOwnProperty.call(source, key)) {
11760 assignValue(object, key, source[key]);
11766 * This method is like `_.assign` except that it iterates over own and
11767 * inherited source properties.
11769 * **Note:** This method mutates `object`.
11776 * @param {Object} object The destination object.
11777 * @param {...Object} [sources] The source objects.
11778 * @returns {Object} Returns `object`.
11790 * Foo.prototype.c = 3;
11791 * Bar.prototype.e = 5;
11793 * _.assignIn({ 'a': 1 }, new Foo, new Bar);
11794 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
11796 var assignIn = createAssigner(function(object, source) {
11797 if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
11798 copyObject(source, keysIn(source), object);
11801 for (var key in source) {
11802 assignValue(object, key, source[key]);
11807 * This method is like `_.assignIn` except that it accepts `customizer`
11808 * which is invoked to produce the assigned values. If `customizer` returns
11809 * `undefined`, assignment is handled by the method instead. The `customizer`
11810 * is invoked with five arguments: (objValue, srcValue, key, object, source).
11812 * **Note:** This method mutates `object`.
11817 * @alias extendWith
11819 * @param {Object} object The destination object.
11820 * @param {...Object} sources The source objects.
11821 * @param {Function} [customizer] The function to customize assigned values.
11822 * @returns {Object} Returns `object`.
11823 * @see _.assignWith
11826 * function customizer(objValue, srcValue) {
11827 * return _.isUndefined(objValue) ? srcValue : objValue;
11830 * var defaults = _.partialRight(_.assignInWith, customizer);
11832 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
11833 * // => { 'a': 1, 'b': 2 }
11835 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
11836 copyObject(source, keysIn(source), object, customizer);
11840 * This method is like `_.assign` except that it accepts `customizer`
11841 * which is invoked to produce the assigned values. If `customizer` returns
11842 * `undefined`, assignment is handled by the method instead. The `customizer`
11843 * is invoked with five arguments: (objValue, srcValue, key, object, source).
11845 * **Note:** This method mutates `object`.
11851 * @param {Object} object The destination object.
11852 * @param {...Object} sources The source objects.
11853 * @param {Function} [customizer] The function to customize assigned values.
11854 * @returns {Object} Returns `object`.
11855 * @see _.assignInWith
11858 * function customizer(objValue, srcValue) {
11859 * return _.isUndefined(objValue) ? srcValue : objValue;
11862 * var defaults = _.partialRight(_.assignWith, customizer);
11864 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
11865 * // => { 'a': 1, 'b': 2 }
11867 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
11868 copyObject(source, keys(source), object, customizer);
11872 * Creates an array of values corresponding to `paths` of `object`.
11878 * @param {Object} object The object to iterate over.
11879 * @param {...(string|string[])} [paths] The property paths of elements to pick.
11880 * @returns {Array} Returns the new array of picked elements.
11883 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
11885 * _.at(object, ['a[0].b.c', 'a[1]']);
11888 * _.at(['a', 'b', 'c'], 0, 2);
11891 var at = rest(function(object, paths) {
11892 return baseAt(object, baseFlatten(paths, 1));
11896 * Creates an object that inherits from the `prototype` object. If a
11897 * `properties` object is given, its own enumerable string keyed properties
11898 * are assigned to the created object.
11904 * @param {Object} prototype The object to inherit from.
11905 * @param {Object} [properties] The properties to assign to the object.
11906 * @returns {Object} Returns the new object.
11909 * function Shape() {
11914 * function Circle() {
11915 * Shape.call(this);
11918 * Circle.prototype = _.create(Shape.prototype, {
11919 * 'constructor': Circle
11922 * var circle = new Circle;
11923 * circle instanceof Circle;
11926 * circle instanceof Shape;
11929 function create(prototype, properties) {
11930 var result = baseCreate(prototype);
11931 return properties ? baseAssign(result, properties) : result;
11935 * Assigns own and inherited enumerable string keyed properties of source
11936 * objects to the destination object for all destination properties that
11937 * resolve to `undefined`. Source objects are applied from left to right.
11938 * Once a property is set, additional values of the same property are ignored.
11940 * **Note:** This method mutates `object`.
11946 * @param {Object} object The destination object.
11947 * @param {...Object} [sources] The source objects.
11948 * @returns {Object} Returns `object`.
11949 * @see _.defaultsDeep
11952 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
11953 * // => { 'user': 'barney', 'age': 36 }
11955 var defaults = rest(function(args) {
11956 args.push(undefined, assignInDefaults);
11957 return apply(assignInWith, undefined, args);
11961 * This method is like `_.defaults` except that it recursively assigns
11962 * default properties.
11964 * **Note:** This method mutates `object`.
11970 * @param {Object} object The destination object.
11971 * @param {...Object} [sources] The source objects.
11972 * @returns {Object} Returns `object`.
11976 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
11977 * // => { 'user': { 'name': 'barney', 'age': 36 } }
11980 var defaultsDeep = rest(function(args) {
11981 args.push(undefined, mergeDefaults);
11982 return apply(mergeWith, undefined, args);
11986 * This method is like `_.find` except that it returns the key of the first
11987 * element `predicate` returns truthy for instead of the element itself.
11993 * @param {Object} object The object to search.
11994 * @param {Array|Function|Object|string} [predicate=_.identity]
11995 * The function invoked per iteration.
11996 * @returns {string|undefined} Returns the key of the matched element,
11997 * else `undefined`.
12001 * 'barney': { 'age': 36, 'active': true },
12002 * 'fred': { 'age': 40, 'active': false },
12003 * 'pebbles': { 'age': 1, 'active': true }
12006 * _.findKey(users, function(o) { return o.age < 40; });
12007 * // => 'barney' (iteration order is not guaranteed)
12009 * // The `_.matches` iteratee shorthand.
12010 * _.findKey(users, { 'age': 1, 'active': true });
12013 * // The `_.matchesProperty` iteratee shorthand.
12014 * _.findKey(users, ['active', false]);
12017 * // The `_.property` iteratee shorthand.
12018 * _.findKey(users, 'active');
12021 function findKey(object, predicate) {
12022 return baseFind(object, getIteratee(predicate, 3), baseForOwn, true);
12026 * This method is like `_.findKey` except that it iterates over elements of
12027 * a collection in the opposite order.
12033 * @param {Object} object The object to search.
12034 * @param {Array|Function|Object|string} [predicate=_.identity]
12035 * The function invoked per iteration.
12036 * @returns {string|undefined} Returns the key of the matched element,
12037 * else `undefined`.
12041 * 'barney': { 'age': 36, 'active': true },
12042 * 'fred': { 'age': 40, 'active': false },
12043 * 'pebbles': { 'age': 1, 'active': true }
12046 * _.findLastKey(users, function(o) { return o.age < 40; });
12047 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
12049 * // The `_.matches` iteratee shorthand.
12050 * _.findLastKey(users, { 'age': 36, 'active': true });
12053 * // The `_.matchesProperty` iteratee shorthand.
12054 * _.findLastKey(users, ['active', false]);
12057 * // The `_.property` iteratee shorthand.
12058 * _.findLastKey(users, 'active');
12061 function findLastKey(object, predicate) {
12062 return baseFind(object, getIteratee(predicate, 3), baseForOwnRight, true);
12066 * Iterates over own and inherited enumerable string keyed properties of an
12067 * object and invokes `iteratee` for each property. The iteratee is invoked
12068 * with three arguments: (value, key, object). Iteratee functions may exit
12069 * iteration early by explicitly returning `false`.
12075 * @param {Object} object The object to iterate over.
12076 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12077 * @returns {Object} Returns `object`.
12078 * @see _.forInRight
12086 * Foo.prototype.c = 3;
12088 * _.forIn(new Foo, function(value, key) {
12089 * console.log(key);
12091 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
12093 function forIn(object, iteratee) {
12094 return object == null
12096 : baseFor(object, getIteratee(iteratee), keysIn);
12100 * This method is like `_.forIn` except that it iterates over properties of
12101 * `object` in the opposite order.
12107 * @param {Object} object The object to iterate over.
12108 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12109 * @returns {Object} Returns `object`.
12118 * Foo.prototype.c = 3;
12120 * _.forInRight(new Foo, function(value, key) {
12121 * console.log(key);
12123 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
12125 function forInRight(object, iteratee) {
12126 return object == null
12128 : baseForRight(object, getIteratee(iteratee), keysIn);
12132 * Iterates over own enumerable string keyed properties of an object and
12133 * invokes `iteratee` for each property. The iteratee is invoked with three
12134 * arguments: (value, key, object). Iteratee functions may exit iteration
12135 * early by explicitly returning `false`.
12141 * @param {Object} object The object to iterate over.
12142 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12143 * @returns {Object} Returns `object`.
12144 * @see _.forOwnRight
12152 * Foo.prototype.c = 3;
12154 * _.forOwn(new Foo, function(value, key) {
12155 * console.log(key);
12157 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
12159 function forOwn(object, iteratee) {
12160 return object && baseForOwn(object, getIteratee(iteratee));
12164 * This method is like `_.forOwn` except that it iterates over properties of
12165 * `object` in the opposite order.
12171 * @param {Object} object The object to iterate over.
12172 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12173 * @returns {Object} Returns `object`.
12182 * Foo.prototype.c = 3;
12184 * _.forOwnRight(new Foo, function(value, key) {
12185 * console.log(key);
12187 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
12189 function forOwnRight(object, iteratee) {
12190 return object && baseForOwnRight(object, getIteratee(iteratee));
12194 * Creates an array of function property names from own enumerable properties
12201 * @param {Object} object The object to inspect.
12202 * @returns {Array} Returns the new array of property names.
12203 * @see _.functionsIn
12207 * this.a = _.constant('a');
12208 * this.b = _.constant('b');
12211 * Foo.prototype.c = _.constant('c');
12213 * _.functions(new Foo);
12216 function functions(object) {
12217 return object == null ? [] : baseFunctions(object, keys(object));
12221 * Creates an array of function property names from own and inherited
12222 * enumerable properties of `object`.
12228 * @param {Object} object The object to inspect.
12229 * @returns {Array} Returns the new array of property names.
12234 * this.a = _.constant('a');
12235 * this.b = _.constant('b');
12238 * Foo.prototype.c = _.constant('c');
12240 * _.functionsIn(new Foo);
12241 * // => ['a', 'b', 'c']
12243 function functionsIn(object) {
12244 return object == null ? [] : baseFunctions(object, keysIn(object));
12248 * Gets the value at `path` of `object`. If the resolved value is
12249 * `undefined`, the `defaultValue` is used in its place.
12255 * @param {Object} object The object to query.
12256 * @param {Array|string} path The path of the property to get.
12257 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
12258 * @returns {*} Returns the resolved value.
12261 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
12263 * _.get(object, 'a[0].b.c');
12266 * _.get(object, ['a', '0', 'b', 'c']);
12269 * _.get(object, 'a.b.c', 'default');
12272 function get(object, path, defaultValue) {
12273 var result = object == null ? undefined : baseGet(object, path);
12274 return result === undefined ? defaultValue : result;
12278 * Checks if `path` is a direct property of `object`.
12284 * @param {Object} object The object to query.
12285 * @param {Array|string} path The path to check.
12286 * @returns {boolean} Returns `true` if `path` exists, else `false`.
12289 * var object = { 'a': { 'b': 2 } };
12290 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
12292 * _.has(object, 'a');
12295 * _.has(object, 'a.b');
12298 * _.has(object, ['a', 'b']);
12301 * _.has(other, 'a');
12304 function has(object, path) {
12305 return object != null && hasPath(object, path, baseHas);
12309 * Checks if `path` is a direct or inherited property of `object`.
12315 * @param {Object} object The object to query.
12316 * @param {Array|string} path The path to check.
12317 * @returns {boolean} Returns `true` if `path` exists, else `false`.
12320 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
12322 * _.hasIn(object, 'a');
12325 * _.hasIn(object, 'a.b');
12328 * _.hasIn(object, ['a', 'b']);
12331 * _.hasIn(object, 'b');
12334 function hasIn(object, path) {
12335 return object != null && hasPath(object, path, baseHasIn);
12339 * Creates an object composed of the inverted keys and values of `object`.
12340 * If `object` contains duplicate values, subsequent values overwrite
12341 * property assignments of previous values.
12347 * @param {Object} object The object to invert.
12348 * @returns {Object} Returns the new inverted object.
12351 * var object = { 'a': 1, 'b': 2, 'c': 1 };
12353 * _.invert(object);
12354 * // => { '1': 'c', '2': 'b' }
12356 var invert = createInverter(function(result, value, key) {
12357 result[value] = key;
12358 }, constant(identity));
12361 * This method is like `_.invert` except that the inverted object is generated
12362 * from the results of running each element of `object` thru `iteratee`. The
12363 * corresponding inverted value of each inverted key is an array of keys
12364 * responsible for generating the inverted value. The iteratee is invoked
12365 * with one argument: (value).
12371 * @param {Object} object The object to invert.
12372 * @param {Array|Function|Object|string} [iteratee=_.identity]
12373 * The iteratee invoked per element.
12374 * @returns {Object} Returns the new inverted object.
12377 * var object = { 'a': 1, 'b': 2, 'c': 1 };
12379 * _.invertBy(object);
12380 * // => { '1': ['a', 'c'], '2': ['b'] }
12382 * _.invertBy(object, function(value) {
12383 * return 'group' + value;
12385 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
12387 var invertBy = createInverter(function(result, value, key) {
12388 if (hasOwnProperty.call(result, value)) {
12389 result[value].push(key);
12391 result[value] = [key];
12396 * Invokes the method at `path` of `object`.
12402 * @param {Object} object The object to query.
12403 * @param {Array|string} path The path of the method to invoke.
12404 * @param {...*} [args] The arguments to invoke the method with.
12405 * @returns {*} Returns the result of the invoked method.
12408 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
12410 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
12413 var invoke = rest(baseInvoke);
12416 * Creates an array of the own enumerable property names of `object`.
12418 * **Note:** Non-object values are coerced to objects. See the
12419 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
12420 * for more details.
12426 * @param {Object} object The object to query.
12427 * @returns {Array} Returns the array of property names.
12435 * Foo.prototype.c = 3;
12438 * // => ['a', 'b'] (iteration order is not guaranteed)
12443 function keys(object) {
12444 var isProto = isPrototype(object);
12445 if (!(isProto || isArrayLike(object))) {
12446 return baseKeys(object);
12448 var indexes = indexKeys(object),
12449 skipIndexes = !!indexes,
12450 result = indexes || [],
12451 length = result.length;
12453 for (var key in object) {
12454 if (baseHas(object, key) &&
12455 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
12456 !(isProto && key == 'constructor')) {
12464 * Creates an array of the own and inherited enumerable property names of `object`.
12466 * **Note:** Non-object values are coerced to objects.
12472 * @param {Object} object The object to query.
12473 * @returns {Array} Returns the array of property names.
12481 * Foo.prototype.c = 3;
12483 * _.keysIn(new Foo);
12484 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
12486 function keysIn(object) {
12488 isProto = isPrototype(object),
12489 props = baseKeysIn(object),
12490 propsLength = props.length,
12491 indexes = indexKeys(object),
12492 skipIndexes = !!indexes,
12493 result = indexes || [],
12494 length = result.length;
12496 while (++index < propsLength) {
12497 var key = props[index];
12498 if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
12499 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
12507 * The opposite of `_.mapValues`; this method creates an object with the
12508 * same values as `object` and keys generated by running each own enumerable
12509 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
12510 * with three arguments: (value, key, object).
12516 * @param {Object} object The object to iterate over.
12517 * @param {Array|Function|Object|string} [iteratee=_.identity]
12518 * The function invoked per iteration.
12519 * @returns {Object} Returns the new mapped object.
12523 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
12524 * return key + value;
12526 * // => { 'a1': 1, 'b2': 2 }
12528 function mapKeys(object, iteratee) {
12530 iteratee = getIteratee(iteratee, 3);
12532 baseForOwn(object, function(value, key, object) {
12533 result[iteratee(value, key, object)] = value;
12539 * Creates an object with the same keys as `object` and values generated
12540 * by running each own enumerable string keyed property of `object` thru
12541 * `iteratee`. The iteratee is invoked with three arguments:
12542 * (value, key, object).
12548 * @param {Object} object The object to iterate over.
12549 * @param {Array|Function|Object|string} [iteratee=_.identity]
12550 * The function invoked per iteration.
12551 * @returns {Object} Returns the new mapped object.
12556 * 'fred': { 'user': 'fred', 'age': 40 },
12557 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
12560 * _.mapValues(users, function(o) { return o.age; });
12561 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
12563 * // The `_.property` iteratee shorthand.
12564 * _.mapValues(users, 'age');
12565 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
12567 function mapValues(object, iteratee) {
12569 iteratee = getIteratee(iteratee, 3);
12571 baseForOwn(object, function(value, key, object) {
12572 result[key] = iteratee(value, key, object);
12578 * This method is like `_.assign` except that it recursively merges own and
12579 * inherited enumerable string keyed properties of source objects into the
12580 * destination object. Source properties that resolve to `undefined` are
12581 * skipped if a destination value exists. Array and plain object properties
12582 * are merged recursively.Other objects and value types are overridden by
12583 * assignment. Source objects are applied from left to right. Subsequent
12584 * sources overwrite property assignments of previous sources.
12586 * **Note:** This method mutates `object`.
12592 * @param {Object} object The destination object.
12593 * @param {...Object} [sources] The source objects.
12594 * @returns {Object} Returns `object`.
12598 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
12602 * 'data': [{ 'age': 36 }, { 'age': 40 }]
12605 * _.merge(users, ages);
12606 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
12608 var merge = createAssigner(function(object, source, srcIndex) {
12609 baseMerge(object, source, srcIndex);
12613 * This method is like `_.merge` except that it accepts `customizer` which
12614 * is invoked to produce the merged values of the destination and source
12615 * properties. If `customizer` returns `undefined`, merging is handled by the
12616 * method instead. The `customizer` is invoked with seven arguments:
12617 * (objValue, srcValue, key, object, source, stack).
12619 * **Note:** This method mutates `object`.
12625 * @param {Object} object The destination object.
12626 * @param {...Object} sources The source objects.
12627 * @param {Function} customizer The function to customize assigned values.
12628 * @returns {Object} Returns `object`.
12631 * function customizer(objValue, srcValue) {
12632 * if (_.isArray(objValue)) {
12633 * return objValue.concat(srcValue);
12638 * 'fruits': ['apple'],
12639 * 'vegetables': ['beet']
12643 * 'fruits': ['banana'],
12644 * 'vegetables': ['carrot']
12647 * _.mergeWith(object, other, customizer);
12648 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
12650 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
12651 baseMerge(object, source, srcIndex, customizer);
12655 * The opposite of `_.pick`; this method creates an object composed of the
12656 * own and inherited enumerable string keyed properties of `object` that are
12663 * @param {Object} object The source object.
12664 * @param {...(string|string[])} [props] The property identifiers to omit.
12665 * @returns {Object} Returns the new object.
12668 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12670 * _.omit(object, ['a', 'c']);
12671 * // => { 'b': '2' }
12673 var omit = rest(function(object, props) {
12674 if (object == null) {
12677 props = arrayMap(baseFlatten(props, 1), toKey);
12678 return basePick(object, baseDifference(getAllKeysIn(object), props));
12682 * The opposite of `_.pickBy`; this method creates an object composed of
12683 * the own and inherited enumerable string keyed properties of `object` that
12684 * `predicate` doesn't return truthy for. The predicate is invoked with two
12685 * arguments: (value, key).
12691 * @param {Object} object The source object.
12692 * @param {Array|Function|Object|string} [predicate=_.identity]
12693 * The function invoked per property.
12694 * @returns {Object} Returns the new object.
12697 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12699 * _.omitBy(object, _.isNumber);
12700 * // => { 'b': '2' }
12702 function omitBy(object, predicate) {
12703 predicate = getIteratee(predicate);
12704 return basePickBy(object, function(value, key) {
12705 return !predicate(value, key);
12710 * Creates an object composed of the picked `object` properties.
12716 * @param {Object} object The source object.
12717 * @param {...(string|string[])} [props] The property identifiers to pick.
12718 * @returns {Object} Returns the new object.
12721 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12723 * _.pick(object, ['a', 'c']);
12724 * // => { 'a': 1, 'c': 3 }
12726 var pick = rest(function(object, props) {
12727 return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
12731 * Creates an object composed of the `object` properties `predicate` returns
12732 * truthy for. The predicate is invoked with two arguments: (value, key).
12738 * @param {Object} object The source object.
12739 * @param {Array|Function|Object|string} [predicate=_.identity]
12740 * The function invoked per property.
12741 * @returns {Object} Returns the new object.
12744 * var object = { 'a': 1, 'b': '2', 'c': 3 };
12746 * _.pickBy(object, _.isNumber);
12747 * // => { 'a': 1, 'c': 3 }
12749 function pickBy(object, predicate) {
12750 return object == null ? {} : basePickBy(object, getIteratee(predicate));
12754 * This method is like `_.get` except that if the resolved value is a
12755 * function it's invoked with the `this` binding of its parent object and
12756 * its result is returned.
12762 * @param {Object} object The object to query.
12763 * @param {Array|string} path The path of the property to resolve.
12764 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
12765 * @returns {*} Returns the resolved value.
12768 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
12770 * _.result(object, 'a[0].b.c1');
12773 * _.result(object, 'a[0].b.c2');
12776 * _.result(object, 'a[0].b.c3', 'default');
12779 * _.result(object, 'a[0].b.c3', _.constant('default'));
12782 function result(object, path, defaultValue) {
12783 path = isKey(path, object) ? [path] : castPath(path);
12786 length = path.length;
12788 // Ensure the loop is entered when path is empty.
12790 object = undefined;
12793 while (++index < length) {
12794 var value = object == null ? undefined : object[toKey(path[index])];
12795 if (value === undefined) {
12797 value = defaultValue;
12799 object = isFunction(value) ? value.call(object) : value;
12805 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
12806 * it's created. Arrays are created for missing index properties while objects
12807 * are created for all other missing properties. Use `_.setWith` to customize
12810 * **Note:** This method mutates `object`.
12816 * @param {Object} object The object to modify.
12817 * @param {Array|string} path The path of the property to set.
12818 * @param {*} value The value to set.
12819 * @returns {Object} Returns `object`.
12822 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
12824 * _.set(object, 'a[0].b.c', 4);
12825 * console.log(object.a[0].b.c);
12828 * _.set(object, ['x', '0', 'y', 'z'], 5);
12829 * console.log(object.x[0].y.z);
12832 function set(object, path, value) {
12833 return object == null ? object : baseSet(object, path, value);
12837 * This method is like `_.set` except that it accepts `customizer` which is
12838 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
12839 * path creation is handled by the method instead. The `customizer` is invoked
12840 * with three arguments: (nsValue, key, nsObject).
12842 * **Note:** This method mutates `object`.
12848 * @param {Object} object The object to modify.
12849 * @param {Array|string} path The path of the property to set.
12850 * @param {*} value The value to set.
12851 * @param {Function} [customizer] The function to customize assigned values.
12852 * @returns {Object} Returns `object`.
12857 * _.setWith(object, '[0][1]', 'a', Object);
12858 * // => { '0': { '1': 'a' } }
12860 function setWith(object, path, value, customizer) {
12861 customizer = typeof customizer == 'function' ? customizer : undefined;
12862 return object == null ? object : baseSet(object, path, value, customizer);
12866 * Creates an array of own enumerable string keyed-value pairs for `object`
12867 * which can be consumed by `_.fromPairs`.
12874 * @param {Object} object The object to query.
12875 * @returns {Array} Returns the new array of key-value pairs.
12883 * Foo.prototype.c = 3;
12885 * _.toPairs(new Foo);
12886 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
12888 function toPairs(object) {
12889 return baseToPairs(object, keys(object));
12893 * Creates an array of own and inherited enumerable string keyed-value pairs
12894 * for `object` which can be consumed by `_.fromPairs`.
12901 * @param {Object} object The object to query.
12902 * @returns {Array} Returns the new array of key-value pairs.
12910 * Foo.prototype.c = 3;
12912 * _.toPairsIn(new Foo);
12913 * // => [['a', 1], ['b', 2], ['c', 1]] (iteration order is not guaranteed)
12915 function toPairsIn(object) {
12916 return baseToPairs(object, keysIn(object));
12920 * An alternative to `_.reduce`; this method transforms `object` to a new
12921 * `accumulator` object which is the result of running each of its own
12922 * enumerable string keyed properties thru `iteratee`, with each invocation
12923 * potentially mutating the `accumulator` object. The iteratee is invoked
12924 * with four arguments: (accumulator, value, key, object). Iteratee functions
12925 * may exit iteration early by explicitly returning `false`.
12931 * @param {Array|Object} object The object to iterate over.
12932 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12933 * @param {*} [accumulator] The custom accumulator value.
12934 * @returns {*} Returns the accumulated value.
12937 * _.transform([2, 3, 4], function(result, n) {
12938 * result.push(n *= n);
12939 * return n % 2 == 0;
12943 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
12944 * (result[value] || (result[value] = [])).push(key);
12946 * // => { '1': ['a', 'c'], '2': ['b'] }
12948 function transform(object, iteratee, accumulator) {
12949 var isArr = isArray(object) || isTypedArray(object);
12950 iteratee = getIteratee(iteratee, 4);
12952 if (accumulator == null) {
12953 if (isArr || isObject(object)) {
12954 var Ctor = object.constructor;
12956 accumulator = isArray(object) ? new Ctor : [];
12958 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
12964 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
12965 return iteratee(accumulator, value, index, object);
12967 return accumulator;
12971 * Removes the property at `path` of `object`.
12973 * **Note:** This method mutates `object`.
12979 * @param {Object} object The object to modify.
12980 * @param {Array|string} path The path of the property to unset.
12981 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
12984 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
12985 * _.unset(object, 'a[0].b.c');
12988 * console.log(object);
12989 * // => { 'a': [{ 'b': {} }] };
12991 * _.unset(object, ['a', '0', 'b', 'c']);
12994 * console.log(object);
12995 * // => { 'a': [{ 'b': {} }] };
12997 function unset(object, path) {
12998 return object == null ? true : baseUnset(object, path);
13002 * This method is like `_.set` except that accepts `updater` to produce the
13003 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13004 * is invoked with one argument: (value).
13006 * **Note:** This method mutates `object`.
13012 * @param {Object} object The object to modify.
13013 * @param {Array|string} path The path of the property to set.
13014 * @param {Function} updater The function to produce the updated value.
13015 * @returns {Object} Returns `object`.
13018 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13020 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13021 * console.log(object.a[0].b.c);
13024 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13025 * console.log(object.x[0].y.z);
13028 function update(object, path, updater) {
13029 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13033 * This method is like `_.update` except that it accepts `customizer` which is
13034 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13035 * path creation is handled by the method instead. The `customizer` is invoked
13036 * with three arguments: (nsValue, key, nsObject).
13038 * **Note:** This method mutates `object`.
13044 * @param {Object} object The object to modify.
13045 * @param {Array|string} path The path of the property to set.
13046 * @param {Function} updater The function to produce the updated value.
13047 * @param {Function} [customizer] The function to customize assigned values.
13048 * @returns {Object} Returns `object`.
13053 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13054 * // => { '0': { '1': 'a' } }
13056 function updateWith(object, path, updater, customizer) {
13057 customizer = typeof customizer == 'function' ? customizer : undefined;
13058 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
13062 * Creates an array of the own enumerable string keyed property values of `object`.
13064 * **Note:** Non-object values are coerced to objects.
13070 * @param {Object} object The object to query.
13071 * @returns {Array} Returns the array of property values.
13079 * Foo.prototype.c = 3;
13081 * _.values(new Foo);
13082 * // => [1, 2] (iteration order is not guaranteed)
13087 function values(object) {
13088 return object ? baseValues(object, keys(object)) : [];
13092 * Creates an array of the own and inherited enumerable string keyed property
13093 * values of `object`.
13095 * **Note:** Non-object values are coerced to objects.
13101 * @param {Object} object The object to query.
13102 * @returns {Array} Returns the array of property values.
13110 * Foo.prototype.c = 3;
13112 * _.valuesIn(new Foo);
13113 * // => [1, 2, 3] (iteration order is not guaranteed)
13115 function valuesIn(object) {
13116 return object == null ? [] : baseValues(object, keysIn(object));
13119 /*------------------------------------------------------------------------*/
13122 * Clamps `number` within the inclusive `lower` and `upper` bounds.
13128 * @param {number} number The number to clamp.
13129 * @param {number} [lower] The lower bound.
13130 * @param {number} upper The upper bound.
13131 * @returns {number} Returns the clamped number.
13134 * _.clamp(-10, -5, 5);
13137 * _.clamp(10, -5, 5);
13140 function clamp(number, lower, upper) {
13141 if (upper === undefined) {
13145 if (upper !== undefined) {
13146 upper = toNumber(upper);
13147 upper = upper === upper ? upper : 0;
13149 if (lower !== undefined) {
13150 lower = toNumber(lower);
13151 lower = lower === lower ? lower : 0;
13153 return baseClamp(toNumber(number), lower, upper);
13157 * Checks if `n` is between `start` and up to, but not including, `end`. If
13158 * `end` is not specified, it's set to `start` with `start` then set to `0`.
13159 * If `start` is greater than `end` the params are swapped to support
13166 * @param {number} number The number to check.
13167 * @param {number} [start=0] The start of the range.
13168 * @param {number} end The end of the range.
13169 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
13170 * @see _.range, _.rangeRight
13173 * _.inRange(3, 2, 4);
13185 * _.inRange(1.2, 2);
13188 * _.inRange(5.2, 4);
13191 * _.inRange(-3, -2, -6);
13194 function inRange(number, start, end) {
13195 start = toNumber(start) || 0;
13196 if (end === undefined) {
13200 end = toNumber(end) || 0;
13202 number = toNumber(number);
13203 return baseInRange(number, start, end);
13207 * Produces a random number between the inclusive `lower` and `upper` bounds.
13208 * If only one argument is provided a number between `0` and the given number
13209 * is returned. If `floating` is `true`, or either `lower` or `upper` are
13210 * floats, a floating-point number is returned instead of an integer.
13212 * **Note:** JavaScript follows the IEEE-754 standard for resolving
13213 * floating-point values which can produce unexpected results.
13219 * @param {number} [lower=0] The lower bound.
13220 * @param {number} [upper=1] The upper bound.
13221 * @param {boolean} [floating] Specify returning a floating-point number.
13222 * @returns {number} Returns the random number.
13226 * // => an integer between 0 and 5
13229 * // => also an integer between 0 and 5
13231 * _.random(5, true);
13232 * // => a floating-point number between 0 and 5
13234 * _.random(1.2, 5.2);
13235 * // => a floating-point number between 1.2 and 5.2
13237 function random(lower, upper, floating) {
13238 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
13239 upper = floating = undefined;
13241 if (floating === undefined) {
13242 if (typeof upper == 'boolean') {
13246 else if (typeof lower == 'boolean') {
13251 if (lower === undefined && upper === undefined) {
13256 lower = toNumber(lower) || 0;
13257 if (upper === undefined) {
13261 upper = toNumber(upper) || 0;
13264 if (lower > upper) {
13269 if (floating || lower % 1 || upper % 1) {
13270 var rand = nativeRandom();
13271 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
13273 return baseRandom(lower, upper);
13276 /*------------------------------------------------------------------------*/
13279 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
13285 * @param {string} [string=''] The string to convert.
13286 * @returns {string} Returns the camel cased string.
13289 * _.camelCase('Foo Bar');
13292 * _.camelCase('--foo-bar--');
13295 * _.camelCase('__FOO_BAR__');
13298 var camelCase = createCompounder(function(result, word, index) {
13299 word = word.toLowerCase();
13300 return result + (index ? capitalize(word) : word);
13304 * Converts the first character of `string` to upper case and the remaining
13311 * @param {string} [string=''] The string to capitalize.
13312 * @returns {string} Returns the capitalized string.
13315 * _.capitalize('FRED');
13318 function capitalize(string) {
13319 return upperFirst(toString(string).toLowerCase());
13323 * Deburrs `string` by converting
13324 * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
13325 * to basic latin letters and removing
13326 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
13332 * @param {string} [string=''] The string to deburr.
13333 * @returns {string} Returns the deburred string.
13336 * _.deburr('déjà vu');
13339 function deburr(string) {
13340 string = toString(string);
13341 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
13345 * Checks if `string` ends with the given target string.
13351 * @param {string} [string=''] The string to search.
13352 * @param {string} [target] The string to search for.
13353 * @param {number} [position=string.length] The position to search from.
13354 * @returns {boolean} Returns `true` if `string` ends with `target`,
13358 * _.endsWith('abc', 'c');
13361 * _.endsWith('abc', 'b');
13364 * _.endsWith('abc', 'b', 2);
13367 function endsWith(string, target, position) {
13368 string = toString(string);
13369 target = baseToString(target);
13371 var length = string.length;
13372 position = position === undefined
13374 : baseClamp(toInteger(position), 0, length);
13376 position -= target.length;
13377 return position >= 0 && string.indexOf(target, position) == position;
13381 * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
13382 * their corresponding HTML entities.
13384 * **Note:** No other characters are escaped. To escape additional
13385 * characters use a third-party library like [_he_](https://mths.be/he).
13387 * Though the ">" character is escaped for symmetry, characters like
13388 * ">" and "/" don't need escaping in HTML and have no special meaning
13389 * unless they're part of a tag or unquoted attribute value. See
13390 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
13391 * (under "semi-related fun fact") for more details.
13393 * Backticks are escaped because in IE < 9, they can break out of
13394 * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
13395 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
13396 * [#133](https://html5sec.org/#133) of the
13397 * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
13399 * When working with HTML you should always
13400 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
13407 * @param {string} [string=''] The string to escape.
13408 * @returns {string} Returns the escaped string.
13411 * _.escape('fred, barney, & pebbles');
13412 * // => 'fred, barney, & pebbles'
13414 function escape(string) {
13415 string = toString(string);
13416 return (string && reHasUnescapedHtml.test(string))
13417 ? string.replace(reUnescapedHtml, escapeHtmlChar)
13422 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
13423 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
13429 * @param {string} [string=''] The string to escape.
13430 * @returns {string} Returns the escaped string.
13433 * _.escapeRegExp('[lodash](https://lodash.com/)');
13434 * // => '\[lodash\]\(https://lodash\.com/\)'
13436 function escapeRegExp(string) {
13437 string = toString(string);
13438 return (string && reHasRegExpChar.test(string))
13439 ? string.replace(reRegExpChar, '\\$&')
13444 * Converts `string` to
13445 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
13451 * @param {string} [string=''] The string to convert.
13452 * @returns {string} Returns the kebab cased string.
13455 * _.kebabCase('Foo Bar');
13458 * _.kebabCase('fooBar');
13461 * _.kebabCase('__FOO_BAR__');
13464 var kebabCase = createCompounder(function(result, word, index) {
13465 return result + (index ? '-' : '') + word.toLowerCase();
13469 * Converts `string`, as space separated words, to lower case.
13475 * @param {string} [string=''] The string to convert.
13476 * @returns {string} Returns the lower cased string.
13479 * _.lowerCase('--Foo-Bar--');
13482 * _.lowerCase('fooBar');
13485 * _.lowerCase('__FOO_BAR__');
13488 var lowerCase = createCompounder(function(result, word, index) {
13489 return result + (index ? ' ' : '') + word.toLowerCase();
13493 * Converts the first character of `string` to lower case.
13499 * @param {string} [string=''] The string to convert.
13500 * @returns {string} Returns the converted string.
13503 * _.lowerFirst('Fred');
13506 * _.lowerFirst('FRED');
13509 var lowerFirst = createCaseFirst('toLowerCase');
13512 * Pads `string` on the left and right sides if it's shorter than `length`.
13513 * Padding characters are truncated if they can't be evenly divided by `length`.
13519 * @param {string} [string=''] The string to pad.
13520 * @param {number} [length=0] The padding length.
13521 * @param {string} [chars=' '] The string used as padding.
13522 * @returns {string} Returns the padded string.
13528 * _.pad('abc', 8, '_-');
13534 function pad(string, length, chars) {
13535 string = toString(string);
13536 length = toInteger(length);
13538 var strLength = length ? stringSize(string) : 0;
13539 if (!length || strLength >= length) {
13542 var mid = (length - strLength) / 2;
13544 createPadding(nativeFloor(mid), chars) +
13546 createPadding(nativeCeil(mid), chars)
13551 * Pads `string` on the right side if it's shorter than `length`. Padding
13552 * characters are truncated if they exceed `length`.
13558 * @param {string} [string=''] The string to pad.
13559 * @param {number} [length=0] The padding length.
13560 * @param {string} [chars=' '] The string used as padding.
13561 * @returns {string} Returns the padded string.
13564 * _.padEnd('abc', 6);
13567 * _.padEnd('abc', 6, '_-');
13570 * _.padEnd('abc', 3);
13573 function padEnd(string, length, chars) {
13574 string = toString(string);
13575 length = toInteger(length);
13577 var strLength = length ? stringSize(string) : 0;
13578 return (length && strLength < length)
13579 ? (string + createPadding(length - strLength, chars))
13584 * Pads `string` on the left side if it's shorter than `length`. Padding
13585 * characters are truncated if they exceed `length`.
13591 * @param {string} [string=''] The string to pad.
13592 * @param {number} [length=0] The padding length.
13593 * @param {string} [chars=' '] The string used as padding.
13594 * @returns {string} Returns the padded string.
13597 * _.padStart('abc', 6);
13600 * _.padStart('abc', 6, '_-');
13603 * _.padStart('abc', 3);
13606 function padStart(string, length, chars) {
13607 string = toString(string);
13608 length = toInteger(length);
13610 var strLength = length ? stringSize(string) : 0;
13611 return (length && strLength < length)
13612 ? (createPadding(length - strLength, chars) + string)
13617 * Converts `string` to an integer of the specified radix. If `radix` is
13618 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
13619 * hexadecimal, in which case a `radix` of `16` is used.
13621 * **Note:** This method aligns with the
13622 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
13628 * @param {string} string The string to convert.
13629 * @param {number} [radix=10] The radix to interpret `value` by.
13630 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
13631 * @returns {number} Returns the converted integer.
13634 * _.parseInt('08');
13637 * _.map(['6', '08', '10'], _.parseInt);
13640 function parseInt(string, radix, guard) {
13641 // Chrome fails to trim leading <BOM> whitespace characters.
13642 // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details.
13643 if (guard || radix == null) {
13645 } else if (radix) {
13648 string = toString(string).replace(reTrim, '');
13649 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
13653 * Repeats the given string `n` times.
13659 * @param {string} [string=''] The string to repeat.
13660 * @param {number} [n=1] The number of times to repeat the string.
13661 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
13662 * @returns {string} Returns the repeated string.
13665 * _.repeat('*', 3);
13668 * _.repeat('abc', 2);
13671 * _.repeat('abc', 0);
13674 function repeat(string, n, guard) {
13675 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
13680 return baseRepeat(toString(string), n);
13684 * Replaces matches for `pattern` in `string` with `replacement`.
13686 * **Note:** This method is based on
13687 * [`String#replace`](https://mdn.io/String/replace).
13693 * @param {string} [string=''] The string to modify.
13694 * @param {RegExp|string} pattern The pattern to replace.
13695 * @param {Function|string} replacement The match replacement.
13696 * @returns {string} Returns the modified string.
13699 * _.replace('Hi Fred', 'Fred', 'Barney');
13700 * // => 'Hi Barney'
13702 function replace() {
13703 var args = arguments,
13704 string = toString(args[0]);
13706 return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]);
13710 * Converts `string` to
13711 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
13717 * @param {string} [string=''] The string to convert.
13718 * @returns {string} Returns the snake cased string.
13721 * _.snakeCase('Foo Bar');
13724 * _.snakeCase('fooBar');
13727 * _.snakeCase('--FOO-BAR--');
13730 var snakeCase = createCompounder(function(result, word, index) {
13731 return result + (index ? '_' : '') + word.toLowerCase();
13735 * Splits `string` by `separator`.
13737 * **Note:** This method is based on
13738 * [`String#split`](https://mdn.io/String/split).
13744 * @param {string} [string=''] The string to split.
13745 * @param {RegExp|string} separator The separator pattern to split by.
13746 * @param {number} [limit] The length to truncate results to.
13747 * @returns {Array} Returns the new array of string segments.
13750 * _.split('a-b-c', '-', 2);
13753 function split(string, separator, limit) {
13754 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
13755 separator = limit = undefined;
13757 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
13761 string = toString(string);
13763 typeof separator == 'string' ||
13764 (separator != null && !isRegExp(separator))
13766 separator = baseToString(separator);
13767 if (separator == '' && reHasComplexSymbol.test(string)) {
13768 return castSlice(stringToArray(string), 0, limit);
13771 return nativeSplit.call(string, separator, limit);
13775 * Converts `string` to
13776 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
13782 * @param {string} [string=''] The string to convert.
13783 * @returns {string} Returns the start cased string.
13786 * _.startCase('--foo-bar--');
13789 * _.startCase('fooBar');
13792 * _.startCase('__FOO_BAR__');
13795 var startCase = createCompounder(function(result, word, index) {
13796 return result + (index ? ' ' : '') + upperFirst(word);
13800 * Checks if `string` starts with the given target string.
13806 * @param {string} [string=''] The string to search.
13807 * @param {string} [target] The string to search for.
13808 * @param {number} [position=0] The position to search from.
13809 * @returns {boolean} Returns `true` if `string` starts with `target`,
13813 * _.startsWith('abc', 'a');
13816 * _.startsWith('abc', 'b');
13819 * _.startsWith('abc', 'b', 1);
13822 function startsWith(string, target, position) {
13823 string = toString(string);
13824 position = baseClamp(toInteger(position), 0, string.length);
13825 return string.lastIndexOf(baseToString(target), position) == position;
13829 * Creates a compiled template function that can interpolate data properties
13830 * in "interpolate" delimiters, HTML-escape interpolated data properties in
13831 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
13832 * properties may be accessed as free variables in the template. If a setting
13833 * object is given, it takes precedence over `_.templateSettings` values.
13835 * **Note:** In the development build `_.template` utilizes
13836 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
13837 * for easier debugging.
13839 * For more information on precompiling templates see
13840 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
13842 * For more information on Chrome extension sandboxes see
13843 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
13849 * @param {string} [string=''] The template string.
13850 * @param {Object} [options={}] The options object.
13851 * @param {RegExp} [options.escape=_.templateSettings.escape]
13852 * The HTML "escape" delimiter.
13853 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
13854 * The "evaluate" delimiter.
13855 * @param {Object} [options.imports=_.templateSettings.imports]
13856 * An object to import into the template as free variables.
13857 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
13858 * The "interpolate" delimiter.
13859 * @param {string} [options.sourceURL='lodash.templateSources[n]']
13860 * The sourceURL of the compiled template.
13861 * @param {string} [options.variable='obj']
13862 * The data object variable name.
13863 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
13864 * @returns {Function} Returns the compiled template function.
13867 * // Use the "interpolate" delimiter to create a compiled template.
13868 * var compiled = _.template('hello <%= user %>!');
13869 * compiled({ 'user': 'fred' });
13870 * // => 'hello fred!'
13872 * // Use the HTML "escape" delimiter to escape data property values.
13873 * var compiled = _.template('<b><%- value %></b>');
13874 * compiled({ 'value': '<script>' });
13875 * // => '<b><script></b>'
13877 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
13878 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
13879 * compiled({ 'users': ['fred', 'barney'] });
13880 * // => '<li>fred</li><li>barney</li>'
13882 * // Use the internal `print` function in "evaluate" delimiters.
13883 * var compiled = _.template('<% print("hello " + user); %>!');
13884 * compiled({ 'user': 'barney' });
13885 * // => 'hello barney!'
13887 * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
13888 * var compiled = _.template('hello ${ user }!');
13889 * compiled({ 'user': 'pebbles' });
13890 * // => 'hello pebbles!'
13892 * // Use custom template delimiters.
13893 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
13894 * var compiled = _.template('hello {{ user }}!');
13895 * compiled({ 'user': 'mustache' });
13896 * // => 'hello mustache!'
13898 * // Use backslashes to treat delimiters as plain text.
13899 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
13900 * compiled({ 'value': 'ignored' });
13901 * // => '<%- value %>'
13903 * // Use the `imports` option to import `jQuery` as `jq`.
13904 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
13905 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
13906 * compiled({ 'users': ['fred', 'barney'] });
13907 * // => '<li>fred</li><li>barney</li>'
13909 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
13910 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
13912 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
13914 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
13915 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
13917 * // => function(data) {
13918 * // var __t, __p = '';
13919 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
13923 * // Use the `source` property to inline compiled templates for meaningful
13924 * // line numbers in error messages and stack traces.
13925 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
13927 * "main": ' + _.template(mainText).source + '\
13931 function template(string, options, guard) {
13932 // Based on John Resig's `tmpl` implementation
13933 // (http://ejohn.org/blog/javascript-micro-templating/)
13934 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
13935 var settings = lodash.templateSettings;
13937 if (guard && isIterateeCall(string, options, guard)) {
13938 options = undefined;
13940 string = toString(string);
13941 options = assignInWith({}, options, settings, assignInDefaults);
13943 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
13944 importsKeys = keys(imports),
13945 importsValues = baseValues(imports, importsKeys);
13950 interpolate = options.interpolate || reNoMatch,
13951 source = "__p += '";
13953 // Compile the regexp to match each delimiter.
13954 var reDelimiters = RegExp(
13955 (options.escape || reNoMatch).source + '|' +
13956 interpolate.source + '|' +
13957 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
13958 (options.evaluate || reNoMatch).source + '|$'
13961 // Use a sourceURL for easier debugging.
13962 var sourceURL = '//# sourceURL=' +
13963 ('sourceURL' in options
13964 ? options.sourceURL
13965 : ('lodash.templateSources[' + (++templateCounter) + ']')
13968 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
13969 interpolateValue || (interpolateValue = esTemplateValue);
13971 // Escape characters that can't be included in string literals.
13972 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
13974 // Replace delimiters with snippets.
13977 source += "' +\n__e(" + escapeValue + ") +\n'";
13979 if (evaluateValue) {
13980 isEvaluating = true;
13981 source += "';\n" + evaluateValue + ";\n__p += '";
13983 if (interpolateValue) {
13984 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
13986 index = offset + match.length;
13988 // The JS engine embedded in Adobe products needs `match` returned in
13989 // order to produce the correct `offset` value.
13995 // If `variable` is not specified wrap a with-statement around the generated
13996 // code to add the data object to the top of the scope chain.
13997 var variable = options.variable;
13999 source = 'with (obj) {\n' + source + '\n}\n';
14001 // Cleanup code by stripping empty strings.
14002 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14003 .replace(reEmptyStringMiddle, '$1')
14004 .replace(reEmptyStringTrailing, '$1;');
14006 // Frame code as the function body.
14007 source = 'function(' + (variable || 'obj') + ') {\n' +
14010 : 'obj || (obj = {});\n'
14012 "var __t, __p = ''" +
14014 ? ', __e = _.escape'
14018 ? ', __j = Array.prototype.join;\n' +
14019 "function print() { __p += __j.call(arguments, '') }\n"
14025 var result = attempt(function() {
14026 return Function(importsKeys, sourceURL + 'return ' + source)
14027 .apply(undefined, importsValues);
14030 // Provide the compiled function's source by its `toString` method or
14031 // the `source` property as a convenience for inlining compiled templates.
14032 result.source = source;
14033 if (isError(result)) {
14040 * Converts `string`, as a whole, to lower case just like
14041 * [String#toLowerCase](https://mdn.io/toLowerCase).
14047 * @param {string} [string=''] The string to convert.
14048 * @returns {string} Returns the lower cased string.
14051 * _.toLower('--Foo-Bar--');
14052 * // => '--foo-bar--'
14054 * _.toLower('fooBar');
14057 * _.toLower('__FOO_BAR__');
14058 * // => '__foo_bar__'
14060 function toLower(value) {
14061 return toString(value).toLowerCase();
14065 * Converts `string`, as a whole, to upper case just like
14066 * [String#toUpperCase](https://mdn.io/toUpperCase).
14072 * @param {string} [string=''] The string to convert.
14073 * @returns {string} Returns the upper cased string.
14076 * _.toUpper('--foo-bar--');
14077 * // => '--FOO-BAR--'
14079 * _.toUpper('fooBar');
14082 * _.toUpper('__foo_bar__');
14083 * // => '__FOO_BAR__'
14085 function toUpper(value) {
14086 return toString(value).toUpperCase();
14090 * Removes leading and trailing whitespace or specified characters from `string`.
14096 * @param {string} [string=''] The string to trim.
14097 * @param {string} [chars=whitespace] The characters to trim.
14098 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14099 * @returns {string} Returns the trimmed string.
14105 * _.trim('-_-abc-_-', '_-');
14108 * _.map([' foo ', ' bar '], _.trim);
14109 * // => ['foo', 'bar']
14111 function trim(string, chars, guard) {
14112 string = toString(string);
14113 if (string && (guard || chars === undefined)) {
14114 return string.replace(reTrim, '');
14116 if (!string || !(chars = baseToString(chars))) {
14119 var strSymbols = stringToArray(string),
14120 chrSymbols = stringToArray(chars),
14121 start = charsStartIndex(strSymbols, chrSymbols),
14122 end = charsEndIndex(strSymbols, chrSymbols) + 1;
14124 return castSlice(strSymbols, start, end).join('');
14128 * Removes trailing whitespace or specified characters from `string`.
14134 * @param {string} [string=''] The string to trim.
14135 * @param {string} [chars=whitespace] The characters to trim.
14136 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14137 * @returns {string} Returns the trimmed string.
14140 * _.trimEnd(' abc ');
14143 * _.trimEnd('-_-abc-_-', '_-');
14146 function trimEnd(string, chars, guard) {
14147 string = toString(string);
14148 if (string && (guard || chars === undefined)) {
14149 return string.replace(reTrimEnd, '');
14151 if (!string || !(chars = baseToString(chars))) {
14154 var strSymbols = stringToArray(string),
14155 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
14157 return castSlice(strSymbols, 0, end).join('');
14161 * Removes leading whitespace or specified characters from `string`.
14167 * @param {string} [string=''] The string to trim.
14168 * @param {string} [chars=whitespace] The characters to trim.
14169 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14170 * @returns {string} Returns the trimmed string.
14173 * _.trimStart(' abc ');
14176 * _.trimStart('-_-abc-_-', '_-');
14179 function trimStart(string, chars, guard) {
14180 string = toString(string);
14181 if (string && (guard || chars === undefined)) {
14182 return string.replace(reTrimStart, '');
14184 if (!string || !(chars = baseToString(chars))) {
14187 var strSymbols = stringToArray(string),
14188 start = charsStartIndex(strSymbols, stringToArray(chars));
14190 return castSlice(strSymbols, start).join('');
14194 * Truncates `string` if it's longer than the given maximum string length.
14195 * The last characters of the truncated string are replaced with the omission
14196 * string which defaults to "...".
14202 * @param {string} [string=''] The string to truncate.
14203 * @param {Object} [options={}] The options object.
14204 * @param {number} [options.length=30] The maximum string length.
14205 * @param {string} [options.omission='...'] The string to indicate text is omitted.
14206 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
14207 * @returns {string} Returns the truncated string.
14210 * _.truncate('hi-diddly-ho there, neighborino');
14211 * // => 'hi-diddly-ho there, neighbo...'
14213 * _.truncate('hi-diddly-ho there, neighborino', {
14217 * // => 'hi-diddly-ho there,...'
14219 * _.truncate('hi-diddly-ho there, neighborino', {
14221 * 'separator': /,? +/
14223 * // => 'hi-diddly-ho there...'
14225 * _.truncate('hi-diddly-ho there, neighborino', {
14226 * 'omission': ' [...]'
14228 * // => 'hi-diddly-ho there, neig [...]'
14230 function truncate(string, options) {
14231 var length = DEFAULT_TRUNC_LENGTH,
14232 omission = DEFAULT_TRUNC_OMISSION;
14234 if (isObject(options)) {
14235 var separator = 'separator' in options ? options.separator : separator;
14236 length = 'length' in options ? toInteger(options.length) : length;
14237 omission = 'omission' in options ? baseToString(options.omission) : omission;
14239 string = toString(string);
14241 var strLength = string.length;
14242 if (reHasComplexSymbol.test(string)) {
14243 var strSymbols = stringToArray(string);
14244 strLength = strSymbols.length;
14246 if (length >= strLength) {
14249 var end = length - stringSize(omission);
14253 var result = strSymbols
14254 ? castSlice(strSymbols, 0, end).join('')
14255 : string.slice(0, end);
14257 if (separator === undefined) {
14258 return result + omission;
14261 end += (result.length - end);
14263 if (isRegExp(separator)) {
14264 if (string.slice(end).search(separator)) {
14266 substring = result;
14268 if (!separator.global) {
14269 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
14271 separator.lastIndex = 0;
14272 while ((match = separator.exec(substring))) {
14273 var newEnd = match.index;
14275 result = result.slice(0, newEnd === undefined ? end : newEnd);
14277 } else if (string.indexOf(baseToString(separator), end) != end) {
14278 var index = result.lastIndexOf(separator);
14280 result = result.slice(0, index);
14283 return result + omission;
14287 * The inverse of `_.escape`; this method converts the HTML entities
14288 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to
14289 * their corresponding characters.
14291 * **Note:** No other HTML entities are unescaped. To unescape additional
14292 * HTML entities use a third-party library like [_he_](https://mths.be/he).
14298 * @param {string} [string=''] The string to unescape.
14299 * @returns {string} Returns the unescaped string.
14302 * _.unescape('fred, barney, & pebbles');
14303 * // => 'fred, barney, & pebbles'
14305 function unescape(string) {
14306 string = toString(string);
14307 return (string && reHasEscapedHtml.test(string))
14308 ? string.replace(reEscapedHtml, unescapeHtmlChar)
14313 * Converts `string`, as space separated words, to upper case.
14319 * @param {string} [string=''] The string to convert.
14320 * @returns {string} Returns the upper cased string.
14323 * _.upperCase('--foo-bar');
14326 * _.upperCase('fooBar');
14329 * _.upperCase('__foo_bar__');
14332 var upperCase = createCompounder(function(result, word, index) {
14333 return result + (index ? ' ' : '') + word.toUpperCase();
14337 * Converts the first character of `string` to upper case.
14343 * @param {string} [string=''] The string to convert.
14344 * @returns {string} Returns the converted string.
14347 * _.upperFirst('fred');
14350 * _.upperFirst('FRED');
14353 var upperFirst = createCaseFirst('toUpperCase');
14356 * Splits `string` into an array of its words.
14362 * @param {string} [string=''] The string to inspect.
14363 * @param {RegExp|string} [pattern] The pattern to match words.
14364 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14365 * @returns {Array} Returns the words of `string`.
14368 * _.words('fred, barney, & pebbles');
14369 * // => ['fred', 'barney', 'pebbles']
14371 * _.words('fred, barney, & pebbles', /[^, ]+/g);
14372 * // => ['fred', 'barney', '&', 'pebbles']
14374 function words(string, pattern, guard) {
14375 string = toString(string);
14376 pattern = guard ? undefined : pattern;
14378 if (pattern === undefined) {
14379 pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
14381 return string.match(pattern) || [];
14384 /*------------------------------------------------------------------------*/
14387 * Attempts to invoke `func`, returning either the result or the caught error
14388 * object. Any additional arguments are provided to `func` when it's invoked.
14394 * @param {Function} func The function to attempt.
14395 * @param {...*} [args] The arguments to invoke `func` with.
14396 * @returns {*} Returns the `func` result or error object.
14399 * // Avoid throwing errors for invalid selectors.
14400 * var elements = _.attempt(function(selector) {
14401 * return document.querySelectorAll(selector);
14404 * if (_.isError(elements)) {
14408 var attempt = rest(function(func, args) {
14410 return apply(func, undefined, args);
14412 return isError(e) ? e : new Error(e);
14417 * Binds methods of an object to the object itself, overwriting the existing
14420 * **Note:** This method doesn't set the "length" property of bound functions.
14426 * @param {Object} object The object to bind and assign the bound methods to.
14427 * @param {...(string|string[])} methodNames The object method names to bind.
14428 * @returns {Object} Returns `object`.
14433 * 'onClick': function() {
14434 * console.log('clicked ' + this.label);
14438 * _.bindAll(view, 'onClick');
14439 * jQuery(element).on('click', view.onClick);
14440 * // => Logs 'clicked docs' when clicked.
14442 var bindAll = rest(function(object, methodNames) {
14443 arrayEach(baseFlatten(methodNames, 1), function(key) {
14445 object[key] = bind(object[key], object);
14451 * Creates a function that iterates over `pairs` and invokes the corresponding
14452 * function of the first predicate to return truthy. The predicate-function
14453 * pairs are invoked with the `this` binding and arguments of the created
14460 * @param {Array} pairs The predicate-function pairs.
14461 * @returns {Function} Returns the new function.
14464 * var func = _.cond([
14465 * [_.matches({ 'a': 1 }), _.constant('matches A')],
14466 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
14467 * [_.constant(true), _.constant('no match')]
14470 * func({ 'a': 1, 'b': 2 });
14471 * // => 'matches A'
14473 * func({ 'a': 0, 'b': 1 });
14474 * // => 'matches B'
14476 * func({ 'a': '1', 'b': '2' });
14479 function cond(pairs) {
14480 var length = pairs ? pairs.length : 0,
14481 toIteratee = getIteratee();
14483 pairs = !length ? [] : arrayMap(pairs, function(pair) {
14484 if (typeof pair[1] != 'function') {
14485 throw new TypeError(FUNC_ERROR_TEXT);
14487 return [toIteratee(pair[0]), pair[1]];
14490 return rest(function(args) {
14492 while (++index < length) {
14493 var pair = pairs[index];
14494 if (apply(pair[0], this, args)) {
14495 return apply(pair[1], this, args);
14502 * Creates a function that invokes the predicate properties of `source` with
14503 * the corresponding property values of a given object, returning `true` if
14504 * all predicates return truthy, else `false`.
14510 * @param {Object} source The object of property predicates to conform to.
14511 * @returns {Function} Returns the new function.
14515 * { 'user': 'barney', 'age': 36 },
14516 * { 'user': 'fred', 'age': 40 }
14519 * _.filter(users, _.conforms({ 'age': _.partial(_.gt, _, 38) }));
14520 * // => [{ 'user': 'fred', 'age': 40 }]
14522 function conforms(source) {
14523 return baseConforms(baseClone(source, true));
14527 * Creates a function that returns `value`.
14533 * @param {*} value The value to return from the new function.
14534 * @returns {Function} Returns the new function.
14537 * var object = { 'user': 'fred' };
14538 * var getter = _.constant(object);
14540 * getter() === object;
14543 function constant(value) {
14544 return function() {
14550 * Creates a function that returns the result of invoking the given functions
14551 * with the `this` binding of the created function, where each successive
14552 * invocation is supplied the return value of the previous.
14558 * @param {...(Function|Function[])} [funcs] Functions to invoke.
14559 * @returns {Function} Returns the new function.
14563 * function square(n) {
14567 * var addSquare = _.flow(_.add, square);
14571 var flow = createFlow();
14574 * This method is like `_.flow` except that it creates a function that
14575 * invokes the given functions from right to left.
14581 * @param {...(Function|Function[])} [funcs] Functions to invoke.
14582 * @returns {Function} Returns the new function.
14586 * function square(n) {
14590 * var addSquare = _.flowRight(square, _.add);
14594 var flowRight = createFlow(true);
14597 * This method returns the first argument given to it.
14603 * @param {*} value Any value.
14604 * @returns {*} Returns `value`.
14607 * var object = { 'user': 'fred' };
14609 * _.identity(object) === object;
14612 function identity(value) {
14617 * Creates a function that invokes `func` with the arguments of the created
14618 * function. If `func` is a property name, the created function returns the
14619 * property value for a given element. If `func` is an array or object, the
14620 * created function returns `true` for elements that contain the equivalent
14621 * source properties, otherwise it returns `false`.
14627 * @param {*} [func=_.identity] The value to convert to a callback.
14628 * @returns {Function} Returns the callback.
14632 * { 'user': 'barney', 'age': 36, 'active': true },
14633 * { 'user': 'fred', 'age': 40, 'active': false }
14636 * // The `_.matches` iteratee shorthand.
14637 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
14638 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
14640 * // The `_.matchesProperty` iteratee shorthand.
14641 * _.filter(users, _.iteratee(['user', 'fred']));
14642 * // => [{ 'user': 'fred', 'age': 40 }]
14644 * // The `_.property` iteratee shorthand.
14645 * _.map(users, _.iteratee('user'));
14646 * // => ['barney', 'fred']
14648 * // Create custom iteratee shorthands.
14649 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
14650 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
14651 * return func.test(string);
14655 * _.filter(['abc', 'def'], /ef/);
14658 function iteratee(func) {
14659 return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
14663 * Creates a function that performs a partial deep comparison between a given
14664 * object and `source`, returning `true` if the given object has equivalent
14665 * property values, else `false`. The created function is equivalent to
14666 * `_.isMatch` with a `source` partially applied.
14668 * **Note:** This method supports comparing the same values as `_.isEqual`.
14674 * @param {Object} source The object of property values to match.
14675 * @returns {Function} Returns the new function.
14679 * { 'user': 'barney', 'age': 36, 'active': true },
14680 * { 'user': 'fred', 'age': 40, 'active': false }
14683 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
14684 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
14686 function matches(source) {
14687 return baseMatches(baseClone(source, true));
14691 * Creates a function that performs a partial deep comparison between the
14692 * value at `path` of a given object to `srcValue`, returning `true` if the
14693 * object value is equivalent, else `false`.
14695 * **Note:** This method supports comparing the same values as `_.isEqual`.
14701 * @param {Array|string} path The path of the property to get.
14702 * @param {*} srcValue The value to match.
14703 * @returns {Function} Returns the new function.
14707 * { 'user': 'barney' },
14708 * { 'user': 'fred' }
14711 * _.find(users, _.matchesProperty('user', 'fred'));
14712 * // => { 'user': 'fred' }
14714 function matchesProperty(path, srcValue) {
14715 return baseMatchesProperty(path, baseClone(srcValue, true));
14719 * Creates a function that invokes the method at `path` of a given object.
14720 * Any additional arguments are provided to the invoked method.
14726 * @param {Array|string} path The path of the method to invoke.
14727 * @param {...*} [args] The arguments to invoke the method with.
14728 * @returns {Function} Returns the new function.
14732 * { 'a': { 'b': _.constant(2) } },
14733 * { 'a': { 'b': _.constant(1) } }
14736 * _.map(objects, _.method('a.b'));
14739 * _.map(objects, _.method(['a', 'b']));
14742 var method = rest(function(path, args) {
14743 return function(object) {
14744 return baseInvoke(object, path, args);
14749 * The opposite of `_.method`; this method creates a function that invokes
14750 * the method at a given path of `object`. Any additional arguments are
14751 * provided to the invoked method.
14757 * @param {Object} object The object to query.
14758 * @param {...*} [args] The arguments to invoke the method with.
14759 * @returns {Function} Returns the new function.
14762 * var array = _.times(3, _.constant),
14763 * object = { 'a': array, 'b': array, 'c': array };
14765 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
14768 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
14771 var methodOf = rest(function(object, args) {
14772 return function(path) {
14773 return baseInvoke(object, path, args);
14778 * Adds all own enumerable string keyed function properties of a source
14779 * object to the destination object. If `object` is a function, then methods
14780 * are added to its prototype as well.
14782 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
14783 * avoid conflicts caused by modifying the original.
14789 * @param {Function|Object} [object=lodash] The destination object.
14790 * @param {Object} source The object of functions to add.
14791 * @param {Object} [options={}] The options object.
14792 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
14793 * @returns {Function|Object} Returns `object`.
14796 * function vowels(string) {
14797 * return _.filter(string, function(v) {
14798 * return /[aeiou]/i.test(v);
14802 * _.mixin({ 'vowels': vowels });
14803 * _.vowels('fred');
14806 * _('fred').vowels().value();
14809 * _.mixin({ 'vowels': vowels }, { 'chain': false });
14810 * _('fred').vowels();
14813 function mixin(object, source, options) {
14814 var props = keys(source),
14815 methodNames = baseFunctions(source, props);
14817 if (options == null &&
14818 !(isObject(source) && (methodNames.length || !props.length))) {
14822 methodNames = baseFunctions(source, keys(source));
14824 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
14825 isFunc = isFunction(object);
14827 arrayEach(methodNames, function(methodName) {
14828 var func = source[methodName];
14829 object[methodName] = func;
14831 object.prototype[methodName] = function() {
14832 var chainAll = this.__chain__;
14833 if (chain || chainAll) {
14834 var result = object(this.__wrapped__),
14835 actions = result.__actions__ = copyArray(this.__actions__);
14837 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
14838 result.__chain__ = chainAll;
14841 return func.apply(object, arrayPush([this.value()], arguments));
14850 * Reverts the `_` variable to its previous value and returns a reference to
14851 * the `lodash` function.
14857 * @returns {Function} Returns the `lodash` function.
14860 * var lodash = _.noConflict();
14862 function noConflict() {
14863 if (root._ === this) {
14870 * A no-operation function that returns `undefined` regardless of the
14871 * arguments it receives.
14879 * var object = { 'user': 'fred' };
14881 * _.noop(object) === undefined;
14885 // No operation performed.
14889 * Creates a function that returns its nth argument. If `n` is negative,
14890 * the nth argument from the end is returned.
14896 * @param {number} [n=0] The index of the argument to return.
14897 * @returns {Function} Returns the new function.
14900 * var func = _.nthArg(1);
14901 * func('a', 'b', 'c', 'd');
14904 * var func = _.nthArg(-2);
14905 * func('a', 'b', 'c', 'd');
14908 function nthArg(n) {
14910 return rest(function(args) {
14911 return baseNth(args, n);
14916 * Creates a function that invokes `iteratees` with the arguments it receives
14917 * and returns their results.
14923 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
14924 * [iteratees=[_.identity]] The iteratees to invoke.
14925 * @returns {Function} Returns the new function.
14928 * var func = _.over(Math.max, Math.min);
14930 * func(1, 2, 3, 4);
14933 var over = createOver(arrayMap);
14936 * Creates a function that checks if **all** of the `predicates` return
14937 * truthy when invoked with the arguments it receives.
14943 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
14944 * [predicates=[_.identity]] The predicates to check.
14945 * @returns {Function} Returns the new function.
14948 * var func = _.overEvery(Boolean, isFinite);
14959 var overEvery = createOver(arrayEvery);
14962 * Creates a function that checks if **any** of the `predicates` return
14963 * truthy when invoked with the arguments it receives.
14969 * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])}
14970 * [predicates=[_.identity]] The predicates to check.
14971 * @returns {Function} Returns the new function.
14974 * var func = _.overSome(Boolean, isFinite);
14985 var overSome = createOver(arraySome);
14988 * Creates a function that returns the value at `path` of a given object.
14994 * @param {Array|string} path The path of the property to get.
14995 * @returns {Function} Returns the new function.
14999 * { 'a': { 'b': 2 } },
15000 * { 'a': { 'b': 1 } }
15003 * _.map(objects, _.property('a.b'));
15006 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
15009 function property(path) {
15010 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
15014 * The opposite of `_.property`; this method creates a function that returns
15015 * the value at a given path of `object`.
15021 * @param {Object} object The object to query.
15022 * @returns {Function} Returns the new function.
15025 * var array = [0, 1, 2],
15026 * object = { 'a': array, 'b': array, 'c': array };
15028 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
15031 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
15034 function propertyOf(object) {
15035 return function(path) {
15036 return object == null ? undefined : baseGet(object, path);
15041 * Creates an array of numbers (positive and/or negative) progressing from
15042 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
15043 * `start` is specified without an `end` or `step`. If `end` is not specified,
15044 * it's set to `start` with `start` then set to `0`.
15046 * **Note:** JavaScript follows the IEEE-754 standard for resolving
15047 * floating-point values which can produce unexpected results.
15053 * @param {number} [start=0] The start of the range.
15054 * @param {number} end The end of the range.
15055 * @param {number} [step=1] The value to increment or decrement by.
15056 * @returns {Array} Returns the new array of numbers.
15057 * @see _.inRange, _.rangeRight
15061 * // => [0, 1, 2, 3]
15064 * // => [0, -1, -2, -3]
15067 * // => [1, 2, 3, 4]
15069 * _.range(0, 20, 5);
15070 * // => [0, 5, 10, 15]
15072 * _.range(0, -4, -1);
15073 * // => [0, -1, -2, -3]
15075 * _.range(1, 4, 0);
15081 var range = createRange();
15084 * This method is like `_.range` except that it populates values in
15085 * descending order.
15091 * @param {number} [start=0] The start of the range.
15092 * @param {number} end The end of the range.
15093 * @param {number} [step=1] The value to increment or decrement by.
15094 * @returns {Array} Returns the new array of numbers.
15095 * @see _.inRange, _.range
15099 * // => [3, 2, 1, 0]
15101 * _.rangeRight(-4);
15102 * // => [-3, -2, -1, 0]
15104 * _.rangeRight(1, 5);
15105 * // => [4, 3, 2, 1]
15107 * _.rangeRight(0, 20, 5);
15108 * // => [15, 10, 5, 0]
15110 * _.rangeRight(0, -4, -1);
15111 * // => [-3, -2, -1, 0]
15113 * _.rangeRight(1, 4, 0);
15119 var rangeRight = createRange(true);
15122 * Invokes the iteratee `n` times, returning an array of the results of
15123 * each invocation. The iteratee is invoked with one argument; (index).
15129 * @param {number} n The number of times to invoke `iteratee`.
15130 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
15131 * @returns {Array} Returns the array of results.
15134 * _.times(3, String);
15135 * // => ['0', '1', '2']
15137 * _.times(4, _.constant(true));
15138 * // => [true, true, true, true]
15140 function times(n, iteratee) {
15142 if (n < 1 || n > MAX_SAFE_INTEGER) {
15145 var index = MAX_ARRAY_LENGTH,
15146 length = nativeMin(n, MAX_ARRAY_LENGTH);
15148 iteratee = getIteratee(iteratee);
15149 n -= MAX_ARRAY_LENGTH;
15151 var result = baseTimes(length, iteratee);
15152 while (++index < n) {
15159 * Converts `value` to a property path array.
15165 * @param {*} value The value to convert.
15166 * @returns {Array} Returns the new property path array.
15169 * _.toPath('a.b.c');
15170 * // => ['a', 'b', 'c']
15172 * _.toPath('a[0].b.c');
15173 * // => ['a', '0', 'b', 'c']
15175 * var path = ['a', 'b', 'c'],
15176 * newPath = _.toPath(path);
15178 * console.log(newPath);
15179 * // => ['a', 'b', 'c']
15181 * console.log(path === newPath);
15184 function toPath(value) {
15185 if (isArray(value)) {
15186 return arrayMap(value, toKey);
15188 return isSymbol(value) ? [value] : copyArray(stringToPath(value));
15192 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
15198 * @param {string} [prefix=''] The value to prefix the ID with.
15199 * @returns {string} Returns the unique ID.
15202 * _.uniqueId('contact_');
15203 * // => 'contact_104'
15208 function uniqueId(prefix) {
15209 var id = ++idCounter;
15210 return toString(prefix) + id;
15213 /*------------------------------------------------------------------------*/
15216 * Adds two numbers.
15222 * @param {number} augend The first number in an addition.
15223 * @param {number} addend The second number in an addition.
15224 * @returns {number} Returns the total.
15230 var add = createMathOperation(function(augend, addend) {
15231 return augend + addend;
15235 * Computes `number` rounded up to `precision`.
15241 * @param {number} number The number to round up.
15242 * @param {number} [precision=0] The precision to round up to.
15243 * @returns {number} Returns the rounded up number.
15249 * _.ceil(6.004, 2);
15252 * _.ceil(6040, -2);
15255 var ceil = createRound('ceil');
15258 * Divide two numbers.
15264 * @param {number} dividend The first number in a division.
15265 * @param {number} divisor The second number in a division.
15266 * @returns {number} Returns the quotient.
15272 var divide = createMathOperation(function(dividend, divisor) {
15273 return dividend / divisor;
15277 * Computes `number` rounded down to `precision`.
15283 * @param {number} number The number to round down.
15284 * @param {number} [precision=0] The precision to round down to.
15285 * @returns {number} Returns the rounded down number.
15291 * _.floor(0.046, 2);
15294 * _.floor(4060, -2);
15297 var floor = createRound('floor');
15300 * Computes the maximum value of `array`. If `array` is empty or falsey,
15301 * `undefined` is returned.
15307 * @param {Array} array The array to iterate over.
15308 * @returns {*} Returns the maximum value.
15311 * _.max([4, 2, 8, 6]);
15317 function max(array) {
15318 return (array && array.length)
15319 ? baseExtremum(array, identity, baseGt)
15324 * This method is like `_.max` except that it accepts `iteratee` which is
15325 * invoked for each element in `array` to generate the criterion by which
15326 * the value is ranked. The iteratee is invoked with one argument: (value).
15332 * @param {Array} array The array to iterate over.
15333 * @param {Array|Function|Object|string} [iteratee=_.identity]
15334 * The iteratee invoked per element.
15335 * @returns {*} Returns the maximum value.
15338 * var objects = [{ 'n': 1 }, { 'n': 2 }];
15340 * _.maxBy(objects, function(o) { return o.n; });
15343 * // The `_.property` iteratee shorthand.
15344 * _.maxBy(objects, 'n');
15347 function maxBy(array, iteratee) {
15348 return (array && array.length)
15349 ? baseExtremum(array, getIteratee(iteratee), baseGt)
15354 * Computes the mean of the values in `array`.
15360 * @param {Array} array The array to iterate over.
15361 * @returns {number} Returns the mean.
15364 * _.mean([4, 2, 8, 6]);
15367 function mean(array) {
15368 return baseMean(array, identity);
15372 * This method is like `_.mean` except that it accepts `iteratee` which is
15373 * invoked for each element in `array` to generate the value to be averaged.
15374 * The iteratee is invoked with one argument: (value).
15380 * @param {Array} array The array to iterate over.
15381 * @param {Array|Function|Object|string} [iteratee=_.identity]
15382 * The iteratee invoked per element.
15383 * @returns {number} Returns the mean.
15386 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
15388 * _.meanBy(objects, function(o) { return o.n; });
15391 * // The `_.property` iteratee shorthand.
15392 * _.meanBy(objects, 'n');
15395 function meanBy(array, iteratee) {
15396 return baseMean(array, getIteratee(iteratee));
15400 * Computes the minimum value of `array`. If `array` is empty or falsey,
15401 * `undefined` is returned.
15407 * @param {Array} array The array to iterate over.
15408 * @returns {*} Returns the minimum value.
15411 * _.min([4, 2, 8, 6]);
15417 function min(array) {
15418 return (array && array.length)
15419 ? baseExtremum(array, identity, baseLt)
15424 * This method is like `_.min` except that it accepts `iteratee` which is
15425 * invoked for each element in `array` to generate the criterion by which
15426 * the value is ranked. The iteratee is invoked with one argument: (value).
15432 * @param {Array} array The array to iterate over.
15433 * @param {Array|Function|Object|string} [iteratee=_.identity]
15434 * The iteratee invoked per element.
15435 * @returns {*} Returns the minimum value.
15438 * var objects = [{ 'n': 1 }, { 'n': 2 }];
15440 * _.minBy(objects, function(o) { return o.n; });
15443 * // The `_.property` iteratee shorthand.
15444 * _.minBy(objects, 'n');
15447 function minBy(array, iteratee) {
15448 return (array && array.length)
15449 ? baseExtremum(array, getIteratee(iteratee), baseLt)
15454 * Multiply two numbers.
15460 * @param {number} multiplier The first number in a multiplication.
15461 * @param {number} multiplicand The second number in a multiplication.
15462 * @returns {number} Returns the product.
15465 * _.multiply(6, 4);
15468 var multiply = createMathOperation(function(multiplier, multiplicand) {
15469 return multiplier * multiplicand;
15473 * Computes `number` rounded to `precision`.
15479 * @param {number} number The number to round.
15480 * @param {number} [precision=0] The precision to round to.
15481 * @returns {number} Returns the rounded number.
15487 * _.round(4.006, 2);
15490 * _.round(4060, -2);
15493 var round = createRound('round');
15496 * Subtract two numbers.
15502 * @param {number} minuend The first number in a subtraction.
15503 * @param {number} subtrahend The second number in a subtraction.
15504 * @returns {number} Returns the difference.
15507 * _.subtract(6, 4);
15510 var subtract = createMathOperation(function(minuend, subtrahend) {
15511 return minuend - subtrahend;
15515 * Computes the sum of the values in `array`.
15521 * @param {Array} array The array to iterate over.
15522 * @returns {number} Returns the sum.
15525 * _.sum([4, 2, 8, 6]);
15528 function sum(array) {
15529 return (array && array.length)
15530 ? baseSum(array, identity)
15535 * This method is like `_.sum` except that it accepts `iteratee` which is
15536 * invoked for each element in `array` to generate the value to be summed.
15537 * The iteratee is invoked with one argument: (value).
15543 * @param {Array} array The array to iterate over.
15544 * @param {Array|Function|Object|string} [iteratee=_.identity]
15545 * The iteratee invoked per element.
15546 * @returns {number} Returns the sum.
15549 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
15551 * _.sumBy(objects, function(o) { return o.n; });
15554 * // The `_.property` iteratee shorthand.
15555 * _.sumBy(objects, 'n');
15558 function sumBy(array, iteratee) {
15559 return (array && array.length)
15560 ? baseSum(array, getIteratee(iteratee))
15564 /*------------------------------------------------------------------------*/
15566 // Add methods that return wrapped values in chain sequences.
15567 lodash.after = after;
15569 lodash.assign = assign;
15570 lodash.assignIn = assignIn;
15571 lodash.assignInWith = assignInWith;
15572 lodash.assignWith = assignWith;
15574 lodash.before = before;
15575 lodash.bind = bind;
15576 lodash.bindAll = bindAll;
15577 lodash.bindKey = bindKey;
15578 lodash.castArray = castArray;
15579 lodash.chain = chain;
15580 lodash.chunk = chunk;
15581 lodash.compact = compact;
15582 lodash.concat = concat;
15583 lodash.cond = cond;
15584 lodash.conforms = conforms;
15585 lodash.constant = constant;
15586 lodash.countBy = countBy;
15587 lodash.create = create;
15588 lodash.curry = curry;
15589 lodash.curryRight = curryRight;
15590 lodash.debounce = debounce;
15591 lodash.defaults = defaults;
15592 lodash.defaultsDeep = defaultsDeep;
15593 lodash.defer = defer;
15594 lodash.delay = delay;
15595 lodash.difference = difference;
15596 lodash.differenceBy = differenceBy;
15597 lodash.differenceWith = differenceWith;
15598 lodash.drop = drop;
15599 lodash.dropRight = dropRight;
15600 lodash.dropRightWhile = dropRightWhile;
15601 lodash.dropWhile = dropWhile;
15602 lodash.fill = fill;
15603 lodash.filter = filter;
15604 lodash.flatMap = flatMap;
15605 lodash.flatMapDeep = flatMapDeep;
15606 lodash.flatMapDepth = flatMapDepth;
15607 lodash.flatten = flatten;
15608 lodash.flattenDeep = flattenDeep;
15609 lodash.flattenDepth = flattenDepth;
15610 lodash.flip = flip;
15611 lodash.flow = flow;
15612 lodash.flowRight = flowRight;
15613 lodash.fromPairs = fromPairs;
15614 lodash.functions = functions;
15615 lodash.functionsIn = functionsIn;
15616 lodash.groupBy = groupBy;
15617 lodash.initial = initial;
15618 lodash.intersection = intersection;
15619 lodash.intersectionBy = intersectionBy;
15620 lodash.intersectionWith = intersectionWith;
15621 lodash.invert = invert;
15622 lodash.invertBy = invertBy;
15623 lodash.invokeMap = invokeMap;
15624 lodash.iteratee = iteratee;
15625 lodash.keyBy = keyBy;
15626 lodash.keys = keys;
15627 lodash.keysIn = keysIn;
15629 lodash.mapKeys = mapKeys;
15630 lodash.mapValues = mapValues;
15631 lodash.matches = matches;
15632 lodash.matchesProperty = matchesProperty;
15633 lodash.memoize = memoize;
15634 lodash.merge = merge;
15635 lodash.mergeWith = mergeWith;
15636 lodash.method = method;
15637 lodash.methodOf = methodOf;
15638 lodash.mixin = mixin;
15639 lodash.negate = negate;
15640 lodash.nthArg = nthArg;
15641 lodash.omit = omit;
15642 lodash.omitBy = omitBy;
15643 lodash.once = once;
15644 lodash.orderBy = orderBy;
15645 lodash.over = over;
15646 lodash.overArgs = overArgs;
15647 lodash.overEvery = overEvery;
15648 lodash.overSome = overSome;
15649 lodash.partial = partial;
15650 lodash.partialRight = partialRight;
15651 lodash.partition = partition;
15652 lodash.pick = pick;
15653 lodash.pickBy = pickBy;
15654 lodash.property = property;
15655 lodash.propertyOf = propertyOf;
15656 lodash.pull = pull;
15657 lodash.pullAll = pullAll;
15658 lodash.pullAllBy = pullAllBy;
15659 lodash.pullAllWith = pullAllWith;
15660 lodash.pullAt = pullAt;
15661 lodash.range = range;
15662 lodash.rangeRight = rangeRight;
15663 lodash.rearg = rearg;
15664 lodash.reject = reject;
15665 lodash.remove = remove;
15666 lodash.rest = rest;
15667 lodash.reverse = reverse;
15668 lodash.sampleSize = sampleSize;
15670 lodash.setWith = setWith;
15671 lodash.shuffle = shuffle;
15672 lodash.slice = slice;
15673 lodash.sortBy = sortBy;
15674 lodash.sortedUniq = sortedUniq;
15675 lodash.sortedUniqBy = sortedUniqBy;
15676 lodash.split = split;
15677 lodash.spread = spread;
15678 lodash.tail = tail;
15679 lodash.take = take;
15680 lodash.takeRight = takeRight;
15681 lodash.takeRightWhile = takeRightWhile;
15682 lodash.takeWhile = takeWhile;
15684 lodash.throttle = throttle;
15685 lodash.thru = thru;
15686 lodash.toArray = toArray;
15687 lodash.toPairs = toPairs;
15688 lodash.toPairsIn = toPairsIn;
15689 lodash.toPath = toPath;
15690 lodash.toPlainObject = toPlainObject;
15691 lodash.transform = transform;
15692 lodash.unary = unary;
15693 lodash.union = union;
15694 lodash.unionBy = unionBy;
15695 lodash.unionWith = unionWith;
15696 lodash.uniq = uniq;
15697 lodash.uniqBy = uniqBy;
15698 lodash.uniqWith = uniqWith;
15699 lodash.unset = unset;
15700 lodash.unzip = unzip;
15701 lodash.unzipWith = unzipWith;
15702 lodash.update = update;
15703 lodash.updateWith = updateWith;
15704 lodash.values = values;
15705 lodash.valuesIn = valuesIn;
15706 lodash.without = without;
15707 lodash.words = words;
15708 lodash.wrap = wrap;
15710 lodash.xorBy = xorBy;
15711 lodash.xorWith = xorWith;
15713 lodash.zipObject = zipObject;
15714 lodash.zipObjectDeep = zipObjectDeep;
15715 lodash.zipWith = zipWith;
15718 lodash.entries = toPairs;
15719 lodash.entriesIn = toPairsIn;
15720 lodash.extend = assignIn;
15721 lodash.extendWith = assignInWith;
15723 // Add methods to `lodash.prototype`.
15724 mixin(lodash, lodash);
15726 /*------------------------------------------------------------------------*/
15728 // Add methods that return unwrapped values in chain sequences.
15730 lodash.attempt = attempt;
15731 lodash.camelCase = camelCase;
15732 lodash.capitalize = capitalize;
15733 lodash.ceil = ceil;
15734 lodash.clamp = clamp;
15735 lodash.clone = clone;
15736 lodash.cloneDeep = cloneDeep;
15737 lodash.cloneDeepWith = cloneDeepWith;
15738 lodash.cloneWith = cloneWith;
15739 lodash.deburr = deburr;
15740 lodash.divide = divide;
15741 lodash.endsWith = endsWith;
15743 lodash.escape = escape;
15744 lodash.escapeRegExp = escapeRegExp;
15745 lodash.every = every;
15746 lodash.find = find;
15747 lodash.findIndex = findIndex;
15748 lodash.findKey = findKey;
15749 lodash.findLast = findLast;
15750 lodash.findLastIndex = findLastIndex;
15751 lodash.findLastKey = findLastKey;
15752 lodash.floor = floor;
15753 lodash.forEach = forEach;
15754 lodash.forEachRight = forEachRight;
15755 lodash.forIn = forIn;
15756 lodash.forInRight = forInRight;
15757 lodash.forOwn = forOwn;
15758 lodash.forOwnRight = forOwnRight;
15763 lodash.hasIn = hasIn;
15764 lodash.head = head;
15765 lodash.identity = identity;
15766 lodash.includes = includes;
15767 lodash.indexOf = indexOf;
15768 lodash.inRange = inRange;
15769 lodash.invoke = invoke;
15770 lodash.isArguments = isArguments;
15771 lodash.isArray = isArray;
15772 lodash.isArrayBuffer = isArrayBuffer;
15773 lodash.isArrayLike = isArrayLike;
15774 lodash.isArrayLikeObject = isArrayLikeObject;
15775 lodash.isBoolean = isBoolean;
15776 lodash.isBuffer = isBuffer;
15777 lodash.isDate = isDate;
15778 lodash.isElement = isElement;
15779 lodash.isEmpty = isEmpty;
15780 lodash.isEqual = isEqual;
15781 lodash.isEqualWith = isEqualWith;
15782 lodash.isError = isError;
15783 lodash.isFinite = isFinite;
15784 lodash.isFunction = isFunction;
15785 lodash.isInteger = isInteger;
15786 lodash.isLength = isLength;
15787 lodash.isMap = isMap;
15788 lodash.isMatch = isMatch;
15789 lodash.isMatchWith = isMatchWith;
15790 lodash.isNaN = isNaN;
15791 lodash.isNative = isNative;
15792 lodash.isNil = isNil;
15793 lodash.isNull = isNull;
15794 lodash.isNumber = isNumber;
15795 lodash.isObject = isObject;
15796 lodash.isObjectLike = isObjectLike;
15797 lodash.isPlainObject = isPlainObject;
15798 lodash.isRegExp = isRegExp;
15799 lodash.isSafeInteger = isSafeInteger;
15800 lodash.isSet = isSet;
15801 lodash.isString = isString;
15802 lodash.isSymbol = isSymbol;
15803 lodash.isTypedArray = isTypedArray;
15804 lodash.isUndefined = isUndefined;
15805 lodash.isWeakMap = isWeakMap;
15806 lodash.isWeakSet = isWeakSet;
15807 lodash.join = join;
15808 lodash.kebabCase = kebabCase;
15809 lodash.last = last;
15810 lodash.lastIndexOf = lastIndexOf;
15811 lodash.lowerCase = lowerCase;
15812 lodash.lowerFirst = lowerFirst;
15816 lodash.maxBy = maxBy;
15817 lodash.mean = mean;
15818 lodash.meanBy = meanBy;
15820 lodash.minBy = minBy;
15821 lodash.multiply = multiply;
15823 lodash.noConflict = noConflict;
15824 lodash.noop = noop;
15827 lodash.padEnd = padEnd;
15828 lodash.padStart = padStart;
15829 lodash.parseInt = parseInt;
15830 lodash.random = random;
15831 lodash.reduce = reduce;
15832 lodash.reduceRight = reduceRight;
15833 lodash.repeat = repeat;
15834 lodash.replace = replace;
15835 lodash.result = result;
15836 lodash.round = round;
15837 lodash.runInContext = runInContext;
15838 lodash.sample = sample;
15839 lodash.size = size;
15840 lodash.snakeCase = snakeCase;
15841 lodash.some = some;
15842 lodash.sortedIndex = sortedIndex;
15843 lodash.sortedIndexBy = sortedIndexBy;
15844 lodash.sortedIndexOf = sortedIndexOf;
15845 lodash.sortedLastIndex = sortedLastIndex;
15846 lodash.sortedLastIndexBy = sortedLastIndexBy;
15847 lodash.sortedLastIndexOf = sortedLastIndexOf;
15848 lodash.startCase = startCase;
15849 lodash.startsWith = startsWith;
15850 lodash.subtract = subtract;
15852 lodash.sumBy = sumBy;
15853 lodash.template = template;
15854 lodash.times = times;
15855 lodash.toInteger = toInteger;
15856 lodash.toLength = toLength;
15857 lodash.toLower = toLower;
15858 lodash.toNumber = toNumber;
15859 lodash.toSafeInteger = toSafeInteger;
15860 lodash.toString = toString;
15861 lodash.toUpper = toUpper;
15862 lodash.trim = trim;
15863 lodash.trimEnd = trimEnd;
15864 lodash.trimStart = trimStart;
15865 lodash.truncate = truncate;
15866 lodash.unescape = unescape;
15867 lodash.uniqueId = uniqueId;
15868 lodash.upperCase = upperCase;
15869 lodash.upperFirst = upperFirst;
15872 lodash.each = forEach;
15873 lodash.eachRight = forEachRight;
15874 lodash.first = head;
15876 mixin(lodash, (function() {
15878 baseForOwn(lodash, function(func, methodName) {
15879 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
15880 source[methodName] = func;
15884 }()), { 'chain': false });
15886 /*------------------------------------------------------------------------*/
15889 * The semantic version number.
15895 lodash.VERSION = VERSION;
15897 // Assign default placeholders.
15898 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
15899 lodash[methodName].placeholder = lodash;
15902 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
15903 arrayEach(['drop', 'take'], function(methodName, index) {
15904 LazyWrapper.prototype[methodName] = function(n) {
15905 var filtered = this.__filtered__;
15906 if (filtered && !index) {
15907 return new LazyWrapper(this);
15909 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
15911 var result = this.clone();
15913 result.__takeCount__ = nativeMin(n, result.__takeCount__);
15915 result.__views__.push({
15916 'size': nativeMin(n, MAX_ARRAY_LENGTH),
15917 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
15923 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
15924 return this.reverse()[methodName](n).reverse();
15928 // Add `LazyWrapper` methods that accept an `iteratee` value.
15929 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
15930 var type = index + 1,
15931 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
15933 LazyWrapper.prototype[methodName] = function(iteratee) {
15934 var result = this.clone();
15935 result.__iteratees__.push({
15936 'iteratee': getIteratee(iteratee, 3),
15939 result.__filtered__ = result.__filtered__ || isFilter;
15944 // Add `LazyWrapper` methods for `_.head` and `_.last`.
15945 arrayEach(['head', 'last'], function(methodName, index) {
15946 var takeName = 'take' + (index ? 'Right' : '');
15948 LazyWrapper.prototype[methodName] = function() {
15949 return this[takeName](1).value()[0];
15953 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
15954 arrayEach(['initial', 'tail'], function(methodName, index) {
15955 var dropName = 'drop' + (index ? '' : 'Right');
15957 LazyWrapper.prototype[methodName] = function() {
15958 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
15962 LazyWrapper.prototype.compact = function() {
15963 return this.filter(identity);
15966 LazyWrapper.prototype.find = function(predicate) {
15967 return this.filter(predicate).head();
15970 LazyWrapper.prototype.findLast = function(predicate) {
15971 return this.reverse().find(predicate);
15974 LazyWrapper.prototype.invokeMap = rest(function(path, args) {
15975 if (typeof path == 'function') {
15976 return new LazyWrapper(this);
15978 return this.map(function(value) {
15979 return baseInvoke(value, path, args);
15983 LazyWrapper.prototype.reject = function(predicate) {
15984 predicate = getIteratee(predicate, 3);
15985 return this.filter(function(value) {
15986 return !predicate(value);
15990 LazyWrapper.prototype.slice = function(start, end) {
15991 start = toInteger(start);
15994 if (result.__filtered__ && (start > 0 || end < 0)) {
15995 return new LazyWrapper(result);
15998 result = result.takeRight(-start);
15999 } else if (start) {
16000 result = result.drop(start);
16002 if (end !== undefined) {
16003 end = toInteger(end);
16004 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
16009 LazyWrapper.prototype.takeRightWhile = function(predicate) {
16010 return this.reverse().takeWhile(predicate).reverse();
16013 LazyWrapper.prototype.toArray = function() {
16014 return this.take(MAX_ARRAY_LENGTH);
16017 // Add `LazyWrapper` methods to `lodash.prototype`.
16018 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16019 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
16020 isTaker = /^(?:head|last)$/.test(methodName),
16021 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
16022 retUnwrapped = isTaker || /^find/.test(methodName);
16027 lodash.prototype[methodName] = function() {
16028 var value = this.__wrapped__,
16029 args = isTaker ? [1] : arguments,
16030 isLazy = value instanceof LazyWrapper,
16031 iteratee = args[0],
16032 useLazy = isLazy || isArray(value);
16034 var interceptor = function(value) {
16035 var result = lodashFunc.apply(lodash, arrayPush([value], args));
16036 return (isTaker && chainAll) ? result[0] : result;
16039 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
16040 // Avoid lazy use if the iteratee has a "length" value other than `1`.
16041 isLazy = useLazy = false;
16043 var chainAll = this.__chain__,
16044 isHybrid = !!this.__actions__.length,
16045 isUnwrapped = retUnwrapped && !chainAll,
16046 onlyLazy = isLazy && !isHybrid;
16048 if (!retUnwrapped && useLazy) {
16049 value = onlyLazy ? value : new LazyWrapper(this);
16050 var result = func.apply(value, args);
16051 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
16052 return new LodashWrapper(result, chainAll);
16054 if (isUnwrapped && onlyLazy) {
16055 return func.apply(this, args);
16057 result = this.thru(interceptor);
16058 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
16062 // Add `Array` methods to `lodash.prototype`.
16063 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
16064 var func = arrayProto[methodName],
16065 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
16066 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
16068 lodash.prototype[methodName] = function() {
16069 var args = arguments;
16070 if (retUnwrapped && !this.__chain__) {
16071 var value = this.value();
16072 return func.apply(isArray(value) ? value : [], args);
16074 return this[chainName](function(value) {
16075 return func.apply(isArray(value) ? value : [], args);
16080 // Map minified method names to their real names.
16081 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16082 var lodashFunc = lodash[methodName];
16084 var key = (lodashFunc.name + ''),
16085 names = realNames[key] || (realNames[key] = []);
16087 names.push({ 'name': methodName, 'func': lodashFunc });
16091 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
16096 // Add methods to `LazyWrapper`.
16097 LazyWrapper.prototype.clone = lazyClone;
16098 LazyWrapper.prototype.reverse = lazyReverse;
16099 LazyWrapper.prototype.value = lazyValue;
16101 // Add chain sequence methods to the `lodash` wrapper.
16102 lodash.prototype.at = wrapperAt;
16103 lodash.prototype.chain = wrapperChain;
16104 lodash.prototype.commit = wrapperCommit;
16105 lodash.prototype.next = wrapperNext;
16106 lodash.prototype.plant = wrapperPlant;
16107 lodash.prototype.reverse = wrapperReverse;
16108 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
16110 if (iteratorSymbol) {
16111 lodash.prototype[iteratorSymbol] = wrapperToIterator;
16116 /*--------------------------------------------------------------------------*/
16119 var _ = runInContext();
16121 // Expose Lodash on the free variable `window` or `self` when available so it's
16122 // globally accessible, even when bundled with Browserify, Webpack, etc. This
16123 // also prevents errors in cases where Lodash is loaded by a script tag in the
16124 // presence of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch
16125 // for more details. Use `_.noConflict` to remove Lodash from the global object.
16126 (freeWindow || freeSelf || {})._ = _;
16128 // Some AMD build optimizers like r.js check for condition patterns like the following:
16129 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
16130 // Define as an anonymous module so, through path mapping, it can be
16131 // referenced as the "underscore" module.
16132 define(function() {
16136 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
16137 else if (freeExports && freeModule) {
16138 // Export for Node.js.
16139 if (moduleExports) {
16140 (freeModule.exports = _)._ = _;
16142 // Export for CommonJS support.
16146 // Export to the global object.