3 * lodash <https://lodash.com/>
4 * Copyright JS Foundation and other contributors <https://js.foundation/>
5 * Released under MIT license <https://lodash.com/license>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
14 /** Used as the semantic version number. */
15 var VERSION = '4.16.6';
17 /** Used as the size to enable large array optimizations. */
18 var LARGE_ARRAY_SIZE = 200;
20 /** Error message constants. */
21 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://github.com/es-shims.',
22 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 maximum memoize cache size. */
28 var MAX_MEMOIZE_SIZE = 500;
30 /** Used as the internal argument placeholder. */
31 var PLACEHOLDER = '__lodash_placeholder__';
33 /** Used to compose bitmasks for function metadata. */
38 CURRY_RIGHT_FLAG = 16,
40 PARTIAL_RIGHT_FLAG = 64,
45 /** Used to compose bitmasks for comparison styles. */
46 var UNORDERED_COMPARE_FLAG = 1,
47 PARTIAL_COMPARE_FLAG = 2;
49 /** Used as default options for `_.truncate`. */
50 var DEFAULT_TRUNC_LENGTH = 30,
51 DEFAULT_TRUNC_OMISSION = '...';
53 /** Used to detect hot functions by number of calls within a span of milliseconds. */
57 /** Used to indicate the type of lazy iteratees. */
58 var LAZY_FILTER_FLAG = 1,
62 /** Used as references for various `Number` constants. */
64 MAX_SAFE_INTEGER = 9007199254740991,
65 MAX_INTEGER = 1.7976931348623157e+308,
68 /** Used as references for the maximum length and index of an array. */
69 var MAX_ARRAY_LENGTH = 4294967295,
70 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
71 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
73 /** Used to associate wrap methods with their bit flags. */
77 ['bindKey', BIND_KEY_FLAG],
78 ['curry', CURRY_FLAG],
79 ['curryRight', CURRY_RIGHT_FLAG],
81 ['partial', PARTIAL_FLAG],
82 ['partialRight', PARTIAL_RIGHT_FLAG],
86 /** `Object#toString` result references. */
87 var argsTag = '[object Arguments]',
88 arrayTag = '[object Array]',
89 asyncTag = '[object AsyncFunction]',
90 boolTag = '[object Boolean]',
91 dateTag = '[object Date]',
92 domExcTag = '[object DOMException]',
93 errorTag = '[object Error]',
94 funcTag = '[object Function]',
95 genTag = '[object GeneratorFunction]',
96 mapTag = '[object Map]',
97 numberTag = '[object Number]',
98 nullTag = '[object Null]',
99 objectTag = '[object Object]',
100 promiseTag = '[object Promise]',
101 proxyTag = '[object Proxy]',
102 regexpTag = '[object RegExp]',
103 setTag = '[object Set]',
104 stringTag = '[object String]',
105 symbolTag = '[object Symbol]',
106 undefinedTag = '[object Undefined]',
107 weakMapTag = '[object WeakMap]',
108 weakSetTag = '[object WeakSet]';
110 var arrayBufferTag = '[object ArrayBuffer]',
111 dataViewTag = '[object DataView]',
112 float32Tag = '[object Float32Array]',
113 float64Tag = '[object Float64Array]',
114 int8Tag = '[object Int8Array]',
115 int16Tag = '[object Int16Array]',
116 int32Tag = '[object Int32Array]',
117 uint8Tag = '[object Uint8Array]',
118 uint8ClampedTag = '[object Uint8ClampedArray]',
119 uint16Tag = '[object Uint16Array]',
120 uint32Tag = '[object Uint32Array]';
122 /** Used to match empty string literals in compiled template source. */
123 var reEmptyStringLeading = /\b__p \+= '';/g,
124 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
125 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
127 /** Used to match HTML entities and HTML characters. */
128 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
129 reUnescapedHtml = /[&<>"']/g,
130 reHasEscapedHtml = RegExp(reEscapedHtml.source),
131 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
133 /** Used to match template delimiters. */
134 var reEscape = /<%-([\s\S]+?)%>/g,
135 reEvaluate = /<%([\s\S]+?)%>/g,
136 reInterpolate = /<%=([\s\S]+?)%>/g;
138 /** Used to match property names within property paths. */
139 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
140 reIsPlainProp = /^\w*$/,
141 reLeadingDot = /^\./,
142 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
145 * Used to match `RegExp`
146 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
148 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
149 reHasRegExpChar = RegExp(reRegExpChar.source);
151 /** Used to match leading and trailing whitespace. */
152 var reTrim = /^\s+|\s+$/g,
153 reTrimStart = /^\s+/,
156 /** Used to match wrap detail comments. */
157 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
158 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
159 reSplitDetails = /,? & /;
161 /** Used to match words composed of alphanumeric characters. */
162 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
164 /** Used to match backslashes in property paths. */
165 var reEscapeChar = /\\(\\)?/g;
169 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
171 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
173 /** Used to match `RegExp` flags from their coerced string values. */
174 var reFlags = /\w*$/;
176 /** Used to detect bad signed hexadecimal string values. */
177 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
179 /** Used to detect binary string values. */
180 var reIsBinary = /^0b[01]+$/i;
182 /** Used to detect host constructors (Safari). */
183 var reIsHostCtor = /^\[object .+?Constructor\]$/;
185 /** Used to detect octal string values. */
186 var reIsOctal = /^0o[0-7]+$/i;
188 /** Used to detect unsigned integer values. */
189 var reIsUint = /^(?:0|[1-9]\d*)$/;
191 /** Used to match Latin Unicode letters (excluding mathematical operators). */
192 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
194 /** Used to ensure capturing order of template delimiters. */
195 var reNoMatch = /($^)/;
197 /** Used to match unescaped characters in compiled string literals. */
198 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
200 /** Used to compose unicode character classes. */
201 var rsAstralRange = '\\ud800-\\udfff',
202 rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
203 rsComboSymbolsRange = '\\u20d0-\\u20f0',
204 rsDingbatRange = '\\u2700-\\u27bf',
205 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
206 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
207 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
208 rsPunctuationRange = '\\u2000-\\u206f',
209 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',
210 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
211 rsVarRange = '\\ufe0e\\ufe0f',
212 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
214 /** Used to compose unicode capture groups. */
215 var rsApos = "['\u2019]",
216 rsAstral = '[' + rsAstralRange + ']',
217 rsBreak = '[' + rsBreakRange + ']',
218 rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
220 rsDingbat = '[' + rsDingbatRange + ']',
221 rsLower = '[' + rsLowerRange + ']',
222 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
223 rsFitz = '\\ud83c[\\udffb-\\udfff]',
224 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
225 rsNonAstral = '[^' + rsAstralRange + ']',
226 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
227 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
228 rsUpper = '[' + rsUpperRange + ']',
231 /** Used to compose unicode regexes. */
232 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
233 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
234 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
235 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
236 reOptMod = rsModifier + '?',
237 rsOptVar = '[' + rsVarRange + ']?',
238 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
239 rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)',
240 rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)',
241 rsSeq = rsOptVar + reOptMod + rsOptJoin,
242 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
243 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
245 /** Used to match apostrophes. */
246 var reApos = RegExp(rsApos, 'g');
249 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
250 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
252 var reComboMark = RegExp(rsCombo, 'g');
254 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
255 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
257 /** Used to match complex or compound words. */
258 var reUnicodeWord = RegExp([
259 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
260 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
261 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
262 rsUpper + '+' + rsOptContrUpper,
269 /** 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/). */
270 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
272 /** Used to detect strings that need a more robust regexp to match words. */
273 var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
275 /** Used to assign default `context` object properties. */
277 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
278 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
279 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
280 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
281 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
284 /** Used to make template sourceURLs easier to identify. */
285 var templateCounter = -1;
287 /** Used to identify `toStringTag` values of typed arrays. */
288 var typedArrayTags = {};
289 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
290 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
291 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
292 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
293 typedArrayTags[uint32Tag] = true;
294 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
295 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
296 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
297 typedArrayTags[errorTag] = typedArrayTags[funcTag] =
298 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
299 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
300 typedArrayTags[setTag] = typedArrayTags[stringTag] =
301 typedArrayTags[weakMapTag] = false;
303 /** Used to identify `toStringTag` values supported by `_.clone`. */
304 var cloneableTags = {};
305 cloneableTags[argsTag] = cloneableTags[arrayTag] =
306 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
307 cloneableTags[boolTag] = cloneableTags[dateTag] =
308 cloneableTags[float32Tag] = cloneableTags[float64Tag] =
309 cloneableTags[int8Tag] = cloneableTags[int16Tag] =
310 cloneableTags[int32Tag] = cloneableTags[mapTag] =
311 cloneableTags[numberTag] = cloneableTags[objectTag] =
312 cloneableTags[regexpTag] = cloneableTags[setTag] =
313 cloneableTags[stringTag] = cloneableTags[symbolTag] =
314 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
315 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
316 cloneableTags[errorTag] = cloneableTags[funcTag] =
317 cloneableTags[weakMapTag] = false;
319 /** Used to map Latin Unicode letters to basic Latin letters. */
320 var deburredLetters = {
321 // Latin-1 Supplement block.
322 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
323 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
324 '\xc7': 'C', '\xe7': 'c',
325 '\xd0': 'D', '\xf0': 'd',
326 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
327 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
328 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
329 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
330 '\xd1': 'N', '\xf1': 'n',
331 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
332 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
333 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
334 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
335 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
336 '\xc6': 'Ae', '\xe6': 'ae',
337 '\xde': 'Th', '\xfe': 'th',
339 // Latin Extended-A block.
340 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
341 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
342 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
343 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
344 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
345 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
346 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
347 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
348 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
349 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
350 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
351 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
352 '\u0134': 'J', '\u0135': 'j',
353 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
354 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
355 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
356 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
357 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
358 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
359 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
360 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
361 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
362 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
363 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
364 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
365 '\u0163': 't', '\u0165': 't', '\u0167': 't',
366 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
367 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
368 '\u0174': 'W', '\u0175': 'w',
369 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
370 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
371 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
372 '\u0132': 'IJ', '\u0133': 'ij',
373 '\u0152': 'Oe', '\u0153': 'oe',
374 '\u0149': "'n", '\u017f': 's'
377 /** Used to map characters to HTML entities. */
386 /** Used to map HTML entities to characters. */
387 var htmlUnescapes = {
395 /** Used to escape characters for inclusion in compiled string literals. */
396 var stringEscapes = {
405 /** Built-in method references without a dependency on `root`. */
406 var freeParseFloat = parseFloat,
407 freeParseInt = parseInt;
409 /** Detect free variable `global` from Node.js. */
410 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
412 /** Detect free variable `self`. */
413 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
415 /** Used as a reference to the global object. */
416 var root = freeGlobal || freeSelf || Function('return this')();
418 /** Detect free variable `exports`. */
419 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
421 /** Detect free variable `module`. */
422 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
424 /** Detect the popular CommonJS extension `module.exports`. */
425 var moduleExports = freeModule && freeModule.exports === freeExports;
427 /** Detect free variable `process` from Node.js. */
428 var freeProcess = moduleExports && freeGlobal.process;
430 /** Used to access faster Node.js helpers. */
431 var nodeUtil = (function() {
433 return freeProcess && freeProcess.binding('util');
437 /* Node.js helper references. */
438 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
439 nodeIsDate = nodeUtil && nodeUtil.isDate,
440 nodeIsMap = nodeUtil && nodeUtil.isMap,
441 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
442 nodeIsSet = nodeUtil && nodeUtil.isSet,
443 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
445 /*--------------------------------------------------------------------------*/
448 * Adds the key-value `pair` to `map`.
451 * @param {Object} map The map to modify.
452 * @param {Array} pair The key-value pair to add.
453 * @returns {Object} Returns `map`.
455 function addMapEntry(map, pair) {
456 // Don't return `map.set` because it's not chainable in IE 11.
457 map.set(pair[0], pair[1]);
462 * Adds `value` to `set`.
465 * @param {Object} set The set to modify.
466 * @param {*} value The value to add.
467 * @returns {Object} Returns `set`.
469 function addSetEntry(set, value) {
470 // Don't return `set.add` because it's not chainable in IE 11.
476 * A faster alternative to `Function#apply`, this function invokes `func`
477 * with the `this` binding of `thisArg` and the arguments of `args`.
480 * @param {Function} func The function to invoke.
481 * @param {*} thisArg The `this` binding of `func`.
482 * @param {Array} args The arguments to invoke `func` with.
483 * @returns {*} Returns the result of `func`.
485 function apply(func, thisArg, args) {
486 switch (args.length) {
487 case 0: return func.call(thisArg);
488 case 1: return func.call(thisArg, args[0]);
489 case 2: return func.call(thisArg, args[0], args[1]);
490 case 3: return func.call(thisArg, args[0], args[1], args[2]);
492 return func.apply(thisArg, args);
496 * A specialized version of `baseAggregator` for arrays.
499 * @param {Array} [array] The array to iterate over.
500 * @param {Function} setter The function to set `accumulator` values.
501 * @param {Function} iteratee The iteratee to transform keys.
502 * @param {Object} accumulator The initial aggregated object.
503 * @returns {Function} Returns `accumulator`.
505 function arrayAggregator(array, setter, iteratee, accumulator) {
507 length = array == null ? 0 : array.length;
509 while (++index < length) {
510 var value = array[index];
511 setter(accumulator, value, iteratee(value), array);
517 * A specialized version of `_.forEach` for arrays without support for
518 * iteratee shorthands.
521 * @param {Array} [array] The array to iterate over.
522 * @param {Function} iteratee The function invoked per iteration.
523 * @returns {Array} Returns `array`.
525 function arrayEach(array, iteratee) {
527 length = array == null ? 0 : array.length;
529 while (++index < length) {
530 if (iteratee(array[index], index, array) === false) {
538 * A specialized version of `_.forEachRight` for arrays without support for
539 * iteratee shorthands.
542 * @param {Array} [array] The array to iterate over.
543 * @param {Function} iteratee The function invoked per iteration.
544 * @returns {Array} Returns `array`.
546 function arrayEachRight(array, iteratee) {
547 var length = array == null ? 0 : array.length;
550 if (iteratee(array[length], length, array) === false) {
558 * A specialized version of `_.every` for arrays without support for
559 * iteratee shorthands.
562 * @param {Array} [array] The array to iterate over.
563 * @param {Function} predicate The function invoked per iteration.
564 * @returns {boolean} Returns `true` if all elements pass the predicate check,
567 function arrayEvery(array, predicate) {
569 length = array == null ? 0 : array.length;
571 while (++index < length) {
572 if (!predicate(array[index], index, array)) {
580 * A specialized version of `_.filter` for arrays without support for
581 * iteratee shorthands.
584 * @param {Array} [array] The array to iterate over.
585 * @param {Function} predicate The function invoked per iteration.
586 * @returns {Array} Returns the new filtered array.
588 function arrayFilter(array, predicate) {
590 length = array == null ? 0 : array.length,
594 while (++index < length) {
595 var value = array[index];
596 if (predicate(value, index, array)) {
597 result[resIndex++] = value;
604 * A specialized version of `_.includes` for arrays without support for
605 * specifying an index to search from.
608 * @param {Array} [array] The array to inspect.
609 * @param {*} target The value to search for.
610 * @returns {boolean} Returns `true` if `target` is found, else `false`.
612 function arrayIncludes(array, value) {
613 var length = array == null ? 0 : array.length;
614 return !!length && baseIndexOf(array, value, 0) > -1;
618 * This function is like `arrayIncludes` except that it accepts a comparator.
621 * @param {Array} [array] The array to inspect.
622 * @param {*} target The value to search for.
623 * @param {Function} comparator The comparator invoked per element.
624 * @returns {boolean} Returns `true` if `target` is found, else `false`.
626 function arrayIncludesWith(array, value, comparator) {
628 length = array == null ? 0 : array.length;
630 while (++index < length) {
631 if (comparator(value, array[index])) {
639 * A specialized version of `_.map` for arrays without support for iteratee
643 * @param {Array} [array] The array to iterate over.
644 * @param {Function} iteratee The function invoked per iteration.
645 * @returns {Array} Returns the new mapped array.
647 function arrayMap(array, iteratee) {
649 length = array == null ? 0 : array.length,
650 result = Array(length);
652 while (++index < length) {
653 result[index] = iteratee(array[index], index, array);
659 * Appends the elements of `values` to `array`.
662 * @param {Array} array The array to modify.
663 * @param {Array} values The values to append.
664 * @returns {Array} Returns `array`.
666 function arrayPush(array, values) {
668 length = values.length,
669 offset = array.length;
671 while (++index < length) {
672 array[offset + index] = values[index];
678 * A specialized version of `_.reduce` for arrays without support for
679 * iteratee shorthands.
682 * @param {Array} [array] The array to iterate over.
683 * @param {Function} iteratee The function invoked per iteration.
684 * @param {*} [accumulator] The initial value.
685 * @param {boolean} [initAccum] Specify using the first element of `array` as
687 * @returns {*} Returns the accumulated value.
689 function arrayReduce(array, iteratee, accumulator, initAccum) {
691 length = array == null ? 0 : array.length;
693 if (initAccum && length) {
694 accumulator = array[++index];
696 while (++index < length) {
697 accumulator = iteratee(accumulator, array[index], index, array);
703 * A specialized version of `_.reduceRight` for arrays without support for
704 * iteratee shorthands.
707 * @param {Array} [array] The array to iterate over.
708 * @param {Function} iteratee The function invoked per iteration.
709 * @param {*} [accumulator] The initial value.
710 * @param {boolean} [initAccum] Specify using the last element of `array` as
712 * @returns {*} Returns the accumulated value.
714 function arrayReduceRight(array, iteratee, accumulator, initAccum) {
715 var length = array == null ? 0 : array.length;
716 if (initAccum && length) {
717 accumulator = array[--length];
720 accumulator = iteratee(accumulator, array[length], length, array);
726 * A specialized version of `_.some` for arrays without support for iteratee
730 * @param {Array} [array] The array to iterate over.
731 * @param {Function} predicate The function invoked per iteration.
732 * @returns {boolean} Returns `true` if any element passes the predicate check,
735 function arraySome(array, predicate) {
737 length = array == null ? 0 : array.length;
739 while (++index < length) {
740 if (predicate(array[index], index, array)) {
748 * Gets the size of an ASCII `string`.
751 * @param {string} string The string inspect.
752 * @returns {number} Returns the string size.
754 var asciiSize = baseProperty('length');
757 * Converts an ASCII `string` to an array.
760 * @param {string} string The string to convert.
761 * @returns {Array} Returns the converted array.
763 function asciiToArray(string) {
764 return string.split('');
768 * Splits an ASCII `string` into an array of its words.
771 * @param {string} The string to inspect.
772 * @returns {Array} Returns the words of `string`.
774 function asciiWords(string) {
775 return string.match(reAsciiWord) || [];
779 * The base implementation of methods like `_.findKey` and `_.findLastKey`,
780 * without support for iteratee shorthands, which iterates over `collection`
784 * @param {Array|Object} collection The collection to inspect.
785 * @param {Function} predicate The function invoked per iteration.
786 * @param {Function} eachFunc The function to iterate over `collection`.
787 * @returns {*} Returns the found element or its key, else `undefined`.
789 function baseFindKey(collection, predicate, eachFunc) {
791 eachFunc(collection, function(value, key, collection) {
792 if (predicate(value, key, collection)) {
801 * The base implementation of `_.findIndex` and `_.findLastIndex` without
802 * support for iteratee shorthands.
805 * @param {Array} array The array to inspect.
806 * @param {Function} predicate The function invoked per iteration.
807 * @param {number} fromIndex The index to search from.
808 * @param {boolean} [fromRight] Specify iterating from right to left.
809 * @returns {number} Returns the index of the matched value, else `-1`.
811 function baseFindIndex(array, predicate, fromIndex, fromRight) {
812 var length = array.length,
813 index = fromIndex + (fromRight ? 1 : -1);
815 while ((fromRight ? index-- : ++index < length)) {
816 if (predicate(array[index], index, array)) {
824 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
827 * @param {Array} array The array to inspect.
828 * @param {*} value The value to search for.
829 * @param {number} fromIndex The index to search from.
830 * @returns {number} Returns the index of the matched value, else `-1`.
832 function baseIndexOf(array, value, fromIndex) {
833 return value === value
834 ? strictIndexOf(array, value, fromIndex)
835 : baseFindIndex(array, baseIsNaN, fromIndex);
839 * This function is like `baseIndexOf` except that it accepts a comparator.
842 * @param {Array} array The array to inspect.
843 * @param {*} value The value to search for.
844 * @param {number} fromIndex The index to search from.
845 * @param {Function} comparator The comparator invoked per element.
846 * @returns {number} Returns the index of the matched value, else `-1`.
848 function baseIndexOfWith(array, value, fromIndex, comparator) {
849 var index = fromIndex - 1,
850 length = array.length;
852 while (++index < length) {
853 if (comparator(array[index], value)) {
861 * The base implementation of `_.isNaN` without support for number objects.
864 * @param {*} value The value to check.
865 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
867 function baseIsNaN(value) {
868 return value !== value;
872 * The base implementation of `_.mean` and `_.meanBy` without support for
873 * iteratee shorthands.
876 * @param {Array} array The array to iterate over.
877 * @param {Function} iteratee The function invoked per iteration.
878 * @returns {number} Returns the mean.
880 function baseMean(array, iteratee) {
881 var length = array == null ? 0 : array.length;
882 return length ? (baseSum(array, iteratee) / length) : NAN;
886 * The base implementation of `_.property` without support for deep paths.
889 * @param {string} key The key of the property to get.
890 * @returns {Function} Returns the new accessor function.
892 function baseProperty(key) {
893 return function(object) {
894 return object == null ? undefined : object[key];
899 * The base implementation of `_.propertyOf` without support for deep paths.
902 * @param {Object} object The object to query.
903 * @returns {Function} Returns the new accessor function.
905 function basePropertyOf(object) {
906 return function(key) {
907 return object == null ? undefined : object[key];
912 * The base implementation of `_.reduce` and `_.reduceRight`, without support
913 * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
916 * @param {Array|Object} collection The collection to iterate over.
917 * @param {Function} iteratee The function invoked per iteration.
918 * @param {*} accumulator The initial value.
919 * @param {boolean} initAccum Specify using the first or last element of
920 * `collection` as the initial value.
921 * @param {Function} eachFunc The function to iterate over `collection`.
922 * @returns {*} Returns the accumulated value.
924 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
925 eachFunc(collection, function(value, index, collection) {
926 accumulator = initAccum
927 ? (initAccum = false, value)
928 : iteratee(accumulator, value, index, collection);
934 * The base implementation of `_.sortBy` which uses `comparer` to define the
935 * sort order of `array` and replaces criteria objects with their corresponding
939 * @param {Array} array The array to sort.
940 * @param {Function} comparer The function to define sort order.
941 * @returns {Array} Returns `array`.
943 function baseSortBy(array, comparer) {
944 var length = array.length;
946 array.sort(comparer);
948 array[length] = array[length].value;
954 * The base implementation of `_.sum` and `_.sumBy` without support for
955 * iteratee shorthands.
958 * @param {Array} array The array to iterate over.
959 * @param {Function} iteratee The function invoked per iteration.
960 * @returns {number} Returns the sum.
962 function baseSum(array, iteratee) {
965 length = array.length;
967 while (++index < length) {
968 var current = iteratee(array[index]);
969 if (current !== undefined) {
970 result = result === undefined ? current : (result + current);
977 * The base implementation of `_.times` without support for iteratee shorthands
978 * or max array length checks.
981 * @param {number} n The number of times to invoke `iteratee`.
982 * @param {Function} iteratee The function invoked per iteration.
983 * @returns {Array} Returns the array of results.
985 function baseTimes(n, iteratee) {
989 while (++index < n) {
990 result[index] = iteratee(index);
996 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
997 * of key-value pairs for `object` corresponding to the property names of `props`.
1000 * @param {Object} object The object to query.
1001 * @param {Array} props The property names to get values for.
1002 * @returns {Object} Returns the key-value pairs.
1004 function baseToPairs(object, props) {
1005 return arrayMap(props, function(key) {
1006 return [key, object[key]];
1011 * The base implementation of `_.unary` without support for storing metadata.
1014 * @param {Function} func The function to cap arguments for.
1015 * @returns {Function} Returns the new capped function.
1017 function baseUnary(func) {
1018 return function(value) {
1024 * The base implementation of `_.values` and `_.valuesIn` which creates an
1025 * array of `object` property values corresponding to the property names
1029 * @param {Object} object The object to query.
1030 * @param {Array} props The property names to get values for.
1031 * @returns {Object} Returns the array of property values.
1033 function baseValues(object, props) {
1034 return arrayMap(props, function(key) {
1040 * Checks if a `cache` value for `key` exists.
1043 * @param {Object} cache The cache to query.
1044 * @param {string} key The key of the entry to check.
1045 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1047 function cacheHas(cache, key) {
1048 return cache.has(key);
1052 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1053 * that is not found in the character symbols.
1056 * @param {Array} strSymbols The string symbols to inspect.
1057 * @param {Array} chrSymbols The character symbols to find.
1058 * @returns {number} Returns the index of the first unmatched string symbol.
1060 function charsStartIndex(strSymbols, chrSymbols) {
1062 length = strSymbols.length;
1064 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1069 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1070 * that is not found in the character symbols.
1073 * @param {Array} strSymbols The string symbols to inspect.
1074 * @param {Array} chrSymbols The character symbols to find.
1075 * @returns {number} Returns the index of the last unmatched string symbol.
1077 function charsEndIndex(strSymbols, chrSymbols) {
1078 var index = strSymbols.length;
1080 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1085 * Gets the number of `placeholder` occurrences in `array`.
1088 * @param {Array} array The array to inspect.
1089 * @param {*} placeholder The placeholder to search for.
1090 * @returns {number} Returns the placeholder count.
1092 function countHolders(array, placeholder) {
1093 var length = array.length,
1097 if (array[length] === placeholder) {
1105 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
1106 * letters to basic Latin letters.
1109 * @param {string} letter The matched letter to deburr.
1110 * @returns {string} Returns the deburred letter.
1112 var deburrLetter = basePropertyOf(deburredLetters);
1115 * Used by `_.escape` to convert characters to HTML entities.
1118 * @param {string} chr The matched character to escape.
1119 * @returns {string} Returns the escaped character.
1121 var escapeHtmlChar = basePropertyOf(htmlEscapes);
1124 * Used by `_.template` to escape characters for inclusion in compiled string literals.
1127 * @param {string} chr The matched character to escape.
1128 * @returns {string} Returns the escaped character.
1130 function escapeStringChar(chr) {
1131 return '\\' + stringEscapes[chr];
1135 * Gets the value at `key` of `object`.
1138 * @param {Object} [object] The object to query.
1139 * @param {string} key The key of the property to get.
1140 * @returns {*} Returns the property value.
1142 function getValue(object, key) {
1143 return object == null ? undefined : object[key];
1147 * Checks if `string` contains Unicode symbols.
1150 * @param {string} string The string to inspect.
1151 * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1153 function hasUnicode(string) {
1154 return reHasUnicode.test(string);
1158 * Checks if `string` contains a word composed of Unicode symbols.
1161 * @param {string} string The string to inspect.
1162 * @returns {boolean} Returns `true` if a word is found, else `false`.
1164 function hasUnicodeWord(string) {
1165 return reHasUnicodeWord.test(string);
1169 * Converts `iterator` to an array.
1172 * @param {Object} iterator The iterator to convert.
1173 * @returns {Array} Returns the converted array.
1175 function iteratorToArray(iterator) {
1179 while (!(data = iterator.next()).done) {
1180 result.push(data.value);
1186 * Converts `map` to its key-value pairs.
1189 * @param {Object} map The map to convert.
1190 * @returns {Array} Returns the key-value pairs.
1192 function mapToArray(map) {
1194 result = Array(map.size);
1196 map.forEach(function(value, key) {
1197 result[++index] = [key, value];
1203 * Creates a unary function that invokes `func` with its argument transformed.
1206 * @param {Function} func The function to wrap.
1207 * @param {Function} transform The argument transform.
1208 * @returns {Function} Returns the new function.
1210 function overArg(func, transform) {
1211 return function(arg) {
1212 return func(transform(arg));
1217 * Replaces all `placeholder` elements in `array` with an internal placeholder
1218 * and returns an array of their indexes.
1221 * @param {Array} array The array to modify.
1222 * @param {*} placeholder The placeholder to replace.
1223 * @returns {Array} Returns the new array of placeholder indexes.
1225 function replaceHolders(array, placeholder) {
1227 length = array.length,
1231 while (++index < length) {
1232 var value = array[index];
1233 if (value === placeholder || value === PLACEHOLDER) {
1234 array[index] = PLACEHOLDER;
1235 result[resIndex++] = index;
1242 * Converts `set` to an array of its values.
1245 * @param {Object} set The set to convert.
1246 * @returns {Array} Returns the values.
1248 function setToArray(set) {
1250 result = Array(set.size);
1252 set.forEach(function(value) {
1253 result[++index] = value;
1259 * Converts `set` to its value-value pairs.
1262 * @param {Object} set The set to convert.
1263 * @returns {Array} Returns the value-value pairs.
1265 function setToPairs(set) {
1267 result = Array(set.size);
1269 set.forEach(function(value) {
1270 result[++index] = [value, value];
1276 * A specialized version of `_.indexOf` which performs strict equality
1277 * comparisons of values, i.e. `===`.
1280 * @param {Array} array The array to inspect.
1281 * @param {*} value The value to search for.
1282 * @param {number} fromIndex The index to search from.
1283 * @returns {number} Returns the index of the matched value, else `-1`.
1285 function strictIndexOf(array, value, fromIndex) {
1286 var index = fromIndex - 1,
1287 length = array.length;
1289 while (++index < length) {
1290 if (array[index] === value) {
1298 * A specialized version of `_.lastIndexOf` which performs strict equality
1299 * comparisons of values, i.e. `===`.
1302 * @param {Array} array The array to inspect.
1303 * @param {*} value The value to search for.
1304 * @param {number} fromIndex The index to search from.
1305 * @returns {number} Returns the index of the matched value, else `-1`.
1307 function strictLastIndexOf(array, value, fromIndex) {
1308 var index = fromIndex + 1;
1310 if (array[index] === value) {
1318 * Gets the number of symbols in `string`.
1321 * @param {string} string The string to inspect.
1322 * @returns {number} Returns the string size.
1324 function stringSize(string) {
1325 return hasUnicode(string)
1326 ? unicodeSize(string)
1327 : asciiSize(string);
1331 * Converts `string` to an array.
1334 * @param {string} string The string to convert.
1335 * @returns {Array} Returns the converted array.
1337 function stringToArray(string) {
1338 return hasUnicode(string)
1339 ? unicodeToArray(string)
1340 : asciiToArray(string);
1344 * Used by `_.unescape` to convert HTML entities to characters.
1347 * @param {string} chr The matched character to unescape.
1348 * @returns {string} Returns the unescaped character.
1350 var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
1353 * Gets the size of a Unicode `string`.
1356 * @param {string} string The string inspect.
1357 * @returns {number} Returns the string size.
1359 function unicodeSize(string) {
1360 var result = reUnicode.lastIndex = 0;
1361 while (reUnicode.test(string)) {
1368 * Converts a Unicode `string` to an array.
1371 * @param {string} string The string to convert.
1372 * @returns {Array} Returns the converted array.
1374 function unicodeToArray(string) {
1375 return string.match(reUnicode) || [];
1379 * Splits a Unicode `string` into an array of its words.
1382 * @param {string} The string to inspect.
1383 * @returns {Array} Returns the words of `string`.
1385 function unicodeWords(string) {
1386 return string.match(reUnicodeWord) || [];
1389 /*--------------------------------------------------------------------------*/
1392 * Create a new pristine `lodash` function using the `context` object.
1398 * @param {Object} [context=root] The context object.
1399 * @returns {Function} Returns a new `lodash` function.
1402 * _.mixin({ 'foo': _.constant('foo') });
1404 * var lodash = _.runInContext();
1405 * lodash.mixin({ 'bar': lodash.constant('bar') });
1407 * _.isFunction(_.foo);
1409 * _.isFunction(_.bar);
1412 * lodash.isFunction(lodash.foo);
1414 * lodash.isFunction(lodash.bar);
1417 * // Create a suped-up `defer` in Node.js.
1418 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1420 var runInContext = (function runInContext(context) {
1421 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1423 /** Built-in constructor references. */
1424 var Array = context.Array,
1425 Date = context.Date,
1426 Error = context.Error,
1427 Function = context.Function,
1428 Math = context.Math,
1429 Object = context.Object,
1430 RegExp = context.RegExp,
1431 String = context.String,
1432 TypeError = context.TypeError;
1434 /** Used for built-in method references. */
1435 var arrayProto = Array.prototype,
1436 funcProto = Function.prototype,
1437 objectProto = Object.prototype;
1439 /** Used to detect overreaching core-js shims. */
1440 var coreJsData = context['__core-js_shared__'];
1442 /** Used to resolve the decompiled source of functions. */
1443 var funcToString = funcProto.toString;
1445 /** Used to check objects for own properties. */
1446 var hasOwnProperty = objectProto.hasOwnProperty;
1448 /** Used to generate unique IDs. */
1451 /** Used to detect methods masquerading as native. */
1452 var maskSrcKey = (function() {
1453 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
1454 return uid ? ('Symbol(src)_1.' + uid) : '';
1458 * Used to resolve the
1459 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
1462 var nativeObjectToString = objectProto.toString;
1464 /** Used to infer the `Object` constructor. */
1465 var objectCtorString = funcToString.call(Object);
1467 /** Used to restore the original `_` reference in `_.noConflict`. */
1468 var oldDash = root._;
1470 /** Used to detect if a method is native. */
1471 var reIsNative = RegExp('^' +
1472 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
1473 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1476 /** Built-in value references. */
1477 var Buffer = moduleExports ? context.Buffer : undefined,
1478 Symbol = context.Symbol,
1479 Uint8Array = context.Uint8Array,
1480 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
1481 getPrototype = overArg(Object.getPrototypeOf, Object),
1482 objectCreate = Object.create,
1483 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1484 splice = arrayProto.splice,
1485 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
1486 symIterator = Symbol ? Symbol.iterator : undefined,
1487 symToStringTag = Symbol ? Symbol.toStringTag : undefined;
1489 var defineProperty = (function() {
1491 var func = getNative(Object, 'defineProperty');
1497 /** Mocked built-ins. */
1498 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
1499 ctxNow = Date && Date.now !== root.Date.now && Date.now,
1500 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1502 /* Built-in method references for those with the same name as other `lodash` methods. */
1503 var nativeCeil = Math.ceil,
1504 nativeFloor = Math.floor,
1505 nativeGetSymbols = Object.getOwnPropertySymbols,
1506 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
1507 nativeIsFinite = context.isFinite,
1508 nativeJoin = arrayProto.join,
1509 nativeKeys = overArg(Object.keys, Object),
1510 nativeMax = Math.max,
1511 nativeMin = Math.min,
1512 nativeNow = Date.now,
1513 nativeParseInt = context.parseInt,
1514 nativeRandom = Math.random,
1515 nativeReverse = arrayProto.reverse;
1517 /* Built-in method references that are verified to be native. */
1518 var DataView = getNative(context, 'DataView'),
1519 Map = getNative(context, 'Map'),
1520 Promise = getNative(context, 'Promise'),
1521 Set = getNative(context, 'Set'),
1522 WeakMap = getNative(context, 'WeakMap'),
1523 nativeCreate = getNative(Object, 'create');
1525 /** Used to store function metadata. */
1526 var metaMap = WeakMap && new WeakMap;
1528 /** Used to lookup unminified function names. */
1531 /** Used to detect maps, sets, and weakmaps. */
1532 var dataViewCtorString = toSource(DataView),
1533 mapCtorString = toSource(Map),
1534 promiseCtorString = toSource(Promise),
1535 setCtorString = toSource(Set),
1536 weakMapCtorString = toSource(WeakMap);
1538 /** Used to convert symbols to primitives and strings. */
1539 var symbolProto = Symbol ? Symbol.prototype : undefined,
1540 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
1541 symbolToString = symbolProto ? symbolProto.toString : undefined;
1543 /*------------------------------------------------------------------------*/
1546 * Creates a `lodash` object which wraps `value` to enable implicit method
1547 * chain sequences. Methods that operate on and return arrays, collections,
1548 * and functions can be chained together. Methods that retrieve a single value
1549 * or may return a primitive value will automatically end the chain sequence
1550 * and return the unwrapped value. Otherwise, the value must be unwrapped
1553 * Explicit chain sequences, which must be unwrapped with `_#value`, may be
1554 * enabled using `_.chain`.
1556 * The execution of chained methods is lazy, that is, it's deferred until
1557 * `_#value` is implicitly or explicitly called.
1559 * Lazy evaluation allows several methods to support shortcut fusion.
1560 * Shortcut fusion is an optimization to merge iteratee calls; this avoids
1561 * the creation of intermediate arrays and can greatly reduce the number of
1562 * iteratee executions. Sections of a chain sequence qualify for shortcut
1563 * fusion if the section is applied to an array of at least `200` elements
1564 * and any iteratees accept only one argument. The heuristic for whether a
1565 * section qualifies for shortcut fusion is subject to change.
1567 * Chaining is supported in custom builds as long as the `_#value` method is
1568 * directly or indirectly included in the build.
1570 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1572 * The wrapper `Array` methods are:
1573 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
1575 * The wrapper `String` methods are:
1576 * `replace` and `split`
1578 * The wrapper methods that support shortcut fusion are:
1579 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
1580 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
1581 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
1583 * The chainable wrapper methods are:
1584 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
1585 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
1586 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
1587 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
1588 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
1589 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
1590 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
1591 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
1592 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
1593 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
1594 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
1595 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
1596 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
1597 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
1598 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
1599 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
1600 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
1601 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
1602 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
1603 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
1604 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
1605 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
1606 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
1607 * `zipObject`, `zipObjectDeep`, and `zipWith`
1609 * The wrapper methods that are **not** chainable by default are:
1610 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
1611 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
1612 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
1613 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
1614 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
1615 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
1616 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
1617 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
1618 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
1619 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
1620 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
1621 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
1622 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
1623 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
1624 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
1625 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
1626 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
1627 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
1628 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
1629 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
1630 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
1631 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
1632 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
1633 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
1634 * `upperFirst`, `value`, and `words`
1639 * @param {*} value The value to wrap in a `lodash` instance.
1640 * @returns {Object} Returns the new `lodash` wrapper instance.
1643 * function square(n) {
1647 * var wrapped = _([1, 2, 3]);
1649 * // Returns an unwrapped value.
1650 * wrapped.reduce(_.add);
1653 * // Returns a wrapped value.
1654 * var squares = wrapped.map(square);
1656 * _.isArray(squares);
1659 * _.isArray(squares.value());
1662 function lodash(value) {
1663 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1664 if (value instanceof LodashWrapper) {
1667 if (hasOwnProperty.call(value, '__wrapped__')) {
1668 return wrapperClone(value);
1671 return new LodashWrapper(value);
1675 * The base implementation of `_.create` without support for assigning
1676 * properties to the created object.
1679 * @param {Object} proto The object to inherit from.
1680 * @returns {Object} Returns the new object.
1682 var baseCreate = (function() {
1683 function object() {}
1684 return function(proto) {
1685 if (!isObject(proto)) {
1689 return objectCreate(proto);
1691 object.prototype = proto;
1692 var result = new object;
1693 object.prototype = undefined;
1699 * The function whose prototype chain sequence wrappers inherit from.
1703 function baseLodash() {
1704 // No operation performed.
1708 * The base constructor for creating `lodash` wrapper objects.
1711 * @param {*} value The value to wrap.
1712 * @param {boolean} [chainAll] Enable explicit method chain sequences.
1714 function LodashWrapper(value, chainAll) {
1715 this.__wrapped__ = value;
1716 this.__actions__ = [];
1717 this.__chain__ = !!chainAll;
1719 this.__values__ = undefined;
1723 * By default, the template delimiters used by lodash are like those in
1724 * embedded Ruby (ERB). Change the following template settings to use
1725 * alternative delimiters.
1731 lodash.templateSettings = {
1734 * Used to detect `data` property values to be HTML-escaped.
1736 * @memberOf _.templateSettings
1742 * Used to detect code to be evaluated.
1744 * @memberOf _.templateSettings
1747 'evaluate': reEvaluate,
1750 * Used to detect `data` property values to inject.
1752 * @memberOf _.templateSettings
1755 'interpolate': reInterpolate,
1758 * Used to reference the data object in the template text.
1760 * @memberOf _.templateSettings
1766 * Used to import variables into the compiled template.
1768 * @memberOf _.templateSettings
1774 * A reference to the `lodash` function.
1776 * @memberOf _.templateSettings.imports
1783 // Ensure wrappers are instances of `baseLodash`.
1784 lodash.prototype = baseLodash.prototype;
1785 lodash.prototype.constructor = lodash;
1787 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
1788 LodashWrapper.prototype.constructor = LodashWrapper;
1790 /*------------------------------------------------------------------------*/
1793 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1797 * @param {*} value The value to wrap.
1799 function LazyWrapper(value) {
1800 this.__wrapped__ = value;
1801 this.__actions__ = [];
1803 this.__filtered__ = false;
1804 this.__iteratees__ = [];
1805 this.__takeCount__ = MAX_ARRAY_LENGTH;
1806 this.__views__ = [];
1810 * Creates a clone of the lazy wrapper object.
1814 * @memberOf LazyWrapper
1815 * @returns {Object} Returns the cloned `LazyWrapper` object.
1817 function lazyClone() {
1818 var result = new LazyWrapper(this.__wrapped__);
1819 result.__actions__ = copyArray(this.__actions__);
1820 result.__dir__ = this.__dir__;
1821 result.__filtered__ = this.__filtered__;
1822 result.__iteratees__ = copyArray(this.__iteratees__);
1823 result.__takeCount__ = this.__takeCount__;
1824 result.__views__ = copyArray(this.__views__);
1829 * Reverses the direction of lazy iteration.
1833 * @memberOf LazyWrapper
1834 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1836 function lazyReverse() {
1837 if (this.__filtered__) {
1838 var result = new LazyWrapper(this);
1839 result.__dir__ = -1;
1840 result.__filtered__ = true;
1842 result = this.clone();
1843 result.__dir__ *= -1;
1849 * Extracts the unwrapped value from its lazy wrapper.
1853 * @memberOf LazyWrapper
1854 * @returns {*} Returns the unwrapped value.
1856 function lazyValue() {
1857 var array = this.__wrapped__.value(),
1859 isArr = isArray(array),
1861 arrLength = isArr ? array.length : 0,
1862 view = getView(0, arrLength, this.__views__),
1865 length = end - start,
1866 index = isRight ? end : (start - 1),
1867 iteratees = this.__iteratees__,
1868 iterLength = iteratees.length,
1870 takeCount = nativeMin(length, this.__takeCount__);
1872 if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
1873 (arrLength == length && takeCount == length)) {
1874 return baseWrapperValue(array, this.__actions__);
1879 while (length-- && resIndex < takeCount) {
1883 value = array[index];
1885 while (++iterIndex < iterLength) {
1886 var data = iteratees[iterIndex],
1887 iteratee = data.iteratee,
1889 computed = iteratee(value);
1891 if (type == LAZY_MAP_FLAG) {
1893 } else if (!computed) {
1894 if (type == LAZY_FILTER_FLAG) {
1901 result[resIndex++] = value;
1906 // Ensure `LazyWrapper` is an instance of `baseLodash`.
1907 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
1908 LazyWrapper.prototype.constructor = LazyWrapper;
1910 /*------------------------------------------------------------------------*/
1913 * Creates a hash object.
1917 * @param {Array} [entries] The key-value pairs to cache.
1919 function Hash(entries) {
1921 length = entries == null ? 0 : entries.length;
1924 while (++index < length) {
1925 var entry = entries[index];
1926 this.set(entry[0], entry[1]);
1931 * Removes all key-value entries from the hash.
1937 function hashClear() {
1938 this.__data__ = nativeCreate ? nativeCreate(null) : {};
1943 * Removes `key` and its value from the hash.
1948 * @param {Object} hash The hash to modify.
1949 * @param {string} key The key of the value to remove.
1950 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
1952 function hashDelete(key) {
1953 var result = this.has(key) && delete this.__data__[key];
1954 this.size -= result ? 1 : 0;
1959 * Gets the hash value for `key`.
1964 * @param {string} key The key of the value to get.
1965 * @returns {*} Returns the entry value.
1967 function hashGet(key) {
1968 var data = this.__data__;
1970 var result = data[key];
1971 return result === HASH_UNDEFINED ? undefined : result;
1973 return hasOwnProperty.call(data, key) ? data[key] : undefined;
1977 * Checks if a hash value for `key` exists.
1982 * @param {string} key The key of the entry to check.
1983 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1985 function hashHas(key) {
1986 var data = this.__data__;
1987 return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
1991 * Sets the hash `key` to `value`.
1996 * @param {string} key The key of the value to set.
1997 * @param {*} value The value to set.
1998 * @returns {Object} Returns the hash instance.
2000 function hashSet(key, value) {
2001 var data = this.__data__;
2002 this.size += this.has(key) ? 0 : 1;
2003 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
2007 // Add methods to `Hash`.
2008 Hash.prototype.clear = hashClear;
2009 Hash.prototype['delete'] = hashDelete;
2010 Hash.prototype.get = hashGet;
2011 Hash.prototype.has = hashHas;
2012 Hash.prototype.set = hashSet;
2014 /*------------------------------------------------------------------------*/
2017 * Creates an list cache object.
2021 * @param {Array} [entries] The key-value pairs to cache.
2023 function ListCache(entries) {
2025 length = entries == null ? 0 : entries.length;
2028 while (++index < length) {
2029 var entry = entries[index];
2030 this.set(entry[0], entry[1]);
2035 * Removes all key-value entries from the list cache.
2039 * @memberOf ListCache
2041 function listCacheClear() {
2047 * Removes `key` and its value from the list cache.
2051 * @memberOf ListCache
2052 * @param {string} key The key of the value to remove.
2053 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2055 function listCacheDelete(key) {
2056 var data = this.__data__,
2057 index = assocIndexOf(data, key);
2062 var lastIndex = data.length - 1;
2063 if (index == lastIndex) {
2066 splice.call(data, index, 1);
2073 * Gets the list cache value for `key`.
2077 * @memberOf ListCache
2078 * @param {string} key The key of the value to get.
2079 * @returns {*} Returns the entry value.
2081 function listCacheGet(key) {
2082 var data = this.__data__,
2083 index = assocIndexOf(data, key);
2085 return index < 0 ? undefined : data[index][1];
2089 * Checks if a list cache value for `key` exists.
2093 * @memberOf ListCache
2094 * @param {string} key The key of the entry to check.
2095 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2097 function listCacheHas(key) {
2098 return assocIndexOf(this.__data__, key) > -1;
2102 * Sets the list cache `key` to `value`.
2106 * @memberOf ListCache
2107 * @param {string} key The key of the value to set.
2108 * @param {*} value The value to set.
2109 * @returns {Object} Returns the list cache instance.
2111 function listCacheSet(key, value) {
2112 var data = this.__data__,
2113 index = assocIndexOf(data, key);
2117 data.push([key, value]);
2119 data[index][1] = value;
2124 // Add methods to `ListCache`.
2125 ListCache.prototype.clear = listCacheClear;
2126 ListCache.prototype['delete'] = listCacheDelete;
2127 ListCache.prototype.get = listCacheGet;
2128 ListCache.prototype.has = listCacheHas;
2129 ListCache.prototype.set = listCacheSet;
2131 /*------------------------------------------------------------------------*/
2134 * Creates a map cache object to store key-value pairs.
2138 * @param {Array} [entries] The key-value pairs to cache.
2140 function MapCache(entries) {
2142 length = entries == null ? 0 : entries.length;
2145 while (++index < length) {
2146 var entry = entries[index];
2147 this.set(entry[0], entry[1]);
2152 * Removes all key-value entries from the map.
2156 * @memberOf MapCache
2158 function mapCacheClear() {
2162 'map': new (Map || ListCache),
2168 * Removes `key` and its value from the map.
2172 * @memberOf MapCache
2173 * @param {string} key The key of the value to remove.
2174 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2176 function mapCacheDelete(key) {
2177 var result = getMapData(this, key)['delete'](key);
2178 this.size -= result ? 1 : 0;
2183 * Gets the map value for `key`.
2187 * @memberOf MapCache
2188 * @param {string} key The key of the value to get.
2189 * @returns {*} Returns the entry value.
2191 function mapCacheGet(key) {
2192 return getMapData(this, key).get(key);
2196 * Checks if a map value for `key` exists.
2200 * @memberOf MapCache
2201 * @param {string} key The key of the entry to check.
2202 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2204 function mapCacheHas(key) {
2205 return getMapData(this, key).has(key);
2209 * Sets the map `key` to `value`.
2213 * @memberOf MapCache
2214 * @param {string} key The key of the value to set.
2215 * @param {*} value The value to set.
2216 * @returns {Object} Returns the map cache instance.
2218 function mapCacheSet(key, value) {
2219 var data = getMapData(this, key),
2222 data.set(key, value);
2223 this.size += data.size == size ? 0 : 1;
2227 // Add methods to `MapCache`.
2228 MapCache.prototype.clear = mapCacheClear;
2229 MapCache.prototype['delete'] = mapCacheDelete;
2230 MapCache.prototype.get = mapCacheGet;
2231 MapCache.prototype.has = mapCacheHas;
2232 MapCache.prototype.set = mapCacheSet;
2234 /*------------------------------------------------------------------------*/
2238 * Creates an array cache object to store unique values.
2242 * @param {Array} [values] The values to cache.
2244 function SetCache(values) {
2246 length = values == null ? 0 : values.length;
2248 this.__data__ = new MapCache;
2249 while (++index < length) {
2250 this.add(values[index]);
2255 * Adds `value` to the array cache.
2259 * @memberOf SetCache
2261 * @param {*} value The value to cache.
2262 * @returns {Object} Returns the cache instance.
2264 function setCacheAdd(value) {
2265 this.__data__.set(value, HASH_UNDEFINED);
2270 * Checks if `value` is in the array cache.
2274 * @memberOf SetCache
2275 * @param {*} value The value to search for.
2276 * @returns {number} Returns `true` if `value` is found, else `false`.
2278 function setCacheHas(value) {
2279 return this.__data__.has(value);
2282 // Add methods to `SetCache`.
2283 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
2284 SetCache.prototype.has = setCacheHas;
2286 /*------------------------------------------------------------------------*/
2289 * Creates a stack cache object to store key-value pairs.
2293 * @param {Array} [entries] The key-value pairs to cache.
2295 function Stack(entries) {
2296 var data = this.__data__ = new ListCache(entries);
2297 this.size = data.size;
2301 * Removes all key-value entries from the stack.
2307 function stackClear() {
2308 this.__data__ = new ListCache;
2313 * Removes `key` and its value from the stack.
2318 * @param {string} key The key of the value to remove.
2319 * @returns {boolean} Returns `true` if the entry was removed, else `false`.
2321 function stackDelete(key) {
2322 var data = this.__data__,
2323 result = data['delete'](key);
2325 this.size = data.size;
2330 * Gets the stack value for `key`.
2335 * @param {string} key The key of the value to get.
2336 * @returns {*} Returns the entry value.
2338 function stackGet(key) {
2339 return this.__data__.get(key);
2343 * Checks if a stack value for `key` exists.
2348 * @param {string} key The key of the entry to check.
2349 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
2351 function stackHas(key) {
2352 return this.__data__.has(key);
2356 * Sets the stack `key` to `value`.
2361 * @param {string} key The key of the value to set.
2362 * @param {*} value The value to set.
2363 * @returns {Object} Returns the stack cache instance.
2365 function stackSet(key, value) {
2366 var data = this.__data__;
2367 if (data instanceof ListCache) {
2368 var pairs = data.__data__;
2369 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
2370 pairs.push([key, value]);
2371 this.size = ++data.size;
2374 data = this.__data__ = new MapCache(pairs);
2376 data.set(key, value);
2377 this.size = data.size;
2381 // Add methods to `Stack`.
2382 Stack.prototype.clear = stackClear;
2383 Stack.prototype['delete'] = stackDelete;
2384 Stack.prototype.get = stackGet;
2385 Stack.prototype.has = stackHas;
2386 Stack.prototype.set = stackSet;
2388 /*------------------------------------------------------------------------*/
2391 * Creates an array of the enumerable property names of the array-like `value`.
2394 * @param {*} value The value to query.
2395 * @param {boolean} inherited Specify returning inherited property names.
2396 * @returns {Array} Returns the array of property names.
2398 function arrayLikeKeys(value, inherited) {
2399 var isArr = isArray(value),
2400 isArg = !isArr && isArguments(value),
2401 isBuff = !isArr && !isArg && isBuffer(value),
2402 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
2403 skipIndexes = isArr || isArg || isBuff || isType,
2404 result = skipIndexes ? baseTimes(value.length, String) : [],
2405 length = result.length;
2407 for (var key in value) {
2408 if ((inherited || hasOwnProperty.call(value, key)) &&
2410 // Safari 9 has enumerable `arguments.length` in strict mode.
2412 // Node.js 0.10 has enumerable non-index properties on buffers.
2413 (isBuff && (key == 'offset' || key == 'parent')) ||
2414 // PhantomJS 2 has enumerable non-index properties on typed arrays.
2415 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
2416 // Skip index properties.
2417 isIndex(key, length)
2426 * A specialized version of `_.sample` for arrays.
2429 * @param {Array} array The array to sample.
2430 * @returns {*} Returns the random element.
2432 function arraySample(array) {
2433 var length = array.length;
2434 return length ? array[baseRandom(0, length - 1)] : undefined;
2438 * A specialized version of `_.sampleSize` for arrays.
2441 * @param {Array} array The array to sample.
2442 * @param {number} n The number of elements to sample.
2443 * @returns {Array} Returns the random elements.
2445 function arraySampleSize(array, n) {
2446 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
2450 * A specialized version of `_.shuffle` for arrays.
2453 * @param {Array} array The array to shuffle.
2454 * @returns {Array} Returns the new shuffled array.
2456 function arrayShuffle(array) {
2457 return shuffleSelf(copyArray(array));
2461 * Used by `_.defaults` to customize its `_.assignIn` use.
2464 * @param {*} objValue The destination value.
2465 * @param {*} srcValue The source value.
2466 * @param {string} key The key of the property to assign.
2467 * @param {Object} object The parent object of `objValue`.
2468 * @returns {*} Returns the value to assign.
2470 function assignInDefaults(objValue, srcValue, key, object) {
2471 if (objValue === undefined ||
2472 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
2479 * This function is like `assignValue` except that it doesn't assign
2480 * `undefined` values.
2483 * @param {Object} object The object to modify.
2484 * @param {string} key The key of the property to assign.
2485 * @param {*} value The value to assign.
2487 function assignMergeValue(object, key, value) {
2488 if ((value !== undefined && !eq(object[key], value)) ||
2489 (value === undefined && !(key in object))) {
2490 baseAssignValue(object, key, value);
2495 * Assigns `value` to `key` of `object` if the existing value is not equivalent
2496 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
2497 * for equality comparisons.
2500 * @param {Object} object The object to modify.
2501 * @param {string} key The key of the property to assign.
2502 * @param {*} value The value to assign.
2504 function assignValue(object, key, value) {
2505 var objValue = object[key];
2506 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
2507 (value === undefined && !(key in object))) {
2508 baseAssignValue(object, key, value);
2513 * Gets the index at which the `key` is found in `array` of key-value pairs.
2516 * @param {Array} array The array to inspect.
2517 * @param {*} key The key to search for.
2518 * @returns {number} Returns the index of the matched value, else `-1`.
2520 function assocIndexOf(array, key) {
2521 var length = array.length;
2523 if (eq(array[length][0], key)) {
2531 * Aggregates elements of `collection` on `accumulator` with keys transformed
2532 * by `iteratee` and values set by `setter`.
2535 * @param {Array|Object} collection The collection to iterate over.
2536 * @param {Function} setter The function to set `accumulator` values.
2537 * @param {Function} iteratee The iteratee to transform keys.
2538 * @param {Object} accumulator The initial aggregated object.
2539 * @returns {Function} Returns `accumulator`.
2541 function baseAggregator(collection, setter, iteratee, accumulator) {
2542 baseEach(collection, function(value, key, collection) {
2543 setter(accumulator, value, iteratee(value), collection);
2549 * The base implementation of `_.assign` without support for multiple sources
2550 * or `customizer` functions.
2553 * @param {Object} object The destination object.
2554 * @param {Object} source The source object.
2555 * @returns {Object} Returns `object`.
2557 function baseAssign(object, source) {
2558 return object && copyObject(source, keys(source), object);
2562 * The base implementation of `assignValue` and `assignMergeValue` without
2566 * @param {Object} object The object to modify.
2567 * @param {string} key The key of the property to assign.
2568 * @param {*} value The value to assign.
2570 function baseAssignValue(object, key, value) {
2571 if (key == '__proto__' && defineProperty) {
2572 defineProperty(object, key, {
2573 'configurable': true,
2579 object[key] = value;
2584 * The base implementation of `_.at` without support for individual paths.
2587 * @param {Object} object The object to iterate over.
2588 * @param {string[]} paths The property paths of elements to pick.
2589 * @returns {Array} Returns the picked elements.
2591 function baseAt(object, paths) {
2593 length = paths.length,
2594 result = Array(length),
2595 skip = object == null;
2597 while (++index < length) {
2598 result[index] = skip ? undefined : get(object, paths[index]);
2604 * The base implementation of `_.clamp` which doesn't coerce arguments.
2607 * @param {number} number The number to clamp.
2608 * @param {number} [lower] The lower bound.
2609 * @param {number} upper The upper bound.
2610 * @returns {number} Returns the clamped number.
2612 function baseClamp(number, lower, upper) {
2613 if (number === number) {
2614 if (upper !== undefined) {
2615 number = number <= upper ? number : upper;
2617 if (lower !== undefined) {
2618 number = number >= lower ? number : lower;
2625 * The base implementation of `_.clone` and `_.cloneDeep` which tracks
2626 * traversed objects.
2629 * @param {*} value The value to clone.
2630 * @param {boolean} [isDeep] Specify a deep clone.
2631 * @param {boolean} [isFull] Specify a clone including symbols.
2632 * @param {Function} [customizer] The function to customize cloning.
2633 * @param {string} [key] The key of `value`.
2634 * @param {Object} [object] The parent object of `value`.
2635 * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
2636 * @returns {*} Returns the cloned value.
2638 function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
2641 result = object ? customizer(value, key, object, stack) : customizer(value);
2643 if (result !== undefined) {
2646 if (!isObject(value)) {
2649 var isArr = isArray(value);
2651 result = initCloneArray(value);
2653 return copyArray(value, result);
2656 var tag = getTag(value),
2657 isFunc = tag == funcTag || tag == genTag;
2659 if (isBuffer(value)) {
2660 return cloneBuffer(value, isDeep);
2662 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2663 result = initCloneObject(isFunc ? {} : value);
2665 return copySymbols(value, baseAssign(result, value));
2668 if (!cloneableTags[tag]) {
2669 return object ? value : {};
2671 result = initCloneByTag(value, tag, baseClone, isDeep);
2674 // Check for circular references and return its corresponding clone.
2675 stack || (stack = new Stack);
2676 var stacked = stack.get(value);
2680 stack.set(value, result);
2682 var props = isArr ? undefined : (isFull ? getAllKeys : keys)(value);
2683 arrayEach(props || value, function(subValue, key) {
2686 subValue = value[key];
2688 // Recursively populate clone (susceptible to call stack limits).
2689 assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
2695 * The base implementation of `_.conforms` which doesn't clone `source`.
2698 * @param {Object} source The object of property predicates to conform to.
2699 * @returns {Function} Returns the new spec function.
2701 function baseConforms(source) {
2702 var props = keys(source);
2703 return function(object) {
2704 return baseConformsTo(object, source, props);
2709 * The base implementation of `_.conformsTo` which accepts `props` to check.
2712 * @param {Object} object The object to inspect.
2713 * @param {Object} source The object of property predicates to conform to.
2714 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
2716 function baseConformsTo(object, source, props) {
2717 var length = props.length;
2718 if (object == null) {
2721 object = Object(object);
2723 var key = props[length],
2724 predicate = source[key],
2725 value = object[key];
2727 if ((value === undefined && !(key in object)) || !predicate(value)) {
2735 * The base implementation of `_.delay` and `_.defer` which accepts `args`
2736 * to provide to `func`.
2739 * @param {Function} func The function to delay.
2740 * @param {number} wait The number of milliseconds to delay invocation.
2741 * @param {Array} args The arguments to provide to `func`.
2742 * @returns {number|Object} Returns the timer id or timeout object.
2744 function baseDelay(func, wait, args) {
2745 if (typeof func != 'function') {
2746 throw new TypeError(FUNC_ERROR_TEXT);
2748 return setTimeout(function() { func.apply(undefined, args); }, wait);
2752 * The base implementation of methods like `_.difference` without support
2753 * for excluding multiple arrays or iteratee shorthands.
2756 * @param {Array} array The array to inspect.
2757 * @param {Array} values The values to exclude.
2758 * @param {Function} [iteratee] The iteratee invoked per element.
2759 * @param {Function} [comparator] The comparator invoked per element.
2760 * @returns {Array} Returns the new array of filtered values.
2762 function baseDifference(array, values, iteratee, comparator) {
2764 includes = arrayIncludes,
2766 length = array.length,
2768 valuesLength = values.length;
2774 values = arrayMap(values, baseUnary(iteratee));
2777 includes = arrayIncludesWith;
2780 else if (values.length >= LARGE_ARRAY_SIZE) {
2781 includes = cacheHas;
2783 values = new SetCache(values);
2786 while (++index < length) {
2787 var value = array[index],
2788 computed = iteratee == null ? value : iteratee(value);
2790 value = (comparator || value !== 0) ? value : 0;
2791 if (isCommon && computed === computed) {
2792 var valuesIndex = valuesLength;
2793 while (valuesIndex--) {
2794 if (values[valuesIndex] === computed) {
2800 else if (!includes(values, computed, comparator)) {
2808 * The base implementation of `_.forEach` without support for iteratee shorthands.
2811 * @param {Array|Object} collection The collection to iterate over.
2812 * @param {Function} iteratee The function invoked per iteration.
2813 * @returns {Array|Object} Returns `collection`.
2815 var baseEach = createBaseEach(baseForOwn);
2818 * The base implementation of `_.forEachRight` without support for iteratee shorthands.
2821 * @param {Array|Object} collection The collection to iterate over.
2822 * @param {Function} iteratee The function invoked per iteration.
2823 * @returns {Array|Object} Returns `collection`.
2825 var baseEachRight = createBaseEach(baseForOwnRight, true);
2828 * The base implementation of `_.every` without support for iteratee shorthands.
2831 * @param {Array|Object} collection The collection to iterate over.
2832 * @param {Function} predicate The function invoked per iteration.
2833 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2836 function baseEvery(collection, predicate) {
2838 baseEach(collection, function(value, index, collection) {
2839 result = !!predicate(value, index, collection);
2846 * The base implementation of methods like `_.max` and `_.min` which accepts a
2847 * `comparator` to determine the extremum value.
2850 * @param {Array} array The array to iterate over.
2851 * @param {Function} iteratee The iteratee invoked per iteration.
2852 * @param {Function} comparator The comparator used to compare values.
2853 * @returns {*} Returns the extremum value.
2855 function baseExtremum(array, iteratee, comparator) {
2857 length = array.length;
2859 while (++index < length) {
2860 var value = array[index],
2861 current = iteratee(value);
2863 if (current != null && (computed === undefined
2864 ? (current === current && !isSymbol(current))
2865 : comparator(current, computed)
2867 var computed = current,
2875 * The base implementation of `_.fill` without an iteratee call guard.
2878 * @param {Array} array The array to fill.
2879 * @param {*} value The value to fill `array` with.
2880 * @param {number} [start=0] The start position.
2881 * @param {number} [end=array.length] The end position.
2882 * @returns {Array} Returns `array`.
2884 function baseFill(array, value, start, end) {
2885 var length = array.length;
2887 start = toInteger(start);
2889 start = -start > length ? 0 : (length + start);
2891 end = (end === undefined || end > length) ? length : toInteger(end);
2895 end = start > end ? 0 : toLength(end);
2896 while (start < end) {
2897 array[start++] = value;
2903 * The base implementation of `_.filter` without support for iteratee shorthands.
2906 * @param {Array|Object} collection The collection to iterate over.
2907 * @param {Function} predicate The function invoked per iteration.
2908 * @returns {Array} Returns the new filtered array.
2910 function baseFilter(collection, predicate) {
2912 baseEach(collection, function(value, index, collection) {
2913 if (predicate(value, index, collection)) {
2921 * The base implementation of `_.flatten` with support for restricting flattening.
2924 * @param {Array} array The array to flatten.
2925 * @param {number} depth The maximum recursion depth.
2926 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
2927 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
2928 * @param {Array} [result=[]] The initial result value.
2929 * @returns {Array} Returns the new flattened array.
2931 function baseFlatten(array, depth, predicate, isStrict, result) {
2933 length = array.length;
2935 predicate || (predicate = isFlattenable);
2936 result || (result = []);
2938 while (++index < length) {
2939 var value = array[index];
2940 if (depth > 0 && predicate(value)) {
2942 // Recursively flatten arrays (susceptible to call stack limits).
2943 baseFlatten(value, depth - 1, predicate, isStrict, result);
2945 arrayPush(result, value);
2947 } else if (!isStrict) {
2948 result[result.length] = value;
2955 * The base implementation of `baseForOwn` which iterates over `object`
2956 * properties returned by `keysFunc` and invokes `iteratee` for each property.
2957 * Iteratee functions may exit iteration early by explicitly returning `false`.
2960 * @param {Object} object The object to iterate over.
2961 * @param {Function} iteratee The function invoked per iteration.
2962 * @param {Function} keysFunc The function to get the keys of `object`.
2963 * @returns {Object} Returns `object`.
2965 var baseFor = createBaseFor();
2968 * This function is like `baseFor` except that it iterates over properties
2969 * in the opposite order.
2972 * @param {Object} object The object to iterate over.
2973 * @param {Function} iteratee The function invoked per iteration.
2974 * @param {Function} keysFunc The function to get the keys of `object`.
2975 * @returns {Object} Returns `object`.
2977 var baseForRight = createBaseFor(true);
2980 * The base implementation of `_.forOwn` without support for iteratee shorthands.
2983 * @param {Object} object The object to iterate over.
2984 * @param {Function} iteratee The function invoked per iteration.
2985 * @returns {Object} Returns `object`.
2987 function baseForOwn(object, iteratee) {
2988 return object && baseFor(object, iteratee, keys);
2992 * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
2995 * @param {Object} object The object to iterate over.
2996 * @param {Function} iteratee The function invoked per iteration.
2997 * @returns {Object} Returns `object`.
2999 function baseForOwnRight(object, iteratee) {
3000 return object && baseForRight(object, iteratee, keys);
3004 * The base implementation of `_.functions` which creates an array of
3005 * `object` function property names filtered from `props`.
3008 * @param {Object} object The object to inspect.
3009 * @param {Array} props The property names to filter.
3010 * @returns {Array} Returns the function names.
3012 function baseFunctions(object, props) {
3013 return arrayFilter(props, function(key) {
3014 return isFunction(object[key]);
3019 * The base implementation of `_.get` without support for default values.
3022 * @param {Object} object The object to query.
3023 * @param {Array|string} path The path of the property to get.
3024 * @returns {*} Returns the resolved value.
3026 function baseGet(object, path) {
3027 path = isKey(path, object) ? [path] : castPath(path);
3030 length = path.length;
3032 while (object != null && index < length) {
3033 object = object[toKey(path[index++])];
3035 return (index && index == length) ? object : undefined;
3039 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
3040 * `keysFunc` and `symbolsFunc` to get the enumerable property names and
3041 * symbols of `object`.
3044 * @param {Object} object The object to query.
3045 * @param {Function} keysFunc The function to get the keys of `object`.
3046 * @param {Function} symbolsFunc The function to get the symbols of `object`.
3047 * @returns {Array} Returns the array of property names and symbols.
3049 function baseGetAllKeys(object, keysFunc, symbolsFunc) {
3050 var result = keysFunc(object);
3051 return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
3055 * The base implementation of `getTag` without fallbacks for buggy environments.
3058 * @param {*} value The value to query.
3059 * @returns {string} Returns the `toStringTag`.
3061 function baseGetTag(value) {
3062 if (value == null) {
3063 return value === undefined ? undefinedTag : nullTag;
3065 value = Object(value);
3066 return (symToStringTag && symToStringTag in value)
3068 : objectToString(value);
3072 * The base implementation of `_.gt` which doesn't coerce arguments.
3075 * @param {*} value The value to compare.
3076 * @param {*} other The other value to compare.
3077 * @returns {boolean} Returns `true` if `value` is greater than `other`,
3080 function baseGt(value, other) {
3081 return value > other;
3085 * The base implementation of `_.has` without support for deep paths.
3088 * @param {Object} [object] The object to query.
3089 * @param {Array|string} key The key to check.
3090 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3092 function baseHas(object, key) {
3093 return object != null && hasOwnProperty.call(object, key);
3097 * The base implementation of `_.hasIn` without support for deep paths.
3100 * @param {Object} [object] The object to query.
3101 * @param {Array|string} key The key to check.
3102 * @returns {boolean} Returns `true` if `key` exists, else `false`.
3104 function baseHasIn(object, key) {
3105 return object != null && key in Object(object);
3109 * The base implementation of `_.inRange` which doesn't coerce arguments.
3112 * @param {number} number The number to check.
3113 * @param {number} start The start of the range.
3114 * @param {number} end The end of the range.
3115 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
3117 function baseInRange(number, start, end) {
3118 return number >= nativeMin(start, end) && number < nativeMax(start, end);
3122 * The base implementation of methods like `_.intersection`, without support
3123 * for iteratee shorthands, that accepts an array of arrays to inspect.
3126 * @param {Array} arrays The arrays to inspect.
3127 * @param {Function} [iteratee] The iteratee invoked per element.
3128 * @param {Function} [comparator] The comparator invoked per element.
3129 * @returns {Array} Returns the new array of shared values.
3131 function baseIntersection(arrays, iteratee, comparator) {
3132 var includes = comparator ? arrayIncludesWith : arrayIncludes,
3133 length = arrays[0].length,
3134 othLength = arrays.length,
3135 othIndex = othLength,
3136 caches = Array(othLength),
3137 maxLength = Infinity,
3140 while (othIndex--) {
3141 var array = arrays[othIndex];
3142 if (othIndex && iteratee) {
3143 array = arrayMap(array, baseUnary(iteratee));
3145 maxLength = nativeMin(array.length, maxLength);
3146 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
3147 ? new SetCache(othIndex && array)
3156 while (++index < length && result.length < maxLength) {
3157 var value = array[index],
3158 computed = iteratee ? iteratee(value) : value;
3160 value = (comparator || value !== 0) ? value : 0;
3162 ? cacheHas(seen, computed)
3163 : includes(result, computed, comparator)
3165 othIndex = othLength;
3166 while (--othIndex) {
3167 var cache = caches[othIndex];
3169 ? cacheHas(cache, computed)
3170 : includes(arrays[othIndex], computed, comparator))
3176 seen.push(computed);
3185 * The base implementation of `_.invert` and `_.invertBy` which inverts
3186 * `object` with values transformed by `iteratee` and set by `setter`.
3189 * @param {Object} object The object to iterate over.
3190 * @param {Function} setter The function to set `accumulator` values.
3191 * @param {Function} iteratee The iteratee to transform values.
3192 * @param {Object} accumulator The initial inverted object.
3193 * @returns {Function} Returns `accumulator`.
3195 function baseInverter(object, setter, iteratee, accumulator) {
3196 baseForOwn(object, function(value, key, object) {
3197 setter(accumulator, iteratee(value), key, object);
3203 * The base implementation of `_.invoke` without support for individual
3207 * @param {Object} object The object to query.
3208 * @param {Array|string} path The path of the method to invoke.
3209 * @param {Array} args The arguments to invoke the method with.
3210 * @returns {*} Returns the result of the invoked method.
3212 function baseInvoke(object, path, args) {
3213 if (!isKey(path, object)) {
3214 path = castPath(path);
3215 object = parent(object, path);
3218 var func = object == null ? object : object[toKey(path)];
3219 return func == null ? undefined : apply(func, object, args);
3223 * The base implementation of `_.isArguments`.
3226 * @param {*} value The value to check.
3227 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
3229 function baseIsArguments(value) {
3230 return isObjectLike(value) && baseGetTag(value) == argsTag;
3234 * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
3237 * @param {*} value The value to check.
3238 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
3240 function baseIsArrayBuffer(value) {
3241 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
3245 * The base implementation of `_.isDate` without Node.js optimizations.
3248 * @param {*} value The value to check.
3249 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
3251 function baseIsDate(value) {
3252 return isObjectLike(value) && baseGetTag(value) == dateTag;
3256 * The base implementation of `_.isEqual` which supports partial comparisons
3257 * and tracks traversed objects.
3260 * @param {*} value The value to compare.
3261 * @param {*} other The other value to compare.
3262 * @param {Function} [customizer] The function to customize comparisons.
3263 * @param {boolean} [bitmask] The bitmask of comparison flags.
3264 * The bitmask may be composed of the following flags:
3265 * 1 - Unordered comparison
3266 * 2 - Partial comparison
3267 * @param {Object} [stack] Tracks traversed `value` and `other` objects.
3268 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3270 function baseIsEqual(value, other, customizer, bitmask, stack) {
3271 if (value === other) {
3274 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
3275 return value !== value && other !== other;
3277 return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
3281 * A specialized version of `baseIsEqual` for arrays and objects which performs
3282 * deep comparisons and tracks traversed objects enabling objects with circular
3283 * references to be compared.
3286 * @param {Object} object The object to compare.
3287 * @param {Object} other The other object to compare.
3288 * @param {Function} equalFunc The function to determine equivalents of values.
3289 * @param {Function} [customizer] The function to customize comparisons.
3290 * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
3292 * @param {Object} [stack] Tracks traversed `object` and `other` objects.
3293 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3295 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
3296 var objIsArr = isArray(object),
3297 othIsArr = isArray(other),
3302 objTag = getTag(object);
3303 objTag = objTag == argsTag ? objectTag : objTag;
3306 othTag = getTag(other);
3307 othTag = othTag == argsTag ? objectTag : othTag;
3309 var objIsObj = objTag == objectTag,
3310 othIsObj = othTag == objectTag,
3311 isSameTag = objTag == othTag;
3313 if (isSameTag && isBuffer(object)) {
3314 if (!isBuffer(other)) {
3320 if (isSameTag && !objIsObj) {
3321 stack || (stack = new Stack);
3322 return (objIsArr || isTypedArray(object))
3323 ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
3324 : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
3326 if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
3327 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
3328 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
3330 if (objIsWrapped || othIsWrapped) {
3331 var objUnwrapped = objIsWrapped ? object.value() : object,
3332 othUnwrapped = othIsWrapped ? other.value() : other;
3334 stack || (stack = new Stack);
3335 return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
3341 stack || (stack = new Stack);
3342 return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
3346 * The base implementation of `_.isMap` without Node.js optimizations.
3349 * @param {*} value The value to check.
3350 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
3352 function baseIsMap(value) {
3353 return isObjectLike(value) && getTag(value) == mapTag;
3357 * The base implementation of `_.isMatch` without support for iteratee shorthands.
3360 * @param {Object} object The object to inspect.
3361 * @param {Object} source The object of property values to match.
3362 * @param {Array} matchData The property names, values, and compare flags to match.
3363 * @param {Function} [customizer] The function to customize comparisons.
3364 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
3366 function baseIsMatch(object, source, matchData, customizer) {
3367 var index = matchData.length,
3369 noCustomizer = !customizer;
3371 if (object == null) {
3374 object = Object(object);
3376 var data = matchData[index];
3377 if ((noCustomizer && data[2])
3378 ? data[1] !== object[data[0]]
3379 : !(data[0] in object)
3384 while (++index < length) {
3385 data = matchData[index];
3387 objValue = object[key],
3390 if (noCustomizer && data[2]) {
3391 if (objValue === undefined && !(key in object)) {
3395 var stack = new Stack;
3397 var result = customizer(objValue, srcValue, key, object, source, stack);
3399 if (!(result === undefined
3400 ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
3411 * The base implementation of `_.isNative` without bad shim checks.
3414 * @param {*} value The value to check.
3415 * @returns {boolean} Returns `true` if `value` is a native function,
3418 function baseIsNative(value) {
3419 if (!isObject(value) || isMasked(value)) {
3422 var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3423 return pattern.test(toSource(value));
3427 * The base implementation of `_.isRegExp` without Node.js optimizations.
3430 * @param {*} value The value to check.
3431 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
3433 function baseIsRegExp(value) {
3434 return isObjectLike(value) && baseGetTag(value) == regexpTag;
3438 * The base implementation of `_.isSet` without Node.js optimizations.
3441 * @param {*} value The value to check.
3442 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
3444 function baseIsSet(value) {
3445 return isObjectLike(value) && getTag(value) == setTag;
3449 * The base implementation of `_.isTypedArray` without Node.js optimizations.
3452 * @param {*} value The value to check.
3453 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
3455 function baseIsTypedArray(value) {
3456 return isObjectLike(value) &&
3457 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
3461 * The base implementation of `_.iteratee`.
3464 * @param {*} [value=_.identity] The value to convert to an iteratee.
3465 * @returns {Function} Returns the iteratee.
3467 function baseIteratee(value) {
3468 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
3469 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
3470 if (typeof value == 'function') {
3473 if (value == null) {
3476 if (typeof value == 'object') {
3477 return isArray(value)
3478 ? baseMatchesProperty(value[0], value[1])
3479 : baseMatches(value);
3481 return property(value);
3485 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
3488 * @param {Object} object The object to query.
3489 * @returns {Array} Returns the array of property names.
3491 function baseKeys(object) {
3492 if (!isPrototype(object)) {
3493 return nativeKeys(object);
3496 for (var key in Object(object)) {
3497 if (hasOwnProperty.call(object, key) && key != 'constructor') {
3505 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
3508 * @param {Object} object The object to query.
3509 * @returns {Array} Returns the array of property names.
3511 function baseKeysIn(object) {
3512 if (!isObject(object)) {
3513 return nativeKeysIn(object);
3515 var isProto = isPrototype(object),
3518 for (var key in object) {
3519 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
3527 * The base implementation of `_.lt` which doesn't coerce arguments.
3530 * @param {*} value The value to compare.
3531 * @param {*} other The other value to compare.
3532 * @returns {boolean} Returns `true` if `value` is less than `other`,
3535 function baseLt(value, other) {
3536 return value < other;
3540 * The base implementation of `_.map` without support for iteratee shorthands.
3543 * @param {Array|Object} collection The collection to iterate over.
3544 * @param {Function} iteratee The function invoked per iteration.
3545 * @returns {Array} Returns the new mapped array.
3547 function baseMap(collection, iteratee) {
3549 result = isArrayLike(collection) ? Array(collection.length) : [];
3551 baseEach(collection, function(value, key, collection) {
3552 result[++index] = iteratee(value, key, collection);
3558 * The base implementation of `_.matches` which doesn't clone `source`.
3561 * @param {Object} source The object of property values to match.
3562 * @returns {Function} Returns the new spec function.
3564 function baseMatches(source) {
3565 var matchData = getMatchData(source);
3566 if (matchData.length == 1 && matchData[0][2]) {
3567 return matchesStrictComparable(matchData[0][0], matchData[0][1]);
3569 return function(object) {
3570 return object === source || baseIsMatch(object, source, matchData);
3575 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
3578 * @param {string} path The path of the property to get.
3579 * @param {*} srcValue The value to match.
3580 * @returns {Function} Returns the new spec function.
3582 function baseMatchesProperty(path, srcValue) {
3583 if (isKey(path) && isStrictComparable(srcValue)) {
3584 return matchesStrictComparable(toKey(path), srcValue);
3586 return function(object) {
3587 var objValue = get(object, path);
3588 return (objValue === undefined && objValue === srcValue)
3589 ? hasIn(object, path)
3590 : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
3595 * The base implementation of `_.merge` without support for multiple sources.
3598 * @param {Object} object The destination object.
3599 * @param {Object} source The source object.
3600 * @param {number} srcIndex The index of `source`.
3601 * @param {Function} [customizer] The function to customize merged values.
3602 * @param {Object} [stack] Tracks traversed source values and their merged
3605 function baseMerge(object, source, srcIndex, customizer, stack) {
3606 if (object === source) {
3609 baseFor(source, function(srcValue, key) {
3610 if (isObject(srcValue)) {
3611 stack || (stack = new Stack);
3612 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3615 var newValue = customizer
3616 ? customizer(object[key], srcValue, (key + ''), object, source, stack)
3619 if (newValue === undefined) {
3620 newValue = srcValue;
3622 assignMergeValue(object, key, newValue);
3628 * A specialized version of `baseMerge` for arrays and objects which performs
3629 * deep merges and tracks traversed objects enabling objects with circular
3630 * references to be merged.
3633 * @param {Object} object The destination object.
3634 * @param {Object} source The source object.
3635 * @param {string} key The key of the value to merge.
3636 * @param {number} srcIndex The index of `source`.
3637 * @param {Function} mergeFunc The function to merge values.
3638 * @param {Function} [customizer] The function to customize assigned values.
3639 * @param {Object} [stack] Tracks traversed source values and their merged
3642 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3643 var objValue = object[key],
3644 srcValue = source[key],
3645 stacked = stack.get(srcValue);
3648 assignMergeValue(object, key, stacked);
3651 var newValue = customizer
3652 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3655 var isCommon = newValue === undefined;
3658 var isArr = isArray(srcValue),
3659 isBuff = !isArr && isBuffer(srcValue),
3660 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3662 newValue = srcValue;
3663 if (isArr || isBuff || isTyped) {
3664 if (isArray(objValue)) {
3665 newValue = objValue;
3667 else if (isArrayLikeObject(objValue)) {
3668 newValue = copyArray(objValue);
3672 newValue = cloneBuffer(srcValue, true);
3676 newValue = cloneTypedArray(srcValue, true);
3682 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3683 newValue = objValue;
3684 if (isArguments(objValue)) {
3685 newValue = toPlainObject(objValue);
3687 else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
3688 newValue = initCloneObject(srcValue);
3696 // Recursively merge objects and arrays (susceptible to call stack limits).
3697 stack.set(srcValue, newValue);
3698 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3699 stack['delete'](srcValue);
3701 assignMergeValue(object, key, newValue);
3705 * The base implementation of `_.nth` which doesn't coerce arguments.
3708 * @param {Array} array The array to query.
3709 * @param {number} n The index of the element to return.
3710 * @returns {*} Returns the nth element of `array`.
3712 function baseNth(array, n) {
3713 var length = array.length;
3717 n += n < 0 ? length : 0;
3718 return isIndex(n, length) ? array[n] : undefined;
3722 * The base implementation of `_.orderBy` without param guards.
3725 * @param {Array|Object} collection The collection to iterate over.
3726 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
3727 * @param {string[]} orders The sort orders of `iteratees`.
3728 * @returns {Array} Returns the new sorted array.
3730 function baseOrderBy(collection, iteratees, orders) {
3732 iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
3734 var result = baseMap(collection, function(value, key, collection) {
3735 var criteria = arrayMap(iteratees, function(iteratee) {
3736 return iteratee(value);
3738 return { 'criteria': criteria, 'index': ++index, 'value': value };
3741 return baseSortBy(result, function(object, other) {
3742 return compareMultiple(object, other, orders);
3747 * The base implementation of `_.pick` without support for individual
3748 * property identifiers.
3751 * @param {Object} object The source object.
3752 * @param {string[]} props The property identifiers to pick.
3753 * @returns {Object} Returns the new object.
3755 function basePick(object, props) {
3756 object = Object(object);
3757 return basePickBy(object, props, function(value, key) {
3758 return key in object;
3763 * The base implementation of `_.pickBy` without support for iteratee shorthands.
3766 * @param {Object} object The source object.
3767 * @param {string[]} props The property identifiers to pick from.
3768 * @param {Function} predicate The function invoked per property.
3769 * @returns {Object} Returns the new object.
3771 function basePickBy(object, props, predicate) {
3773 length = props.length,
3776 while (++index < length) {
3777 var key = props[index],
3778 value = object[key];
3780 if (predicate(value, key)) {
3781 baseAssignValue(result, key, value);
3788 * A specialized version of `baseProperty` which supports deep paths.
3791 * @param {Array|string} path The path of the property to get.
3792 * @returns {Function} Returns the new accessor function.
3794 function basePropertyDeep(path) {
3795 return function(object) {
3796 return baseGet(object, path);
3801 * The base implementation of `_.pullAllBy` without support for iteratee
3805 * @param {Array} array The array to modify.
3806 * @param {Array} values The values to remove.
3807 * @param {Function} [iteratee] The iteratee invoked per element.
3808 * @param {Function} [comparator] The comparator invoked per element.
3809 * @returns {Array} Returns `array`.
3811 function basePullAll(array, values, iteratee, comparator) {
3812 var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
3814 length = values.length,
3817 if (array === values) {
3818 values = copyArray(values);
3821 seen = arrayMap(array, baseUnary(iteratee));
3823 while (++index < length) {
3825 value = values[index],
3826 computed = iteratee ? iteratee(value) : value;
3828 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
3829 if (seen !== array) {
3830 splice.call(seen, fromIndex, 1);
3832 splice.call(array, fromIndex, 1);
3839 * The base implementation of `_.pullAt` without support for individual
3840 * indexes or capturing the removed elements.
3843 * @param {Array} array The array to modify.
3844 * @param {number[]} indexes The indexes of elements to remove.
3845 * @returns {Array} Returns `array`.
3847 function basePullAt(array, indexes) {
3848 var length = array ? indexes.length : 0,
3849 lastIndex = length - 1;
3852 var index = indexes[length];
3853 if (length == lastIndex || index !== previous) {
3854 var previous = index;
3855 if (isIndex(index)) {
3856 splice.call(array, index, 1);
3858 else if (!isKey(index, array)) {
3859 var path = castPath(index),
3860 object = parent(array, path);
3862 if (object != null) {
3863 delete object[toKey(last(path))];
3867 delete array[toKey(index)];
3875 * The base implementation of `_.random` without support for returning
3876 * floating-point numbers.
3879 * @param {number} lower The lower bound.
3880 * @param {number} upper The upper bound.
3881 * @returns {number} Returns the random number.
3883 function baseRandom(lower, upper) {
3884 return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
3888 * The base implementation of `_.range` and `_.rangeRight` which doesn't
3892 * @param {number} start The start of the range.
3893 * @param {number} end The end of the range.
3894 * @param {number} step The value to increment or decrement by.
3895 * @param {boolean} [fromRight] Specify iterating from right to left.
3896 * @returns {Array} Returns the range of numbers.
3898 function baseRange(start, end, step, fromRight) {
3900 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
3901 result = Array(length);
3904 result[fromRight ? length : ++index] = start;
3911 * The base implementation of `_.repeat` which doesn't coerce arguments.
3914 * @param {string} string The string to repeat.
3915 * @param {number} n The number of times to repeat the string.
3916 * @returns {string} Returns the repeated string.
3918 function baseRepeat(string, n) {
3920 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
3923 // Leverage the exponentiation by squaring algorithm for a faster repeat.
3924 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
3929 n = nativeFloor(n / 2);
3939 * The base implementation of `_.rest` which doesn't validate or coerce arguments.
3942 * @param {Function} func The function to apply a rest parameter to.
3943 * @param {number} [start=func.length-1] The start position of the rest parameter.
3944 * @returns {Function} Returns the new function.
3946 function baseRest(func, start) {
3947 return setToString(overRest(func, start, identity), func + '');
3951 * The base implementation of `_.sample`.
3954 * @param {Array|Object} collection The collection to sample.
3955 * @returns {*} Returns the random element.
3957 function baseSample(collection) {
3958 return arraySample(values(collection));
3962 * The base implementation of `_.sampleSize` without param guards.
3965 * @param {Array|Object} collection The collection to sample.
3966 * @param {number} n The number of elements to sample.
3967 * @returns {Array} Returns the random elements.
3969 function baseSampleSize(collection, n) {
3970 var array = values(collection);
3971 return shuffleSelf(array, baseClamp(n, 0, array.length));
3975 * The base implementation of `_.set`.
3978 * @param {Object} object The object to modify.
3979 * @param {Array|string} path The path of the property to set.
3980 * @param {*} value The value to set.
3981 * @param {Function} [customizer] The function to customize path creation.
3982 * @returns {Object} Returns `object`.
3984 function baseSet(object, path, value, customizer) {
3985 if (!isObject(object)) {
3988 path = isKey(path, object) ? [path] : castPath(path);
3991 length = path.length,
3992 lastIndex = length - 1,
3995 while (nested != null && ++index < length) {
3996 var key = toKey(path[index]),
3999 if (index != lastIndex) {
4000 var objValue = nested[key];
4001 newValue = customizer ? customizer(objValue, key, nested) : undefined;
4002 if (newValue === undefined) {
4003 newValue = isObject(objValue)
4005 : (isIndex(path[index + 1]) ? [] : {});
4008 assignValue(nested, key, newValue);
4009 nested = nested[key];
4015 * The base implementation of `setData` without support for hot loop shorting.
4018 * @param {Function} func The function to associate metadata with.
4019 * @param {*} data The metadata.
4020 * @returns {Function} Returns `func`.
4022 var baseSetData = !metaMap ? identity : function(func, data) {
4023 metaMap.set(func, data);
4028 * The base implementation of `setToString` without support for hot loop shorting.
4031 * @param {Function} func The function to modify.
4032 * @param {Function} string The `toString` result.
4033 * @returns {Function} Returns `func`.
4035 var baseSetToString = !defineProperty ? identity : function(func, string) {
4036 return defineProperty(func, 'toString', {
4037 'configurable': true,
4038 'enumerable': false,
4039 'value': constant(string),
4045 * The base implementation of `_.shuffle`.
4048 * @param {Array|Object} collection The collection to shuffle.
4049 * @returns {Array} Returns the new shuffled array.
4051 function baseShuffle(collection) {
4052 return shuffleSelf(values(collection));
4056 * The base implementation of `_.slice` without an iteratee call guard.
4059 * @param {Array} array The array to slice.
4060 * @param {number} [start=0] The start position.
4061 * @param {number} [end=array.length] The end position.
4062 * @returns {Array} Returns the slice of `array`.
4064 function baseSlice(array, start, end) {
4066 length = array.length;
4069 start = -start > length ? 0 : (length + start);
4071 end = end > length ? length : end;
4075 length = start > end ? 0 : ((end - start) >>> 0);
4078 var result = Array(length);
4079 while (++index < length) {
4080 result[index] = array[index + start];
4086 * The base implementation of `_.some` without support for iteratee shorthands.
4089 * @param {Array|Object} collection The collection to iterate over.
4090 * @param {Function} predicate The function invoked per iteration.
4091 * @returns {boolean} Returns `true` if any element passes the predicate check,
4094 function baseSome(collection, predicate) {
4097 baseEach(collection, function(value, index, collection) {
4098 result = predicate(value, index, collection);
4105 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
4106 * performs a binary search of `array` to determine the index at which `value`
4107 * should be inserted into `array` in order to maintain its sort order.
4110 * @param {Array} array The sorted array to inspect.
4111 * @param {*} value The value to evaluate.
4112 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4113 * @returns {number} Returns the index at which `value` should be inserted
4116 function baseSortedIndex(array, value, retHighest) {
4118 high = array == null ? low : array.length;
4120 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
4121 while (low < high) {
4122 var mid = (low + high) >>> 1,
4123 computed = array[mid];
4125 if (computed !== null && !isSymbol(computed) &&
4126 (retHighest ? (computed <= value) : (computed < value))) {
4134 return baseSortedIndexBy(array, value, identity, retHighest);
4138 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
4139 * which invokes `iteratee` for `value` and each element of `array` to compute
4140 * their sort ranking. The iteratee is invoked with one argument; (value).
4143 * @param {Array} array The sorted array to inspect.
4144 * @param {*} value The value to evaluate.
4145 * @param {Function} iteratee The iteratee invoked per element.
4146 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4147 * @returns {number} Returns the index at which `value` should be inserted
4150 function baseSortedIndexBy(array, value, iteratee, retHighest) {
4151 value = iteratee(value);
4154 high = array == null ? 0 : array.length,
4155 valIsNaN = value !== value,
4156 valIsNull = value === null,
4157 valIsSymbol = isSymbol(value),
4158 valIsUndefined = value === undefined;
4160 while (low < high) {
4161 var mid = nativeFloor((low + high) / 2),
4162 computed = iteratee(array[mid]),
4163 othIsDefined = computed !== undefined,
4164 othIsNull = computed === null,
4165 othIsReflexive = computed === computed,
4166 othIsSymbol = isSymbol(computed);
4169 var setLow = retHighest || othIsReflexive;
4170 } else if (valIsUndefined) {
4171 setLow = othIsReflexive && (retHighest || othIsDefined);
4172 } else if (valIsNull) {
4173 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
4174 } else if (valIsSymbol) {
4175 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
4176 } else if (othIsNull || othIsSymbol) {
4179 setLow = retHighest ? (computed <= value) : (computed < value);
4187 return nativeMin(high, MAX_ARRAY_INDEX);
4191 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
4192 * support for iteratee shorthands.
4195 * @param {Array} array The array to inspect.
4196 * @param {Function} [iteratee] The iteratee invoked per element.
4197 * @returns {Array} Returns the new duplicate free array.
4199 function baseSortedUniq(array, iteratee) {
4201 length = array.length,
4205 while (++index < length) {
4206 var value = array[index],
4207 computed = iteratee ? iteratee(value) : value;
4209 if (!index || !eq(computed, seen)) {
4210 var seen = computed;
4211 result[resIndex++] = value === 0 ? 0 : value;
4218 * The base implementation of `_.toNumber` which doesn't ensure correct
4219 * conversions of binary, hexadecimal, or octal string values.
4222 * @param {*} value The value to process.
4223 * @returns {number} Returns the number.
4225 function baseToNumber(value) {
4226 if (typeof value == 'number') {
4229 if (isSymbol(value)) {
4236 * The base implementation of `_.toString` which doesn't convert nullish
4237 * values to empty strings.
4240 * @param {*} value The value to process.
4241 * @returns {string} Returns the string.
4243 function baseToString(value) {
4244 // Exit early for strings to avoid a performance hit in some environments.
4245 if (typeof value == 'string') {
4248 if (isArray(value)) {
4249 // Recursively convert values (susceptible to call stack limits).
4250 return arrayMap(value, baseToString) + '';
4252 if (isSymbol(value)) {
4253 return symbolToString ? symbolToString.call(value) : '';
4255 var result = (value + '');
4256 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
4260 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
4263 * @param {Array} array The array to inspect.
4264 * @param {Function} [iteratee] The iteratee invoked per element.
4265 * @param {Function} [comparator] The comparator invoked per element.
4266 * @returns {Array} Returns the new duplicate free array.
4268 function baseUniq(array, iteratee, comparator) {
4270 includes = arrayIncludes,
4271 length = array.length,
4278 includes = arrayIncludesWith;
4280 else if (length >= LARGE_ARRAY_SIZE) {
4281 var set = iteratee ? null : createSet(array);
4283 return setToArray(set);
4286 includes = cacheHas;
4287 seen = new SetCache;
4290 seen = iteratee ? [] : result;
4293 while (++index < length) {
4294 var value = array[index],
4295 computed = iteratee ? iteratee(value) : value;
4297 value = (comparator || value !== 0) ? value : 0;
4298 if (isCommon && computed === computed) {
4299 var seenIndex = seen.length;
4300 while (seenIndex--) {
4301 if (seen[seenIndex] === computed) {
4306 seen.push(computed);
4310 else if (!includes(seen, computed, comparator)) {
4311 if (seen !== result) {
4312 seen.push(computed);
4321 * The base implementation of `_.unset`.
4324 * @param {Object} object The object to modify.
4325 * @param {Array|string} path The path of the property to unset.
4326 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
4328 function baseUnset(object, path) {
4329 path = isKey(path, object) ? [path] : castPath(path);
4330 object = parent(object, path);
4332 var key = toKey(last(path));
4333 return !(object != null && hasOwnProperty.call(object, key)) || delete object[key];
4337 * The base implementation of `_.update`.
4340 * @param {Object} object The object to modify.
4341 * @param {Array|string} path The path of the property to update.
4342 * @param {Function} updater The function to produce the updated value.
4343 * @param {Function} [customizer] The function to customize path creation.
4344 * @returns {Object} Returns `object`.
4346 function baseUpdate(object, path, updater, customizer) {
4347 return baseSet(object, path, updater(baseGet(object, path)), customizer);
4351 * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
4352 * without support for iteratee shorthands.
4355 * @param {Array} array The array to query.
4356 * @param {Function} predicate The function invoked per iteration.
4357 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
4358 * @param {boolean} [fromRight] Specify iterating from right to left.
4359 * @returns {Array} Returns the slice of `array`.
4361 function baseWhile(array, predicate, isDrop, fromRight) {
4362 var length = array.length,
4363 index = fromRight ? length : -1;
4365 while ((fromRight ? index-- : ++index < length) &&
4366 predicate(array[index], index, array)) {}
4369 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
4370 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
4374 * The base implementation of `wrapperValue` which returns the result of
4375 * performing a sequence of actions on the unwrapped `value`, where each
4376 * successive action is supplied the return value of the previous.
4379 * @param {*} value The unwrapped value.
4380 * @param {Array} actions Actions to perform to resolve the unwrapped value.
4381 * @returns {*} Returns the resolved value.
4383 function baseWrapperValue(value, actions) {
4385 if (result instanceof LazyWrapper) {
4386 result = result.value();
4388 return arrayReduce(actions, function(result, action) {
4389 return action.func.apply(action.thisArg, arrayPush([result], action.args));
4394 * The base implementation of methods like `_.xor`, without support for
4395 * iteratee shorthands, that accepts an array of arrays to inspect.
4398 * @param {Array} arrays The arrays to inspect.
4399 * @param {Function} [iteratee] The iteratee invoked per element.
4400 * @param {Function} [comparator] The comparator invoked per element.
4401 * @returns {Array} Returns the new array of values.
4403 function baseXor(arrays, iteratee, comparator) {
4404 var length = arrays.length;
4406 return length ? baseUniq(arrays[0]) : [];
4409 result = Array(length);
4411 while (++index < length) {
4412 var array = arrays[index],
4415 while (++othIndex < length) {
4416 if (othIndex != index) {
4417 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
4421 return baseUniq(baseFlatten(result, 1), iteratee, comparator);
4425 * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
4428 * @param {Array} props The property identifiers.
4429 * @param {Array} values The property values.
4430 * @param {Function} assignFunc The function to assign values.
4431 * @returns {Object} Returns the new object.
4433 function baseZipObject(props, values, assignFunc) {
4435 length = props.length,
4436 valsLength = values.length,
4439 while (++index < length) {
4440 var value = index < valsLength ? values[index] : undefined;
4441 assignFunc(result, props[index], value);
4447 * Casts `value` to an empty array if it's not an array like object.
4450 * @param {*} value The value to inspect.
4451 * @returns {Array|Object} Returns the cast array-like object.
4453 function castArrayLikeObject(value) {
4454 return isArrayLikeObject(value) ? value : [];
4458 * Casts `value` to `identity` if it's not a function.
4461 * @param {*} value The value to inspect.
4462 * @returns {Function} Returns cast function.
4464 function castFunction(value) {
4465 return typeof value == 'function' ? value : identity;
4469 * Casts `value` to a path array if it's not one.
4472 * @param {*} value The value to inspect.
4473 * @returns {Array} Returns the cast property path array.
4475 function castPath(value) {
4476 return isArray(value) ? value : stringToPath(value);
4480 * A `baseRest` alias which can be replaced with `identity` by module
4481 * replacement plugins.
4485 * @param {Function} func The function to apply a rest parameter to.
4486 * @returns {Function} Returns the new function.
4488 var castRest = baseRest;
4491 * Casts `array` to a slice if it's needed.
4494 * @param {Array} array The array to inspect.
4495 * @param {number} start The start position.
4496 * @param {number} [end=array.length] The end position.
4497 * @returns {Array} Returns the cast slice.
4499 function castSlice(array, start, end) {
4500 var length = array.length;
4501 end = end === undefined ? length : end;
4502 return (!start && end >= length) ? array : baseSlice(array, start, end);
4506 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
4509 * @param {number|Object} id The timer id or timeout object of the timer to clear.
4511 var clearTimeout = ctxClearTimeout || function(id) {
4512 return root.clearTimeout(id);
4516 * Creates a clone of `buffer`.
4519 * @param {Buffer} buffer The buffer to clone.
4520 * @param {boolean} [isDeep] Specify a deep clone.
4521 * @returns {Buffer} Returns the cloned buffer.
4523 function cloneBuffer(buffer, isDeep) {
4525 return buffer.slice();
4527 var length = buffer.length,
4528 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
4530 buffer.copy(result);
4535 * Creates a clone of `arrayBuffer`.
4538 * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
4539 * @returns {ArrayBuffer} Returns the cloned array buffer.
4541 function cloneArrayBuffer(arrayBuffer) {
4542 var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
4543 new Uint8Array(result).set(new Uint8Array(arrayBuffer));
4548 * Creates a clone of `dataView`.
4551 * @param {Object} dataView The data view to clone.
4552 * @param {boolean} [isDeep] Specify a deep clone.
4553 * @returns {Object} Returns the cloned data view.
4555 function cloneDataView(dataView, isDeep) {
4556 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
4557 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
4561 * Creates a clone of `map`.
4564 * @param {Object} map The map to clone.
4565 * @param {Function} cloneFunc The function to clone values.
4566 * @param {boolean} [isDeep] Specify a deep clone.
4567 * @returns {Object} Returns the cloned map.
4569 function cloneMap(map, isDeep, cloneFunc) {
4570 var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
4571 return arrayReduce(array, addMapEntry, new map.constructor);
4575 * Creates a clone of `regexp`.
4578 * @param {Object} regexp The regexp to clone.
4579 * @returns {Object} Returns the cloned regexp.
4581 function cloneRegExp(regexp) {
4582 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
4583 result.lastIndex = regexp.lastIndex;
4588 * Creates a clone of `set`.
4591 * @param {Object} set The set to clone.
4592 * @param {Function} cloneFunc The function to clone values.
4593 * @param {boolean} [isDeep] Specify a deep clone.
4594 * @returns {Object} Returns the cloned set.
4596 function cloneSet(set, isDeep, cloneFunc) {
4597 var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
4598 return arrayReduce(array, addSetEntry, new set.constructor);
4602 * Creates a clone of the `symbol` object.
4605 * @param {Object} symbol The symbol object to clone.
4606 * @returns {Object} Returns the cloned symbol object.
4608 function cloneSymbol(symbol) {
4609 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
4613 * Creates a clone of `typedArray`.
4616 * @param {Object} typedArray The typed array to clone.
4617 * @param {boolean} [isDeep] Specify a deep clone.
4618 * @returns {Object} Returns the cloned typed array.
4620 function cloneTypedArray(typedArray, isDeep) {
4621 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
4622 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
4626 * Compares values to sort them in ascending order.
4629 * @param {*} value The value to compare.
4630 * @param {*} other The other value to compare.
4631 * @returns {number} Returns the sort order indicator for `value`.
4633 function compareAscending(value, other) {
4634 if (value !== other) {
4635 var valIsDefined = value !== undefined,
4636 valIsNull = value === null,
4637 valIsReflexive = value === value,
4638 valIsSymbol = isSymbol(value);
4640 var othIsDefined = other !== undefined,
4641 othIsNull = other === null,
4642 othIsReflexive = other === other,
4643 othIsSymbol = isSymbol(other);
4645 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
4646 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
4647 (valIsNull && othIsDefined && othIsReflexive) ||
4648 (!valIsDefined && othIsReflexive) ||
4652 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
4653 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
4654 (othIsNull && valIsDefined && valIsReflexive) ||
4655 (!othIsDefined && valIsReflexive) ||
4664 * Used by `_.orderBy` to compare multiple properties of a value to another
4665 * and stable sort them.
4667 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
4668 * specify an order of "desc" for descending or "asc" for ascending sort order
4669 * of corresponding values.
4672 * @param {Object} object The object to compare.
4673 * @param {Object} other The other object to compare.
4674 * @param {boolean[]|string[]} orders The order to sort by for each property.
4675 * @returns {number} Returns the sort order indicator for `object`.
4677 function compareMultiple(object, other, orders) {
4679 objCriteria = object.criteria,
4680 othCriteria = other.criteria,
4681 length = objCriteria.length,
4682 ordersLength = orders.length;
4684 while (++index < length) {
4685 var result = compareAscending(objCriteria[index], othCriteria[index]);
4687 if (index >= ordersLength) {
4690 var order = orders[index];
4691 return result * (order == 'desc' ? -1 : 1);
4694 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
4695 // that causes it, under certain circumstances, to provide the same value for
4696 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
4697 // for more details.
4699 // This also ensures a stable sort in V8 and other engines.
4700 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
4701 return object.index - other.index;
4705 * Creates an array that is the composition of partially applied arguments,
4706 * placeholders, and provided arguments into a single array of arguments.
4709 * @param {Array} args The provided arguments.
4710 * @param {Array} partials The arguments to prepend to those provided.
4711 * @param {Array} holders The `partials` placeholder indexes.
4712 * @params {boolean} [isCurried] Specify composing for a curried function.
4713 * @returns {Array} Returns the new array of composed arguments.
4715 function composeArgs(args, partials, holders, isCurried) {
4717 argsLength = args.length,
4718 holdersLength = holders.length,
4720 leftLength = partials.length,
4721 rangeLength = nativeMax(argsLength - holdersLength, 0),
4722 result = Array(leftLength + rangeLength),
4723 isUncurried = !isCurried;
4725 while (++leftIndex < leftLength) {
4726 result[leftIndex] = partials[leftIndex];
4728 while (++argsIndex < holdersLength) {
4729 if (isUncurried || argsIndex < argsLength) {
4730 result[holders[argsIndex]] = args[argsIndex];
4733 while (rangeLength--) {
4734 result[leftIndex++] = args[argsIndex++];
4740 * This function is like `composeArgs` except that the arguments composition
4741 * is tailored for `_.partialRight`.
4744 * @param {Array} args The provided arguments.
4745 * @param {Array} partials The arguments to append to those provided.
4746 * @param {Array} holders The `partials` placeholder indexes.
4747 * @params {boolean} [isCurried] Specify composing for a curried function.
4748 * @returns {Array} Returns the new array of composed arguments.
4750 function composeArgsRight(args, partials, holders, isCurried) {
4752 argsLength = args.length,
4754 holdersLength = holders.length,
4756 rightLength = partials.length,
4757 rangeLength = nativeMax(argsLength - holdersLength, 0),
4758 result = Array(rangeLength + rightLength),
4759 isUncurried = !isCurried;
4761 while (++argsIndex < rangeLength) {
4762 result[argsIndex] = args[argsIndex];
4764 var offset = argsIndex;
4765 while (++rightIndex < rightLength) {
4766 result[offset + rightIndex] = partials[rightIndex];
4768 while (++holdersIndex < holdersLength) {
4769 if (isUncurried || argsIndex < argsLength) {
4770 result[offset + holders[holdersIndex]] = args[argsIndex++];
4777 * Copies the values of `source` to `array`.
4780 * @param {Array} source The array to copy values from.
4781 * @param {Array} [array=[]] The array to copy values to.
4782 * @returns {Array} Returns `array`.
4784 function copyArray(source, array) {
4786 length = source.length;
4788 array || (array = Array(length));
4789 while (++index < length) {
4790 array[index] = source[index];
4796 * Copies properties of `source` to `object`.
4799 * @param {Object} source The object to copy properties from.
4800 * @param {Array} props The property identifiers to copy.
4801 * @param {Object} [object={}] The object to copy properties to.
4802 * @param {Function} [customizer] The function to customize copied values.
4803 * @returns {Object} Returns `object`.
4805 function copyObject(source, props, object, customizer) {
4806 var isNew = !object;
4807 object || (object = {});
4810 length = props.length;
4812 while (++index < length) {
4813 var key = props[index];
4815 var newValue = customizer
4816 ? customizer(object[key], source[key], key, object, source)
4819 if (newValue === undefined) {
4820 newValue = source[key];
4823 baseAssignValue(object, key, newValue);
4825 assignValue(object, key, newValue);
4832 * Copies own symbol properties of `source` to `object`.
4835 * @param {Object} source The object to copy symbols from.
4836 * @param {Object} [object={}] The object to copy symbols to.
4837 * @returns {Object} Returns `object`.
4839 function copySymbols(source, object) {
4840 return copyObject(source, getSymbols(source), object);
4844 * Creates a function like `_.groupBy`.
4847 * @param {Function} setter The function to set accumulator values.
4848 * @param {Function} [initializer] The accumulator object initializer.
4849 * @returns {Function} Returns the new aggregator function.
4851 function createAggregator(setter, initializer) {
4852 return function(collection, iteratee) {
4853 var func = isArray(collection) ? arrayAggregator : baseAggregator,
4854 accumulator = initializer ? initializer() : {};
4856 return func(collection, setter, getIteratee(iteratee, 2), accumulator);
4861 * Creates a function like `_.assign`.
4864 * @param {Function} assigner The function to assign values.
4865 * @returns {Function} Returns the new assigner function.
4867 function createAssigner(assigner) {
4868 return baseRest(function(object, sources) {
4870 length = sources.length,
4871 customizer = length > 1 ? sources[length - 1] : undefined,
4872 guard = length > 2 ? sources[2] : undefined;
4874 customizer = (assigner.length > 3 && typeof customizer == 'function')
4875 ? (length--, customizer)
4878 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
4879 customizer = length < 3 ? undefined : customizer;
4882 object = Object(object);
4883 while (++index < length) {
4884 var source = sources[index];
4886 assigner(object, source, index, customizer);
4894 * Creates a `baseEach` or `baseEachRight` function.
4897 * @param {Function} eachFunc The function to iterate over a collection.
4898 * @param {boolean} [fromRight] Specify iterating from right to left.
4899 * @returns {Function} Returns the new base function.
4901 function createBaseEach(eachFunc, fromRight) {
4902 return function(collection, iteratee) {
4903 if (collection == null) {
4906 if (!isArrayLike(collection)) {
4907 return eachFunc(collection, iteratee);
4909 var length = collection.length,
4910 index = fromRight ? length : -1,
4911 iterable = Object(collection);
4913 while ((fromRight ? index-- : ++index < length)) {
4914 if (iteratee(iterable[index], index, iterable) === false) {
4923 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
4926 * @param {boolean} [fromRight] Specify iterating from right to left.
4927 * @returns {Function} Returns the new base function.
4929 function createBaseFor(fromRight) {
4930 return function(object, iteratee, keysFunc) {
4932 iterable = Object(object),
4933 props = keysFunc(object),
4934 length = props.length;
4937 var key = props[fromRight ? length : ++index];
4938 if (iteratee(iterable[key], key, iterable) === false) {
4947 * Creates a function that wraps `func` to invoke it with the optional `this`
4948 * binding of `thisArg`.
4951 * @param {Function} func The function to wrap.
4952 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
4953 * @param {*} [thisArg] The `this` binding of `func`.
4954 * @returns {Function} Returns the new wrapped function.
4956 function createBind(func, bitmask, thisArg) {
4957 var isBind = bitmask & BIND_FLAG,
4958 Ctor = createCtor(func);
4960 function wrapper() {
4961 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4962 return fn.apply(isBind ? thisArg : this, arguments);
4968 * Creates a function like `_.lowerFirst`.
4971 * @param {string} methodName The name of the `String` case method to use.
4972 * @returns {Function} Returns the new case function.
4974 function createCaseFirst(methodName) {
4975 return function(string) {
4976 string = toString(string);
4978 var strSymbols = hasUnicode(string)
4979 ? stringToArray(string)
4982 var chr = strSymbols
4986 var trailing = strSymbols
4987 ? castSlice(strSymbols, 1).join('')
4990 return chr[methodName]() + trailing;
4995 * Creates a function like `_.camelCase`.
4998 * @param {Function} callback The function to combine each word.
4999 * @returns {Function} Returns the new compounder function.
5001 function createCompounder(callback) {
5002 return function(string) {
5003 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
5008 * Creates a function that produces an instance of `Ctor` regardless of
5009 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
5012 * @param {Function} Ctor The constructor to wrap.
5013 * @returns {Function} Returns the new wrapped function.
5015 function createCtor(Ctor) {
5017 // Use a `switch` statement to work with class constructors. See
5018 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
5019 // for more details.
5020 var args = arguments;
5021 switch (args.length) {
5022 case 0: return new Ctor;
5023 case 1: return new Ctor(args[0]);
5024 case 2: return new Ctor(args[0], args[1]);
5025 case 3: return new Ctor(args[0], args[1], args[2]);
5026 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
5027 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
5028 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
5029 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
5031 var thisBinding = baseCreate(Ctor.prototype),
5032 result = Ctor.apply(thisBinding, args);
5034 // Mimic the constructor's `return` behavior.
5035 // See https://es5.github.io/#x13.2.2 for more details.
5036 return isObject(result) ? result : thisBinding;
5041 * Creates a function that wraps `func` to enable currying.
5044 * @param {Function} func The function to wrap.
5045 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5046 * @param {number} arity The arity of `func`.
5047 * @returns {Function} Returns the new wrapped function.
5049 function createCurry(func, bitmask, arity) {
5050 var Ctor = createCtor(func);
5052 function wrapper() {
5053 var length = arguments.length,
5054 args = Array(length),
5056 placeholder = getHolder(wrapper);
5059 args[index] = arguments[index];
5061 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
5063 : replaceHolders(args, placeholder);
5065 length -= holders.length;
5066 if (length < arity) {
5067 return createRecurry(
5068 func, bitmask, createHybrid, wrapper.placeholder, undefined,
5069 args, holders, undefined, undefined, arity - length);
5071 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5072 return apply(fn, this, args);
5078 * Creates a `_.find` or `_.findLast` function.
5081 * @param {Function} findIndexFunc The function to find the collection index.
5082 * @returns {Function} Returns the new find function.
5084 function createFind(findIndexFunc) {
5085 return function(collection, predicate, fromIndex) {
5086 var iterable = Object(collection);
5087 if (!isArrayLike(collection)) {
5088 var iteratee = getIteratee(predicate, 3);
5089 collection = keys(collection);
5090 predicate = function(key) { return iteratee(iterable[key], key, iterable); };
5092 var index = findIndexFunc(collection, predicate, fromIndex);
5093 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
5098 * Creates a `_.flow` or `_.flowRight` function.
5101 * @param {boolean} [fromRight] Specify iterating from right to left.
5102 * @returns {Function} Returns the new flow function.
5104 function createFlow(fromRight) {
5105 return flatRest(function(funcs) {
5106 var length = funcs.length,
5108 prereq = LodashWrapper.prototype.thru;
5114 var func = funcs[index];
5115 if (typeof func != 'function') {
5116 throw new TypeError(FUNC_ERROR_TEXT);
5118 if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
5119 var wrapper = new LodashWrapper([], true);
5122 index = wrapper ? index : length;
5123 while (++index < length) {
5124 func = funcs[index];
5126 var funcName = getFuncName(func),
5127 data = funcName == 'wrapper' ? getData(func) : undefined;
5129 if (data && isLaziable(data[0]) &&
5130 data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
5131 !data[4].length && data[9] == 1
5133 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
5135 wrapper = (func.length == 1 && isLaziable(func))
5136 ? wrapper[funcName]()
5137 : wrapper.thru(func);
5141 var args = arguments,
5144 if (wrapper && args.length == 1 &&
5145 isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
5146 return wrapper.plant(value).value();
5149 result = length ? funcs[index].apply(this, args) : value;
5151 while (++index < length) {
5152 result = funcs[index].call(this, result);
5160 * Creates a function that wraps `func` to invoke it with optional `this`
5161 * binding of `thisArg`, partial application, and currying.
5164 * @param {Function|string} func The function or method name to wrap.
5165 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5166 * @param {*} [thisArg] The `this` binding of `func`.
5167 * @param {Array} [partials] The arguments to prepend to those provided to
5169 * @param {Array} [holders] The `partials` placeholder indexes.
5170 * @param {Array} [partialsRight] The arguments to append to those provided
5171 * to the new function.
5172 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
5173 * @param {Array} [argPos] The argument positions of the new function.
5174 * @param {number} [ary] The arity cap of `func`.
5175 * @param {number} [arity] The arity of `func`.
5176 * @returns {Function} Returns the new wrapped function.
5178 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
5179 var isAry = bitmask & ARY_FLAG,
5180 isBind = bitmask & BIND_FLAG,
5181 isBindKey = bitmask & BIND_KEY_FLAG,
5182 isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
5183 isFlip = bitmask & FLIP_FLAG,
5184 Ctor = isBindKey ? undefined : createCtor(func);
5186 function wrapper() {
5187 var length = arguments.length,
5188 args = Array(length),
5192 args[index] = arguments[index];
5195 var placeholder = getHolder(wrapper),
5196 holdersCount = countHolders(args, placeholder);
5199 args = composeArgs(args, partials, holders, isCurried);
5201 if (partialsRight) {
5202 args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
5204 length -= holdersCount;
5205 if (isCurried && length < arity) {
5206 var newHolders = replaceHolders(args, placeholder);
5207 return createRecurry(
5208 func, bitmask, createHybrid, wrapper.placeholder, thisArg,
5209 args, newHolders, argPos, ary, arity - length
5212 var thisBinding = isBind ? thisArg : this,
5213 fn = isBindKey ? thisBinding[func] : func;
5215 length = args.length;
5217 args = reorder(args, argPos);
5218 } else if (isFlip && length > 1) {
5221 if (isAry && ary < length) {
5224 if (this && this !== root && this instanceof wrapper) {
5225 fn = Ctor || createCtor(fn);
5227 return fn.apply(thisBinding, args);
5233 * Creates a function like `_.invertBy`.
5236 * @param {Function} setter The function to set accumulator values.
5237 * @param {Function} toIteratee The function to resolve iteratees.
5238 * @returns {Function} Returns the new inverter function.
5240 function createInverter(setter, toIteratee) {
5241 return function(object, iteratee) {
5242 return baseInverter(object, setter, toIteratee(iteratee), {});
5247 * Creates a function that performs a mathematical operation on two values.
5250 * @param {Function} operator The function to perform the operation.
5251 * @param {number} [defaultValue] The value used for `undefined` arguments.
5252 * @returns {Function} Returns the new mathematical operation function.
5254 function createMathOperation(operator, defaultValue) {
5255 return function(value, other) {
5257 if (value === undefined && other === undefined) {
5258 return defaultValue;
5260 if (value !== undefined) {
5263 if (other !== undefined) {
5264 if (result === undefined) {
5267 if (typeof value == 'string' || typeof other == 'string') {
5268 value = baseToString(value);
5269 other = baseToString(other);
5271 value = baseToNumber(value);
5272 other = baseToNumber(other);
5274 result = operator(value, other);
5281 * Creates a function like `_.over`.
5284 * @param {Function} arrayFunc The function to iterate over iteratees.
5285 * @returns {Function} Returns the new over function.
5287 function createOver(arrayFunc) {
5288 return flatRest(function(iteratees) {
5289 iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
5290 return baseRest(function(args) {
5292 return arrayFunc(iteratees, function(iteratee) {
5293 return apply(iteratee, thisArg, args);
5300 * Creates the padding for `string` based on `length`. The `chars` string
5301 * is truncated if the number of characters exceeds `length`.
5304 * @param {number} length The padding length.
5305 * @param {string} [chars=' '] The string used as padding.
5306 * @returns {string} Returns the padding for `string`.
5308 function createPadding(length, chars) {
5309 chars = chars === undefined ? ' ' : baseToString(chars);
5311 var charsLength = chars.length;
5312 if (charsLength < 2) {
5313 return charsLength ? baseRepeat(chars, length) : chars;
5315 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
5316 return hasUnicode(chars)
5317 ? castSlice(stringToArray(result), 0, length).join('')
5318 : result.slice(0, length);
5322 * Creates a function that wraps `func` to invoke it with the `this` binding
5323 * of `thisArg` and `partials` prepended to the arguments it receives.
5326 * @param {Function} func The function to wrap.
5327 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5328 * @param {*} thisArg The `this` binding of `func`.
5329 * @param {Array} partials The arguments to prepend to those provided to
5331 * @returns {Function} Returns the new wrapped function.
5333 function createPartial(func, bitmask, thisArg, partials) {
5334 var isBind = bitmask & BIND_FLAG,
5335 Ctor = createCtor(func);
5337 function wrapper() {
5339 argsLength = arguments.length,
5341 leftLength = partials.length,
5342 args = Array(leftLength + argsLength),
5343 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
5345 while (++leftIndex < leftLength) {
5346 args[leftIndex] = partials[leftIndex];
5348 while (argsLength--) {
5349 args[leftIndex++] = arguments[++argsIndex];
5351 return apply(fn, isBind ? thisArg : this, args);
5357 * Creates a `_.range` or `_.rangeRight` function.
5360 * @param {boolean} [fromRight] Specify iterating from right to left.
5361 * @returns {Function} Returns the new range function.
5363 function createRange(fromRight) {
5364 return function(start, end, step) {
5365 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
5366 end = step = undefined;
5368 // Ensure the sign of `-0` is preserved.
5369 start = toFinite(start);
5370 if (end === undefined) {
5374 end = toFinite(end);
5376 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
5377 return baseRange(start, end, step, fromRight);
5382 * Creates a function that performs a relational operation on two values.
5385 * @param {Function} operator The function to perform the operation.
5386 * @returns {Function} Returns the new relational operation function.
5388 function createRelationalOperation(operator) {
5389 return function(value, other) {
5390 if (!(typeof value == 'string' && typeof other == 'string')) {
5391 value = toNumber(value);
5392 other = toNumber(other);
5394 return operator(value, other);
5399 * Creates a function that wraps `func` to continue currying.
5402 * @param {Function} func The function to wrap.
5403 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
5404 * @param {Function} wrapFunc The function to create the `func` wrapper.
5405 * @param {*} placeholder The placeholder value.
5406 * @param {*} [thisArg] The `this` binding of `func`.
5407 * @param {Array} [partials] The arguments to prepend to those provided to
5409 * @param {Array} [holders] The `partials` placeholder indexes.
5410 * @param {Array} [argPos] The argument positions of the new function.
5411 * @param {number} [ary] The arity cap of `func`.
5412 * @param {number} [arity] The arity of `func`.
5413 * @returns {Function} Returns the new wrapped function.
5415 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
5416 var isCurry = bitmask & CURRY_FLAG,
5417 newHolders = isCurry ? holders : undefined,
5418 newHoldersRight = isCurry ? undefined : holders,
5419 newPartials = isCurry ? partials : undefined,
5420 newPartialsRight = isCurry ? undefined : partials;
5422 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
5423 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
5425 if (!(bitmask & CURRY_BOUND_FLAG)) {
5426 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
5429 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
5430 newHoldersRight, argPos, ary, arity
5433 var result = wrapFunc.apply(undefined, newData);
5434 if (isLaziable(func)) {
5435 setData(result, newData);
5437 result.placeholder = placeholder;
5438 return setWrapToString(result, func, bitmask);
5442 * Creates a function like `_.round`.
5445 * @param {string} methodName The name of the `Math` method to use when rounding.
5446 * @returns {Function} Returns the new round function.
5448 function createRound(methodName) {
5449 var func = Math[methodName];
5450 return function(number, precision) {
5451 number = toNumber(number);
5452 precision = nativeMin(toInteger(precision), 292);
5454 // Shift with exponential notation to avoid floating-point issues.
5455 // See [MDN](https://mdn.io/round#Examples) for more details.
5456 var pair = (toString(number) + 'e').split('e'),
5457 value = func(pair[0] + 'e' + (+pair[1] + precision));
5459 pair = (toString(value) + 'e').split('e');
5460 return +(pair[0] + 'e' + (+pair[1] - precision));
5462 return func(number);
5467 * Creates a set object of `values`.
5470 * @param {Array} values The values to add to the set.
5471 * @returns {Object} Returns the new set.
5473 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
5474 return new Set(values);
5478 * Creates a `_.toPairs` or `_.toPairsIn` function.
5481 * @param {Function} keysFunc The function to get the keys of a given object.
5482 * @returns {Function} Returns the new pairs function.
5484 function createToPairs(keysFunc) {
5485 return function(object) {
5486 var tag = getTag(object);
5487 if (tag == mapTag) {
5488 return mapToArray(object);
5490 if (tag == setTag) {
5491 return setToPairs(object);
5493 return baseToPairs(object, keysFunc(object));
5498 * Creates a function that either curries or invokes `func` with optional
5499 * `this` binding and partially applied arguments.
5502 * @param {Function|string} func The function or method name to wrap.
5503 * @param {number} bitmask The bitmask flags.
5504 * The bitmask may be composed of the following flags:
5507 * 4 - `_.curry` or `_.curryRight` of a bound function
5509 * 16 - `_.curryRight`
5511 * 64 - `_.partialRight`
5515 * @param {*} [thisArg] The `this` binding of `func`.
5516 * @param {Array} [partials] The arguments to be partially applied.
5517 * @param {Array} [holders] The `partials` placeholder indexes.
5518 * @param {Array} [argPos] The argument positions of the new function.
5519 * @param {number} [ary] The arity cap of `func`.
5520 * @param {number} [arity] The arity of `func`.
5521 * @returns {Function} Returns the new wrapped function.
5523 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
5524 var isBindKey = bitmask & BIND_KEY_FLAG;
5525 if (!isBindKey && typeof func != 'function') {
5526 throw new TypeError(FUNC_ERROR_TEXT);
5528 var length = partials ? partials.length : 0;
5530 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
5531 partials = holders = undefined;
5533 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
5534 arity = arity === undefined ? arity : toInteger(arity);
5535 length -= holders ? holders.length : 0;
5537 if (bitmask & PARTIAL_RIGHT_FLAG) {
5538 var partialsRight = partials,
5539 holdersRight = holders;
5541 partials = holders = undefined;
5543 var data = isBindKey ? undefined : getData(func);
5546 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
5551 mergeData(newData, data);
5554 bitmask = newData[1];
5555 thisArg = newData[2];
5556 partials = newData[3];
5557 holders = newData[4];
5558 arity = newData[9] = newData[9] == null
5559 ? (isBindKey ? 0 : func.length)
5560 : nativeMax(newData[9] - length, 0);
5562 if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
5563 bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
5565 if (!bitmask || bitmask == BIND_FLAG) {
5566 var result = createBind(func, bitmask, thisArg);
5567 } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
5568 result = createCurry(func, bitmask, arity);
5569 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
5570 result = createPartial(func, bitmask, thisArg, partials);
5572 result = createHybrid.apply(undefined, newData);
5574 var setter = data ? baseSetData : setData;
5575 return setWrapToString(setter(result, newData), func, bitmask);
5579 * A specialized version of `baseIsEqualDeep` for arrays with support for
5580 * partial deep comparisons.
5583 * @param {Array} array The array to compare.
5584 * @param {Array} other The other array to compare.
5585 * @param {Function} equalFunc The function to determine equivalents of values.
5586 * @param {Function} customizer The function to customize comparisons.
5587 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5589 * @param {Object} stack Tracks traversed `array` and `other` objects.
5590 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
5592 function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
5593 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
5594 arrLength = array.length,
5595 othLength = other.length;
5597 if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
5600 // Assume cyclic values are equal.
5601 var stacked = stack.get(array);
5602 if (stacked && stack.get(other)) {
5603 return stacked == other;
5607 seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
5609 stack.set(array, other);
5610 stack.set(other, array);
5612 // Ignore non-index properties.
5613 while (++index < arrLength) {
5614 var arrValue = array[index],
5615 othValue = other[index];
5618 var compared = isPartial
5619 ? customizer(othValue, arrValue, index, other, array, stack)
5620 : customizer(arrValue, othValue, index, array, other, stack);
5622 if (compared !== undefined) {
5629 // Recursively compare arrays (susceptible to call stack limits).
5631 if (!arraySome(other, function(othValue, othIndex) {
5632 if (!cacheHas(seen, othIndex) &&
5633 (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
5634 return seen.push(othIndex);
5641 arrValue === othValue ||
5642 equalFunc(arrValue, othValue, customizer, bitmask, stack)
5648 stack['delete'](array);
5649 stack['delete'](other);
5654 * A specialized version of `baseIsEqualDeep` for comparing objects of
5655 * the same `toStringTag`.
5657 * **Note:** This function only supports comparing values with tags of
5658 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
5661 * @param {Object} object The object to compare.
5662 * @param {Object} other The other object to compare.
5663 * @param {string} tag The `toStringTag` of the objects to compare.
5664 * @param {Function} equalFunc The function to determine equivalents of values.
5665 * @param {Function} customizer The function to customize comparisons.
5666 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5668 * @param {Object} stack Tracks traversed `object` and `other` objects.
5669 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5671 function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
5674 if ((object.byteLength != other.byteLength) ||
5675 (object.byteOffset != other.byteOffset)) {
5678 object = object.buffer;
5679 other = other.buffer;
5681 case arrayBufferTag:
5682 if ((object.byteLength != other.byteLength) ||
5683 !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
5691 // Coerce booleans to `1` or `0` and dates to milliseconds.
5692 // Invalid dates are coerced to `NaN`.
5693 return eq(+object, +other);
5696 return object.name == other.name && object.message == other.message;
5700 // Coerce regexes to strings and treat strings, primitives and objects,
5701 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
5702 // for more details.
5703 return object == (other + '');
5706 var convert = mapToArray;
5709 var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
5710 convert || (convert = setToArray);
5712 if (object.size != other.size && !isPartial) {
5715 // Assume cyclic values are equal.
5716 var stacked = stack.get(object);
5718 return stacked == other;
5720 bitmask |= UNORDERED_COMPARE_FLAG;
5722 // Recursively compare objects (susceptible to call stack limits).
5723 stack.set(object, other);
5724 var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
5725 stack['delete'](object);
5729 if (symbolValueOf) {
5730 return symbolValueOf.call(object) == symbolValueOf.call(other);
5737 * A specialized version of `baseIsEqualDeep` for objects with support for
5738 * partial deep comparisons.
5741 * @param {Object} object The object to compare.
5742 * @param {Object} other The other object to compare.
5743 * @param {Function} equalFunc The function to determine equivalents of values.
5744 * @param {Function} customizer The function to customize comparisons.
5745 * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
5747 * @param {Object} stack Tracks traversed `object` and `other` objects.
5748 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
5750 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
5751 var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
5752 objProps = keys(object),
5753 objLength = objProps.length,
5754 othProps = keys(other),
5755 othLength = othProps.length;
5757 if (objLength != othLength && !isPartial) {
5760 var index = objLength;
5762 var key = objProps[index];
5763 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
5767 // Assume cyclic values are equal.
5768 var stacked = stack.get(object);
5769 if (stacked && stack.get(other)) {
5770 return stacked == other;
5773 stack.set(object, other);
5774 stack.set(other, object);
5776 var skipCtor = isPartial;
5777 while (++index < objLength) {
5778 key = objProps[index];
5779 var objValue = object[key],
5780 othValue = other[key];
5783 var compared = isPartial
5784 ? customizer(othValue, objValue, key, other, object, stack)
5785 : customizer(objValue, othValue, key, object, other, stack);
5787 // Recursively compare objects (susceptible to call stack limits).
5788 if (!(compared === undefined
5789 ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
5795 skipCtor || (skipCtor = key == 'constructor');
5797 if (result && !skipCtor) {
5798 var objCtor = object.constructor,
5799 othCtor = other.constructor;
5801 // Non `Object` object instances with different constructors are not equal.
5802 if (objCtor != othCtor &&
5803 ('constructor' in object && 'constructor' in other) &&
5804 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
5805 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
5809 stack['delete'](object);
5810 stack['delete'](other);
5815 * A specialized version of `baseRest` which flattens the rest array.
5818 * @param {Function} func The function to apply a rest parameter to.
5819 * @returns {Function} Returns the new function.
5821 function flatRest(func) {
5822 return setToString(overRest(func, undefined, flatten), func + '');
5826 * Creates an array of own enumerable property names and symbols of `object`.
5829 * @param {Object} object The object to query.
5830 * @returns {Array} Returns the array of property names and symbols.
5832 function getAllKeys(object) {
5833 return baseGetAllKeys(object, keys, getSymbols);
5837 * Creates an array of own and inherited enumerable property names and
5838 * symbols of `object`.
5841 * @param {Object} object The object to query.
5842 * @returns {Array} Returns the array of property names and symbols.
5844 function getAllKeysIn(object) {
5845 return baseGetAllKeys(object, keysIn, getSymbolsIn);
5849 * Gets metadata for `func`.
5852 * @param {Function} func The function to query.
5853 * @returns {*} Returns the metadata for `func`.
5855 var getData = !metaMap ? noop : function(func) {
5856 return metaMap.get(func);
5860 * Gets the name of `func`.
5863 * @param {Function} func The function to query.
5864 * @returns {string} Returns the function name.
5866 function getFuncName(func) {
5867 var result = (func.name + ''),
5868 array = realNames[result],
5869 length = hasOwnProperty.call(realNames, result) ? array.length : 0;
5872 var data = array[length],
5873 otherFunc = data.func;
5874 if (otherFunc == null || otherFunc == func) {
5882 * Gets the argument placeholder value for `func`.
5885 * @param {Function} func The function to inspect.
5886 * @returns {*} Returns the placeholder value.
5888 function getHolder(func) {
5889 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
5890 return object.placeholder;
5894 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
5895 * this function returns the custom method, otherwise it returns `baseIteratee`.
5896 * If arguments are provided, the chosen function is invoked with them and
5897 * its result is returned.
5900 * @param {*} [value] The value to convert to an iteratee.
5901 * @param {number} [arity] The arity of the created iteratee.
5902 * @returns {Function} Returns the chosen function or its result.
5904 function getIteratee() {
5905 var result = lodash.iteratee || iteratee;
5906 result = result === iteratee ? baseIteratee : result;
5907 return arguments.length ? result(arguments[0], arguments[1]) : result;
5911 * Gets the data for `map`.
5914 * @param {Object} map The map to query.
5915 * @param {string} key The reference key.
5916 * @returns {*} Returns the map data.
5918 function getMapData(map, key) {
5919 var data = map.__data__;
5920 return isKeyable(key)
5921 ? data[typeof key == 'string' ? 'string' : 'hash']
5926 * Gets the property names, values, and compare flags of `object`.
5929 * @param {Object} object The object to query.
5930 * @returns {Array} Returns the match data of `object`.
5932 function getMatchData(object) {
5933 var result = keys(object),
5934 length = result.length;
5937 var key = result[length],
5938 value = object[key];
5940 result[length] = [key, value, isStrictComparable(value)];
5946 * Gets the native function at `key` of `object`.
5949 * @param {Object} object The object to query.
5950 * @param {string} key The key of the method to get.
5951 * @returns {*} Returns the function if it's native, else `undefined`.
5953 function getNative(object, key) {
5954 var value = getValue(object, key);
5955 return baseIsNative(value) ? value : undefined;
5959 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
5962 * @param {*} value The value to query.
5963 * @returns {string} Returns the raw `toStringTag`.
5965 function getRawTag(value) {
5966 var isOwn = hasOwnProperty.call(value, symToStringTag),
5967 tag = value[symToStringTag];
5970 value[symToStringTag] = undefined;
5971 var unmasked = true;
5974 var result = nativeObjectToString.call(value);
5977 value[symToStringTag] = tag;
5979 delete value[symToStringTag];
5986 * Creates an array of the own enumerable symbol properties of `object`.
5989 * @param {Object} object The object to query.
5990 * @returns {Array} Returns the array of symbols.
5992 var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
5995 * Creates an array of the own and inherited enumerable symbol properties
5999 * @param {Object} object The object to query.
6000 * @returns {Array} Returns the array of symbols.
6002 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
6005 arrayPush(result, getSymbols(object));
6006 object = getPrototype(object);
6012 * Gets the `toStringTag` of `value`.
6015 * @param {*} value The value to query.
6016 * @returns {string} Returns the `toStringTag`.
6018 var getTag = baseGetTag;
6020 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
6021 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
6022 (Map && getTag(new Map) != mapTag) ||
6023 (Promise && getTag(Promise.resolve()) != promiseTag) ||
6024 (Set && getTag(new Set) != setTag) ||
6025 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
6026 getTag = function(value) {
6027 var result = baseGetTag(value),
6028 Ctor = result == objectTag ? value.constructor : undefined,
6029 ctorString = Ctor ? toSource(Ctor) : '';
6032 switch (ctorString) {
6033 case dataViewCtorString: return dataViewTag;
6034 case mapCtorString: return mapTag;
6035 case promiseCtorString: return promiseTag;
6036 case setCtorString: return setTag;
6037 case weakMapCtorString: return weakMapTag;
6045 * Gets the view, applying any `transforms` to the `start` and `end` positions.
6048 * @param {number} start The start of the view.
6049 * @param {number} end The end of the view.
6050 * @param {Array} transforms The transformations to apply to the view.
6051 * @returns {Object} Returns an object containing the `start` and `end`
6052 * positions of the view.
6054 function getView(start, end, transforms) {
6056 length = transforms.length;
6058 while (++index < length) {
6059 var data = transforms[index],
6062 switch (data.type) {
6063 case 'drop': start += size; break;
6064 case 'dropRight': end -= size; break;
6065 case 'take': end = nativeMin(end, start + size); break;
6066 case 'takeRight': start = nativeMax(start, end - size); break;
6069 return { 'start': start, 'end': end };
6073 * Extracts wrapper details from the `source` body comment.
6076 * @param {string} source The source to inspect.
6077 * @returns {Array} Returns the wrapper details.
6079 function getWrapDetails(source) {
6080 var match = source.match(reWrapDetails);
6081 return match ? match[1].split(reSplitDetails) : [];
6085 * Checks if `path` exists on `object`.
6088 * @param {Object} object The object to query.
6089 * @param {Array|string} path The path to check.
6090 * @param {Function} hasFunc The function to check properties.
6091 * @returns {boolean} Returns `true` if `path` exists, else `false`.
6093 function hasPath(object, path, hasFunc) {
6094 path = isKey(path, object) ? [path] : castPath(path);
6097 length = path.length,
6100 while (++index < length) {
6101 var key = toKey(path[index]);
6102 if (!(result = object != null && hasFunc(object, key))) {
6105 object = object[key];
6107 if (result || ++index != length) {
6110 length = object == null ? 0 : object.length;
6111 return !!length && isLength(length) && isIndex(key, length) &&
6112 (isArray(object) || isArguments(object));
6116 * Initializes an array clone.
6119 * @param {Array} array The array to clone.
6120 * @returns {Array} Returns the initialized clone.
6122 function initCloneArray(array) {
6123 var length = array.length,
6124 result = array.constructor(length);
6126 // Add properties assigned by `RegExp#exec`.
6127 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
6128 result.index = array.index;
6129 result.input = array.input;
6135 * Initializes an object clone.
6138 * @param {Object} object The object to clone.
6139 * @returns {Object} Returns the initialized clone.
6141 function initCloneObject(object) {
6142 return (typeof object.constructor == 'function' && !isPrototype(object))
6143 ? baseCreate(getPrototype(object))
6148 * Initializes an object clone based on its `toStringTag`.
6150 * **Note:** This function only supports cloning values with tags of
6151 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
6154 * @param {Object} object The object to clone.
6155 * @param {string} tag The `toStringTag` of the object to clone.
6156 * @param {Function} cloneFunc The function to clone values.
6157 * @param {boolean} [isDeep] Specify a deep clone.
6158 * @returns {Object} Returns the initialized clone.
6160 function initCloneByTag(object, tag, cloneFunc, isDeep) {
6161 var Ctor = object.constructor;
6163 case arrayBufferTag:
6164 return cloneArrayBuffer(object);
6168 return new Ctor(+object);
6171 return cloneDataView(object, isDeep);
6173 case float32Tag: case float64Tag:
6174 case int8Tag: case int16Tag: case int32Tag:
6175 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
6176 return cloneTypedArray(object, isDeep);
6179 return cloneMap(object, isDeep, cloneFunc);
6183 return new Ctor(object);
6186 return cloneRegExp(object);
6189 return cloneSet(object, isDeep, cloneFunc);
6192 return cloneSymbol(object);
6197 * Inserts wrapper `details` in a comment at the top of the `source` body.
6200 * @param {string} source The source to modify.
6201 * @returns {Array} details The details to insert.
6202 * @returns {string} Returns the modified source.
6204 function insertWrapDetails(source, details) {
6205 var length = details.length;
6209 var lastIndex = length - 1;
6210 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
6211 details = details.join(length > 2 ? ', ' : ' ');
6212 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
6216 * Checks if `value` is a flattenable `arguments` object or array.
6219 * @param {*} value The value to check.
6220 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
6222 function isFlattenable(value) {
6223 return isArray(value) || isArguments(value) ||
6224 !!(spreadableSymbol && value && value[spreadableSymbol]);
6228 * Checks if `value` is a valid array-like index.
6231 * @param {*} value The value to check.
6232 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
6233 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
6235 function isIndex(value, length) {
6236 length = length == null ? MAX_SAFE_INTEGER : length;
6238 (typeof value == 'number' || reIsUint.test(value)) &&
6239 (value > -1 && value % 1 == 0 && value < length);
6243 * Checks if the given arguments are from an iteratee call.
6246 * @param {*} value The potential iteratee value argument.
6247 * @param {*} index The potential iteratee index or key argument.
6248 * @param {*} object The potential iteratee object argument.
6249 * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
6252 function isIterateeCall(value, index, object) {
6253 if (!isObject(object)) {
6256 var type = typeof index;
6257 if (type == 'number'
6258 ? (isArrayLike(object) && isIndex(index, object.length))
6259 : (type == 'string' && index in object)
6261 return eq(object[index], value);
6267 * Checks if `value` is a property name and not a property path.
6270 * @param {*} value The value to check.
6271 * @param {Object} [object] The object to query keys on.
6272 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6274 function isKey(value, object) {
6275 if (isArray(value)) {
6278 var type = typeof value;
6279 if (type == 'number' || type == 'symbol' || type == 'boolean' ||
6280 value == null || isSymbol(value)) {
6283 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
6284 (object != null && value in Object(object));
6288 * Checks if `value` is suitable for use as unique object key.
6291 * @param {*} value The value to check.
6292 * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
6294 function isKeyable(value) {
6295 var type = typeof value;
6296 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
6297 ? (value !== '__proto__')
6302 * Checks if `func` has a lazy counterpart.
6305 * @param {Function} func The function to check.
6306 * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
6309 function isLaziable(func) {
6310 var funcName = getFuncName(func),
6311 other = lodash[funcName];
6313 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
6316 if (func === other) {
6319 var data = getData(other);
6320 return !!data && func === data[0];
6324 * Checks if `func` has its source masked.
6327 * @param {Function} func The function to check.
6328 * @returns {boolean} Returns `true` if `func` is masked, else `false`.
6330 function isMasked(func) {
6331 return !!maskSrcKey && (maskSrcKey in func);
6335 * Checks if `func` is capable of being masked.
6338 * @param {*} value The value to check.
6339 * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
6341 var isMaskable = coreJsData ? isFunction : stubFalse;
6344 * Checks if `value` is likely a prototype object.
6347 * @param {*} value The value to check.
6348 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
6350 function isPrototype(value) {
6351 var Ctor = value && value.constructor,
6352 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
6354 return value === proto;
6358 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
6361 * @param {*} value The value to check.
6362 * @returns {boolean} Returns `true` if `value` if suitable for strict
6363 * equality comparisons, else `false`.
6365 function isStrictComparable(value) {
6366 return value === value && !isObject(value);
6370 * A specialized version of `matchesProperty` for source values suitable
6371 * for strict equality comparisons, i.e. `===`.
6374 * @param {string} key The key of the property to get.
6375 * @param {*} srcValue The value to match.
6376 * @returns {Function} Returns the new spec function.
6378 function matchesStrictComparable(key, srcValue) {
6379 return function(object) {
6380 if (object == null) {
6383 return object[key] === srcValue &&
6384 (srcValue !== undefined || (key in Object(object)));
6389 * A specialized version of `_.memoize` which clears the memoized function's
6390 * cache when it exceeds `MAX_MEMOIZE_SIZE`.
6393 * @param {Function} func The function to have its output memoized.
6394 * @returns {Function} Returns the new memoized function.
6396 function memoizeCapped(func) {
6397 var result = memoize(func, function(key) {
6398 if (cache.size === MAX_MEMOIZE_SIZE) {
6404 var cache = result.cache;
6409 * Merges the function metadata of `source` into `data`.
6411 * Merging metadata reduces the number of wrappers used to invoke a function.
6412 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
6413 * may be applied regardless of execution order. Methods like `_.ary` and
6414 * `_.rearg` modify function arguments, making the order in which they are
6415 * executed important, preventing the merging of metadata. However, we make
6416 * an exception for a safe combined case where curried functions have `_.ary`
6417 * and or `_.rearg` applied.
6420 * @param {Array} data The destination metadata.
6421 * @param {Array} source The source metadata.
6422 * @returns {Array} Returns `data`.
6424 function mergeData(data, source) {
6425 var bitmask = data[1],
6426 srcBitmask = source[1],
6427 newBitmask = bitmask | srcBitmask,
6428 isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
6431 ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
6432 ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
6433 ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
6435 // Exit early if metadata can't be merged.
6436 if (!(isCommon || isCombo)) {
6439 // Use source `thisArg` if available.
6440 if (srcBitmask & BIND_FLAG) {
6441 data[2] = source[2];
6442 // Set when currying a bound function.
6443 newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
6445 // Compose partial arguments.
6446 var value = source[3];
6448 var partials = data[3];
6449 data[3] = partials ? composeArgs(partials, value, source[4]) : value;
6450 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
6452 // Compose partial right arguments.
6456 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
6457 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
6459 // Use source `argPos` if available.
6464 // Use source `ary` if it's smaller.
6465 if (srcBitmask & ARY_FLAG) {
6466 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
6468 // Use source `arity` if one is not provided.
6469 if (data[9] == null) {
6470 data[9] = source[9];
6472 // Use source `func` and merge bitmasks.
6473 data[0] = source[0];
6474 data[1] = newBitmask;
6480 * Used by `_.defaultsDeep` to customize its `_.merge` use.
6483 * @param {*} objValue The destination value.
6484 * @param {*} srcValue The source value.
6485 * @param {string} key The key of the property to merge.
6486 * @param {Object} object The parent object of `objValue`.
6487 * @param {Object} source The parent object of `srcValue`.
6488 * @param {Object} [stack] Tracks traversed source values and their merged
6490 * @returns {*} Returns the value to assign.
6492 function mergeDefaults(objValue, srcValue, key, object, source, stack) {
6493 if (isObject(objValue) && isObject(srcValue)) {
6494 // Recursively merge objects and arrays (susceptible to call stack limits).
6495 stack.set(srcValue, objValue);
6496 baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
6497 stack['delete'](srcValue);
6503 * This function is like
6504 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
6505 * except that it includes inherited enumerable properties.
6508 * @param {Object} object The object to query.
6509 * @returns {Array} Returns the array of property names.
6511 function nativeKeysIn(object) {
6513 if (object != null) {
6514 for (var key in Object(object)) {
6522 * Converts `value` to a string using `Object.prototype.toString`.
6525 * @param {*} value The value to convert.
6526 * @returns {string} Returns the converted string.
6528 function objectToString(value) {
6529 return nativeObjectToString.call(value);
6533 * A specialized version of `baseRest` which transforms the rest array.
6536 * @param {Function} func The function to apply a rest parameter to.
6537 * @param {number} [start=func.length-1] The start position of the rest parameter.
6538 * @param {Function} transform The rest array transform.
6539 * @returns {Function} Returns the new function.
6541 function overRest(func, start, transform) {
6542 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
6544 var args = arguments,
6546 length = nativeMax(args.length - start, 0),
6547 array = Array(length);
6549 while (++index < length) {
6550 array[index] = args[start + index];
6553 var otherArgs = Array(start + 1);
6554 while (++index < start) {
6555 otherArgs[index] = args[index];
6557 otherArgs[start] = transform(array);
6558 return apply(func, this, otherArgs);
6563 * Gets the parent value at `path` of `object`.
6566 * @param {Object} object The object to query.
6567 * @param {Array} path The path to get the parent value of.
6568 * @returns {*} Returns the parent value.
6570 function parent(object, path) {
6571 return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
6575 * Reorder `array` according to the specified indexes where the element at
6576 * the first index is assigned as the first element, the element at
6577 * the second index is assigned as the second element, and so on.
6580 * @param {Array} array The array to reorder.
6581 * @param {Array} indexes The arranged array indexes.
6582 * @returns {Array} Returns `array`.
6584 function reorder(array, indexes) {
6585 var arrLength = array.length,
6586 length = nativeMin(indexes.length, arrLength),
6587 oldArray = copyArray(array);
6590 var index = indexes[length];
6591 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
6597 * Sets metadata for `func`.
6599 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
6600 * period of time, it will trip its breaker and transition to an identity
6601 * function to avoid garbage collection pauses in V8. See
6602 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
6606 * @param {Function} func The function to associate metadata with.
6607 * @param {*} data The metadata.
6608 * @returns {Function} Returns `func`.
6610 var setData = shortOut(baseSetData);
6613 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
6616 * @param {Function} func The function to delay.
6617 * @param {number} wait The number of milliseconds to delay invocation.
6618 * @returns {number|Object} Returns the timer id or timeout object.
6620 var setTimeout = ctxSetTimeout || function(func, wait) {
6621 return root.setTimeout(func, wait);
6625 * Sets the `toString` method of `func` to return `string`.
6628 * @param {Function} func The function to modify.
6629 * @param {Function} string The `toString` result.
6630 * @returns {Function} Returns `func`.
6632 var setToString = shortOut(baseSetToString);
6635 * Sets the `toString` method of `wrapper` to mimic the source of `reference`
6636 * with wrapper details in a comment at the top of the source body.
6639 * @param {Function} wrapper The function to modify.
6640 * @param {Function} reference The reference function.
6641 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6642 * @returns {Function} Returns `wrapper`.
6644 function setWrapToString(wrapper, reference, bitmask) {
6645 var source = (reference + '');
6646 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
6650 * Creates a function that'll short out and invoke `identity` instead
6651 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
6655 * @param {Function} func The function to restrict.
6656 * @returns {Function} Returns the new shortable function.
6658 function shortOut(func) {
6663 var stamp = nativeNow(),
6664 remaining = HOT_SPAN - (stamp - lastCalled);
6667 if (remaining > 0) {
6668 if (++count >= HOT_COUNT) {
6669 return arguments[0];
6674 return func.apply(undefined, arguments);
6679 * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
6682 * @param {Array} array The array to shuffle.
6683 * @param {number} [size=array.length] The size of `array`.
6684 * @returns {Array} Returns `array`.
6686 function shuffleSelf(array, size) {
6688 length = array.length,
6689 lastIndex = length - 1;
6691 size = size === undefined ? length : size;
6692 while (++index < size) {
6693 var rand = baseRandom(index, lastIndex),
6694 value = array[rand];
6696 array[rand] = array[index];
6697 array[index] = value;
6699 array.length = size;
6704 * Converts `string` to a property path array.
6707 * @param {string} string The string to convert.
6708 * @returns {Array} Returns the property path array.
6710 var stringToPath = memoizeCapped(function(string) {
6711 string = toString(string);
6714 if (reLeadingDot.test(string)) {
6717 string.replace(rePropName, function(match, number, quote, string) {
6718 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
6724 * Converts `value` to a string key if it's not a string or symbol.
6727 * @param {*} value The value to inspect.
6728 * @returns {string|symbol} Returns the key.
6730 function toKey(value) {
6731 if (typeof value == 'string' || isSymbol(value)) {
6734 var result = (value + '');
6735 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
6739 * Converts `func` to its source code.
6742 * @param {Function} func The function to convert.
6743 * @returns {string} Returns the source code.
6745 function toSource(func) {
6748 return funcToString.call(func);
6758 * Updates wrapper `details` based on `bitmask` flags.
6761 * @returns {Array} details The details to modify.
6762 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
6763 * @returns {Array} Returns `details`.
6765 function updateWrapDetails(details, bitmask) {
6766 arrayEach(wrapFlags, function(pair) {
6767 var value = '_.' + pair[0];
6768 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
6769 details.push(value);
6772 return details.sort();
6776 * Creates a clone of `wrapper`.
6779 * @param {Object} wrapper The wrapper to clone.
6780 * @returns {Object} Returns the cloned wrapper.
6782 function wrapperClone(wrapper) {
6783 if (wrapper instanceof LazyWrapper) {
6784 return wrapper.clone();
6786 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
6787 result.__actions__ = copyArray(wrapper.__actions__);
6788 result.__index__ = wrapper.__index__;
6789 result.__values__ = wrapper.__values__;
6793 /*------------------------------------------------------------------------*/
6796 * Creates an array of elements split into groups the length of `size`.
6797 * If `array` can't be split evenly, the final chunk will be the remaining
6804 * @param {Array} array The array to process.
6805 * @param {number} [size=1] The length of each chunk
6806 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
6807 * @returns {Array} Returns the new array of chunks.
6810 * _.chunk(['a', 'b', 'c', 'd'], 2);
6811 * // => [['a', 'b'], ['c', 'd']]
6813 * _.chunk(['a', 'b', 'c', 'd'], 3);
6814 * // => [['a', 'b', 'c'], ['d']]
6816 function chunk(array, size, guard) {
6817 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
6820 size = nativeMax(toInteger(size), 0);
6822 var length = array == null ? 0 : array.length;
6823 if (!length || size < 1) {
6828 result = Array(nativeCeil(length / size));
6830 while (index < length) {
6831 result[resIndex++] = baseSlice(array, index, (index += size));
6837 * Creates an array with all falsey values removed. The values `false`, `null`,
6838 * `0`, `""`, `undefined`, and `NaN` are falsey.
6844 * @param {Array} array The array to compact.
6845 * @returns {Array} Returns the new array of filtered values.
6848 * _.compact([0, 1, false, 2, '', 3]);
6851 function compact(array) {
6853 length = array == null ? 0 : array.length,
6857 while (++index < length) {
6858 var value = array[index];
6860 result[resIndex++] = value;
6867 * Creates a new array concatenating `array` with any additional arrays
6874 * @param {Array} array The array to concatenate.
6875 * @param {...*} [values] The values to concatenate.
6876 * @returns {Array} Returns the new concatenated array.
6880 * var other = _.concat(array, 2, [3], [[4]]);
6882 * console.log(other);
6883 * // => [1, 2, 3, [4]]
6885 * console.log(array);
6889 var length = arguments.length;
6893 var args = Array(length - 1),
6894 array = arguments[0],
6898 args[index - 1] = arguments[index];
6900 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
6904 * Creates an array of `array` values not included in the other given arrays
6905 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
6906 * for equality comparisons. The order and references of result values are
6907 * determined by the first array.
6909 * **Note:** Unlike `_.pullAll`, this method returns a new array.
6915 * @param {Array} array The array to inspect.
6916 * @param {...Array} [values] The values to exclude.
6917 * @returns {Array} Returns the new array of filtered values.
6918 * @see _.without, _.xor
6921 * _.difference([2, 1], [2, 3]);
6924 var difference = baseRest(function(array, values) {
6925 return isArrayLikeObject(array)
6926 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
6931 * This method is like `_.difference` except that it accepts `iteratee` which
6932 * is invoked for each element of `array` and `values` to generate the criterion
6933 * by which they're compared. The order and references of result values are
6934 * determined by the first array. The iteratee is invoked with one argument:
6937 * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
6943 * @param {Array} array The array to inspect.
6944 * @param {...Array} [values] The values to exclude.
6945 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
6946 * @returns {Array} Returns the new array of filtered values.
6949 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
6952 * // The `_.property` iteratee shorthand.
6953 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
6954 * // => [{ 'x': 2 }]
6956 var differenceBy = baseRest(function(array, values) {
6957 var iteratee = last(values);
6958 if (isArrayLikeObject(iteratee)) {
6959 iteratee = undefined;
6961 return isArrayLikeObject(array)
6962 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
6967 * This method is like `_.difference` except that it accepts `comparator`
6968 * which is invoked to compare elements of `array` to `values`. The order and
6969 * references of result values are determined by the first array. The comparator
6970 * is invoked with two arguments: (arrVal, othVal).
6972 * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
6978 * @param {Array} array The array to inspect.
6979 * @param {...Array} [values] The values to exclude.
6980 * @param {Function} [comparator] The comparator invoked per element.
6981 * @returns {Array} Returns the new array of filtered values.
6984 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
6986 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
6987 * // => [{ 'x': 2, 'y': 1 }]
6989 var differenceWith = baseRest(function(array, values) {
6990 var comparator = last(values);
6991 if (isArrayLikeObject(comparator)) {
6992 comparator = undefined;
6994 return isArrayLikeObject(array)
6995 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
7000 * Creates a slice of `array` with `n` elements dropped from the beginning.
7006 * @param {Array} array The array to query.
7007 * @param {number} [n=1] The number of elements to drop.
7008 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7009 * @returns {Array} Returns the slice of `array`.
7012 * _.drop([1, 2, 3]);
7015 * _.drop([1, 2, 3], 2);
7018 * _.drop([1, 2, 3], 5);
7021 * _.drop([1, 2, 3], 0);
7024 function drop(array, n, guard) {
7025 var length = array == null ? 0 : array.length;
7029 n = (guard || n === undefined) ? 1 : toInteger(n);
7030 return baseSlice(array, n < 0 ? 0 : n, length);
7034 * Creates a slice of `array` with `n` elements dropped from the end.
7040 * @param {Array} array The array to query.
7041 * @param {number} [n=1] The number of elements to drop.
7042 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
7043 * @returns {Array} Returns the slice of `array`.
7046 * _.dropRight([1, 2, 3]);
7049 * _.dropRight([1, 2, 3], 2);
7052 * _.dropRight([1, 2, 3], 5);
7055 * _.dropRight([1, 2, 3], 0);
7058 function dropRight(array, n, guard) {
7059 var length = array == null ? 0 : array.length;
7063 n = (guard || n === undefined) ? 1 : toInteger(n);
7065 return baseSlice(array, 0, n < 0 ? 0 : n);
7069 * Creates a slice of `array` excluding elements dropped from the end.
7070 * Elements are dropped until `predicate` returns falsey. The predicate is
7071 * invoked with three arguments: (value, index, array).
7077 * @param {Array} array The array to query.
7078 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7079 * @returns {Array} Returns the slice of `array`.
7083 * { 'user': 'barney', 'active': true },
7084 * { 'user': 'fred', 'active': false },
7085 * { 'user': 'pebbles', 'active': false }
7088 * _.dropRightWhile(users, function(o) { return !o.active; });
7089 * // => objects for ['barney']
7091 * // The `_.matches` iteratee shorthand.
7092 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
7093 * // => objects for ['barney', 'fred']
7095 * // The `_.matchesProperty` iteratee shorthand.
7096 * _.dropRightWhile(users, ['active', false]);
7097 * // => objects for ['barney']
7099 * // The `_.property` iteratee shorthand.
7100 * _.dropRightWhile(users, 'active');
7101 * // => objects for ['barney', 'fred', 'pebbles']
7103 function dropRightWhile(array, predicate) {
7104 return (array && array.length)
7105 ? baseWhile(array, getIteratee(predicate, 3), true, true)
7110 * Creates a slice of `array` excluding elements dropped from the beginning.
7111 * Elements are dropped until `predicate` returns falsey. The predicate is
7112 * invoked with three arguments: (value, index, array).
7118 * @param {Array} array The array to query.
7119 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7120 * @returns {Array} Returns the slice of `array`.
7124 * { 'user': 'barney', 'active': false },
7125 * { 'user': 'fred', 'active': false },
7126 * { 'user': 'pebbles', 'active': true }
7129 * _.dropWhile(users, function(o) { return !o.active; });
7130 * // => objects for ['pebbles']
7132 * // The `_.matches` iteratee shorthand.
7133 * _.dropWhile(users, { 'user': 'barney', 'active': false });
7134 * // => objects for ['fred', 'pebbles']
7136 * // The `_.matchesProperty` iteratee shorthand.
7137 * _.dropWhile(users, ['active', false]);
7138 * // => objects for ['pebbles']
7140 * // The `_.property` iteratee shorthand.
7141 * _.dropWhile(users, 'active');
7142 * // => objects for ['barney', 'fred', 'pebbles']
7144 function dropWhile(array, predicate) {
7145 return (array && array.length)
7146 ? baseWhile(array, getIteratee(predicate, 3), true)
7151 * Fills elements of `array` with `value` from `start` up to, but not
7154 * **Note:** This method mutates `array`.
7160 * @param {Array} array The array to fill.
7161 * @param {*} value The value to fill `array` with.
7162 * @param {number} [start=0] The start position.
7163 * @param {number} [end=array.length] The end position.
7164 * @returns {Array} Returns `array`.
7167 * var array = [1, 2, 3];
7169 * _.fill(array, 'a');
7170 * console.log(array);
7171 * // => ['a', 'a', 'a']
7173 * _.fill(Array(3), 2);
7176 * _.fill([4, 6, 8, 10], '*', 1, 3);
7177 * // => [4, '*', '*', 10]
7179 function fill(array, value, start, end) {
7180 var length = array == null ? 0 : array.length;
7184 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
7188 return baseFill(array, value, start, end);
7192 * This method is like `_.find` except that it returns the index of the first
7193 * element `predicate` returns truthy for instead of the element itself.
7199 * @param {Array} array The array to inspect.
7200 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7201 * @param {number} [fromIndex=0] The index to search from.
7202 * @returns {number} Returns the index of the found element, else `-1`.
7206 * { 'user': 'barney', 'active': false },
7207 * { 'user': 'fred', 'active': false },
7208 * { 'user': 'pebbles', 'active': true }
7211 * _.findIndex(users, function(o) { return o.user == 'barney'; });
7214 * // The `_.matches` iteratee shorthand.
7215 * _.findIndex(users, { 'user': 'fred', 'active': false });
7218 * // The `_.matchesProperty` iteratee shorthand.
7219 * _.findIndex(users, ['active', false]);
7222 * // The `_.property` iteratee shorthand.
7223 * _.findIndex(users, 'active');
7226 function findIndex(array, predicate, fromIndex) {
7227 var length = array == null ? 0 : array.length;
7231 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7233 index = nativeMax(length + index, 0);
7235 return baseFindIndex(array, getIteratee(predicate, 3), index);
7239 * This method is like `_.findIndex` except that it iterates over elements
7240 * of `collection` from right to left.
7246 * @param {Array} array The array to inspect.
7247 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7248 * @param {number} [fromIndex=array.length-1] The index to search from.
7249 * @returns {number} Returns the index of the found element, else `-1`.
7253 * { 'user': 'barney', 'active': true },
7254 * { 'user': 'fred', 'active': false },
7255 * { 'user': 'pebbles', 'active': false }
7258 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
7261 * // The `_.matches` iteratee shorthand.
7262 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
7265 * // The `_.matchesProperty` iteratee shorthand.
7266 * _.findLastIndex(users, ['active', false]);
7269 * // The `_.property` iteratee shorthand.
7270 * _.findLastIndex(users, 'active');
7273 function findLastIndex(array, predicate, fromIndex) {
7274 var length = array == null ? 0 : array.length;
7278 var index = length - 1;
7279 if (fromIndex !== undefined) {
7280 index = toInteger(fromIndex);
7281 index = fromIndex < 0
7282 ? nativeMax(length + index, 0)
7283 : nativeMin(index, length - 1);
7285 return baseFindIndex(array, getIteratee(predicate, 3), index, true);
7289 * Flattens `array` a single level deep.
7295 * @param {Array} array The array to flatten.
7296 * @returns {Array} Returns the new flattened array.
7299 * _.flatten([1, [2, [3, [4]], 5]]);
7300 * // => [1, 2, [3, [4]], 5]
7302 function flatten(array) {
7303 var length = array == null ? 0 : array.length;
7304 return length ? baseFlatten(array, 1) : [];
7308 * Recursively flattens `array`.
7314 * @param {Array} array The array to flatten.
7315 * @returns {Array} Returns the new flattened array.
7318 * _.flattenDeep([1, [2, [3, [4]], 5]]);
7319 * // => [1, 2, 3, 4, 5]
7321 function flattenDeep(array) {
7322 var length = array == null ? 0 : array.length;
7323 return length ? baseFlatten(array, INFINITY) : [];
7327 * Recursively flatten `array` up to `depth` times.
7333 * @param {Array} array The array to flatten.
7334 * @param {number} [depth=1] The maximum recursion depth.
7335 * @returns {Array} Returns the new flattened array.
7338 * var array = [1, [2, [3, [4]], 5]];
7340 * _.flattenDepth(array, 1);
7341 * // => [1, 2, [3, [4]], 5]
7343 * _.flattenDepth(array, 2);
7344 * // => [1, 2, 3, [4], 5]
7346 function flattenDepth(array, depth) {
7347 var length = array == null ? 0 : array.length;
7351 depth = depth === undefined ? 1 : toInteger(depth);
7352 return baseFlatten(array, depth);
7356 * The inverse of `_.toPairs`; this method returns an object composed
7357 * from key-value `pairs`.
7363 * @param {Array} pairs The key-value pairs.
7364 * @returns {Object} Returns the new object.
7367 * _.fromPairs([['a', 1], ['b', 2]]);
7368 * // => { 'a': 1, 'b': 2 }
7370 function fromPairs(pairs) {
7372 length = pairs == null ? 0 : pairs.length,
7375 while (++index < length) {
7376 var pair = pairs[index];
7377 result[pair[0]] = pair[1];
7383 * Gets the first element of `array`.
7390 * @param {Array} array The array to query.
7391 * @returns {*} Returns the first element of `array`.
7394 * _.head([1, 2, 3]);
7400 function head(array) {
7401 return (array && array.length) ? array[0] : undefined;
7405 * Gets the index at which the first occurrence of `value` is found in `array`
7406 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7407 * for equality comparisons. If `fromIndex` is negative, it's used as the
7408 * offset from the end of `array`.
7414 * @param {Array} array The array to inspect.
7415 * @param {*} value The value to search for.
7416 * @param {number} [fromIndex=0] The index to search from.
7417 * @returns {number} Returns the index of the matched value, else `-1`.
7420 * _.indexOf([1, 2, 1, 2], 2);
7423 * // Search from the `fromIndex`.
7424 * _.indexOf([1, 2, 1, 2], 2, 2);
7427 function indexOf(array, value, fromIndex) {
7428 var length = array == null ? 0 : array.length;
7432 var index = fromIndex == null ? 0 : toInteger(fromIndex);
7434 index = nativeMax(length + index, 0);
7436 return baseIndexOf(array, value, index);
7440 * Gets all but the last element of `array`.
7446 * @param {Array} array The array to query.
7447 * @returns {Array} Returns the slice of `array`.
7450 * _.initial([1, 2, 3]);
7453 function initial(array) {
7454 var length = array == null ? 0 : array.length;
7455 return length ? baseSlice(array, 0, -1) : [];
7459 * Creates an array of unique values that are included in all given arrays
7460 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7461 * for equality comparisons. The order and references of result values are
7462 * determined by the first array.
7468 * @param {...Array} [arrays] The arrays to inspect.
7469 * @returns {Array} Returns the new array of intersecting values.
7472 * _.intersection([2, 1], [2, 3]);
7475 var intersection = baseRest(function(arrays) {
7476 var mapped = arrayMap(arrays, castArrayLikeObject);
7477 return (mapped.length && mapped[0] === arrays[0])
7478 ? baseIntersection(mapped)
7483 * This method is like `_.intersection` except that it accepts `iteratee`
7484 * which is invoked for each element of each `arrays` to generate the criterion
7485 * by which they're compared. The order and references of result values are
7486 * determined by the first array. The iteratee is invoked with one argument:
7493 * @param {...Array} [arrays] The arrays to inspect.
7494 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7495 * @returns {Array} Returns the new array of intersecting values.
7498 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
7501 * // The `_.property` iteratee shorthand.
7502 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
7503 * // => [{ 'x': 1 }]
7505 var intersectionBy = baseRest(function(arrays) {
7506 var iteratee = last(arrays),
7507 mapped = arrayMap(arrays, castArrayLikeObject);
7509 if (iteratee === last(mapped)) {
7510 iteratee = undefined;
7514 return (mapped.length && mapped[0] === arrays[0])
7515 ? baseIntersection(mapped, getIteratee(iteratee, 2))
7520 * This method is like `_.intersection` except that it accepts `comparator`
7521 * which is invoked to compare elements of `arrays`. The order and references
7522 * of result values are determined by the first array. The comparator is
7523 * invoked with two arguments: (arrVal, othVal).
7529 * @param {...Array} [arrays] The arrays to inspect.
7530 * @param {Function} [comparator] The comparator invoked per element.
7531 * @returns {Array} Returns the new array of intersecting values.
7534 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
7535 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
7537 * _.intersectionWith(objects, others, _.isEqual);
7538 * // => [{ 'x': 1, 'y': 2 }]
7540 var intersectionWith = baseRest(function(arrays) {
7541 var comparator = last(arrays),
7542 mapped = arrayMap(arrays, castArrayLikeObject);
7544 comparator = typeof comparator == 'function' ? comparator : undefined;
7548 return (mapped.length && mapped[0] === arrays[0])
7549 ? baseIntersection(mapped, undefined, comparator)
7554 * Converts all elements in `array` into a string separated by `separator`.
7560 * @param {Array} array The array to convert.
7561 * @param {string} [separator=','] The element separator.
7562 * @returns {string} Returns the joined string.
7565 * _.join(['a', 'b', 'c'], '~');
7568 function join(array, separator) {
7569 return array == null ? '' : nativeJoin.call(array, separator);
7573 * Gets the last element of `array`.
7579 * @param {Array} array The array to query.
7580 * @returns {*} Returns the last element of `array`.
7583 * _.last([1, 2, 3]);
7586 function last(array) {
7587 var length = array == null ? 0 : array.length;
7588 return length ? array[length - 1] : undefined;
7592 * This method is like `_.indexOf` except that it iterates over elements of
7593 * `array` from right to left.
7599 * @param {Array} array The array to inspect.
7600 * @param {*} value The value to search for.
7601 * @param {number} [fromIndex=array.length-1] The index to search from.
7602 * @returns {number} Returns the index of the matched value, else `-1`.
7605 * _.lastIndexOf([1, 2, 1, 2], 2);
7608 * // Search from the `fromIndex`.
7609 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
7612 function lastIndexOf(array, value, fromIndex) {
7613 var length = array == null ? 0 : array.length;
7618 if (fromIndex !== undefined) {
7619 index = toInteger(fromIndex);
7620 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
7622 return value === value
7623 ? strictLastIndexOf(array, value, index)
7624 : baseFindIndex(array, baseIsNaN, index, true);
7628 * Gets the element at index `n` of `array`. If `n` is negative, the nth
7629 * element from the end is returned.
7635 * @param {Array} array The array to query.
7636 * @param {number} [n=0] The index of the element to return.
7637 * @returns {*} Returns the nth element of `array`.
7640 * var array = ['a', 'b', 'c', 'd'];
7648 function nth(array, n) {
7649 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
7653 * Removes all given values from `array` using
7654 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
7655 * for equality comparisons.
7657 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
7658 * to remove elements from an array by predicate.
7664 * @param {Array} array The array to modify.
7665 * @param {...*} [values] The values to remove.
7666 * @returns {Array} Returns `array`.
7669 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7671 * _.pull(array, 'a', 'c');
7672 * console.log(array);
7675 var pull = baseRest(pullAll);
7678 * This method is like `_.pull` except that it accepts an array of values to remove.
7680 * **Note:** Unlike `_.difference`, this method mutates `array`.
7686 * @param {Array} array The array to modify.
7687 * @param {Array} values The values to remove.
7688 * @returns {Array} Returns `array`.
7691 * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
7693 * _.pullAll(array, ['a', 'c']);
7694 * console.log(array);
7697 function pullAll(array, values) {
7698 return (array && array.length && values && values.length)
7699 ? basePullAll(array, values)
7704 * This method is like `_.pullAll` except that it accepts `iteratee` which is
7705 * invoked for each element of `array` and `values` to generate the criterion
7706 * by which they're compared. The iteratee is invoked with one argument: (value).
7708 * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
7714 * @param {Array} array The array to modify.
7715 * @param {Array} values The values to remove.
7716 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7717 * @returns {Array} Returns `array`.
7720 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
7722 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
7723 * console.log(array);
7724 * // => [{ 'x': 2 }]
7726 function pullAllBy(array, values, iteratee) {
7727 return (array && array.length && values && values.length)
7728 ? basePullAll(array, values, getIteratee(iteratee, 2))
7733 * This method is like `_.pullAll` except that it accepts `comparator` which
7734 * is invoked to compare elements of `array` to `values`. The comparator is
7735 * invoked with two arguments: (arrVal, othVal).
7737 * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
7743 * @param {Array} array The array to modify.
7744 * @param {Array} values The values to remove.
7745 * @param {Function} [comparator] The comparator invoked per element.
7746 * @returns {Array} Returns `array`.
7749 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
7751 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
7752 * console.log(array);
7753 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
7755 function pullAllWith(array, values, comparator) {
7756 return (array && array.length && values && values.length)
7757 ? basePullAll(array, values, undefined, comparator)
7762 * Removes elements from `array` corresponding to `indexes` and returns an
7763 * array of removed elements.
7765 * **Note:** Unlike `_.at`, this method mutates `array`.
7771 * @param {Array} array The array to modify.
7772 * @param {...(number|number[])} [indexes] The indexes of elements to remove.
7773 * @returns {Array} Returns the new array of removed elements.
7776 * var array = ['a', 'b', 'c', 'd'];
7777 * var pulled = _.pullAt(array, [1, 3]);
7779 * console.log(array);
7782 * console.log(pulled);
7785 var pullAt = flatRest(function(array, indexes) {
7786 var length = array == null ? 0 : array.length,
7787 result = baseAt(array, indexes);
7789 basePullAt(array, arrayMap(indexes, function(index) {
7790 return isIndex(index, length) ? +index : index;
7791 }).sort(compareAscending));
7797 * Removes all elements from `array` that `predicate` returns truthy for
7798 * and returns an array of the removed elements. The predicate is invoked
7799 * with three arguments: (value, index, array).
7801 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
7802 * to pull elements from an array by value.
7808 * @param {Array} array The array to modify.
7809 * @param {Function} [predicate=_.identity] The function invoked per iteration.
7810 * @returns {Array} Returns the new array of removed elements.
7813 * var array = [1, 2, 3, 4];
7814 * var evens = _.remove(array, function(n) {
7815 * return n % 2 == 0;
7818 * console.log(array);
7821 * console.log(evens);
7824 function remove(array, predicate) {
7826 if (!(array && array.length)) {
7831 length = array.length;
7833 predicate = getIteratee(predicate, 3);
7834 while (++index < length) {
7835 var value = array[index];
7836 if (predicate(value, index, array)) {
7838 indexes.push(index);
7841 basePullAt(array, indexes);
7846 * Reverses `array` so that the first element becomes the last, the second
7847 * element becomes the second to last, and so on.
7849 * **Note:** This method mutates `array` and is based on
7850 * [`Array#reverse`](https://mdn.io/Array/reverse).
7856 * @param {Array} array The array to modify.
7857 * @returns {Array} Returns `array`.
7860 * var array = [1, 2, 3];
7865 * console.log(array);
7868 function reverse(array) {
7869 return array == null ? array : nativeReverse.call(array);
7873 * Creates a slice of `array` from `start` up to, but not including, `end`.
7875 * **Note:** This method is used instead of
7876 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
7883 * @param {Array} array The array to slice.
7884 * @param {number} [start=0] The start position.
7885 * @param {number} [end=array.length] The end position.
7886 * @returns {Array} Returns the slice of `array`.
7888 function slice(array, start, end) {
7889 var length = array == null ? 0 : array.length;
7893 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
7898 start = start == null ? 0 : toInteger(start);
7899 end = end === undefined ? length : toInteger(end);
7901 return baseSlice(array, start, end);
7905 * Uses a binary search to determine the lowest index at which `value`
7906 * should be inserted into `array` in order to maintain its sort order.
7912 * @param {Array} array The sorted array to inspect.
7913 * @param {*} value The value to evaluate.
7914 * @returns {number} Returns the index at which `value` should be inserted
7918 * _.sortedIndex([30, 50], 40);
7921 function sortedIndex(array, value) {
7922 return baseSortedIndex(array, value);
7926 * This method is like `_.sortedIndex` except that it accepts `iteratee`
7927 * which is invoked for `value` and each element of `array` to compute their
7928 * sort ranking. The iteratee is invoked with one argument: (value).
7934 * @param {Array} array The sorted array to inspect.
7935 * @param {*} value The value to evaluate.
7936 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
7937 * @returns {number} Returns the index at which `value` should be inserted
7941 * var objects = [{ 'x': 4 }, { 'x': 5 }];
7943 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
7946 * // The `_.property` iteratee shorthand.
7947 * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
7950 function sortedIndexBy(array, value, iteratee) {
7951 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
7955 * This method is like `_.indexOf` except that it performs a binary
7956 * search on a sorted `array`.
7962 * @param {Array} array The array to inspect.
7963 * @param {*} value The value to search for.
7964 * @returns {number} Returns the index of the matched value, else `-1`.
7967 * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
7970 function sortedIndexOf(array, value) {
7971 var length = array == null ? 0 : array.length;
7973 var index = baseSortedIndex(array, value);
7974 if (index < length && eq(array[index], value)) {
7982 * This method is like `_.sortedIndex` except that it returns the highest
7983 * index at which `value` should be inserted into `array` in order to
7984 * maintain its sort order.
7990 * @param {Array} array The sorted array to inspect.
7991 * @param {*} value The value to evaluate.
7992 * @returns {number} Returns the index at which `value` should be inserted
7996 * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
7999 function sortedLastIndex(array, value) {
8000 return baseSortedIndex(array, value, true);
8004 * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
8005 * which is invoked for `value` and each element of `array` to compute their
8006 * sort ranking. The iteratee is invoked with one argument: (value).
8012 * @param {Array} array The sorted array to inspect.
8013 * @param {*} value The value to evaluate.
8014 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8015 * @returns {number} Returns the index at which `value` should be inserted
8019 * var objects = [{ 'x': 4 }, { 'x': 5 }];
8021 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
8024 * // The `_.property` iteratee shorthand.
8025 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
8028 function sortedLastIndexBy(array, value, iteratee) {
8029 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
8033 * This method is like `_.lastIndexOf` except that it performs a binary
8034 * search on a sorted `array`.
8040 * @param {Array} array The array to inspect.
8041 * @param {*} value The value to search for.
8042 * @returns {number} Returns the index of the matched value, else `-1`.
8045 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
8048 function sortedLastIndexOf(array, value) {
8049 var length = array == null ? 0 : array.length;
8051 var index = baseSortedIndex(array, value, true) - 1;
8052 if (eq(array[index], value)) {
8060 * This method is like `_.uniq` except that it's designed and optimized
8061 * for sorted arrays.
8067 * @param {Array} array The array to inspect.
8068 * @returns {Array} Returns the new duplicate free array.
8071 * _.sortedUniq([1, 1, 2]);
8074 function sortedUniq(array) {
8075 return (array && array.length)
8076 ? baseSortedUniq(array)
8081 * This method is like `_.uniqBy` except that it's designed and optimized
8082 * for sorted arrays.
8088 * @param {Array} array The array to inspect.
8089 * @param {Function} [iteratee] The iteratee invoked per element.
8090 * @returns {Array} Returns the new duplicate free array.
8093 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
8096 function sortedUniqBy(array, iteratee) {
8097 return (array && array.length)
8098 ? baseSortedUniq(array, getIteratee(iteratee, 2))
8103 * Gets all but the first element of `array`.
8109 * @param {Array} array The array to query.
8110 * @returns {Array} Returns the slice of `array`.
8113 * _.tail([1, 2, 3]);
8116 function tail(array) {
8117 var length = array == null ? 0 : array.length;
8118 return length ? baseSlice(array, 1, length) : [];
8122 * Creates a slice of `array` with `n` elements taken from the beginning.
8128 * @param {Array} array The array to query.
8129 * @param {number} [n=1] The number of elements to take.
8130 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8131 * @returns {Array} Returns the slice of `array`.
8134 * _.take([1, 2, 3]);
8137 * _.take([1, 2, 3], 2);
8140 * _.take([1, 2, 3], 5);
8143 * _.take([1, 2, 3], 0);
8146 function take(array, n, guard) {
8147 if (!(array && array.length)) {
8150 n = (guard || n === undefined) ? 1 : toInteger(n);
8151 return baseSlice(array, 0, n < 0 ? 0 : n);
8155 * Creates a slice of `array` with `n` elements taken from the end.
8161 * @param {Array} array The array to query.
8162 * @param {number} [n=1] The number of elements to take.
8163 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
8164 * @returns {Array} Returns the slice of `array`.
8167 * _.takeRight([1, 2, 3]);
8170 * _.takeRight([1, 2, 3], 2);
8173 * _.takeRight([1, 2, 3], 5);
8176 * _.takeRight([1, 2, 3], 0);
8179 function takeRight(array, n, guard) {
8180 var length = array == null ? 0 : array.length;
8184 n = (guard || n === undefined) ? 1 : toInteger(n);
8186 return baseSlice(array, n < 0 ? 0 : n, length);
8190 * Creates a slice of `array` with elements taken from the end. Elements are
8191 * taken until `predicate` returns falsey. The predicate is invoked with
8192 * three arguments: (value, index, array).
8198 * @param {Array} array The array to query.
8199 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8200 * @returns {Array} Returns the slice of `array`.
8204 * { 'user': 'barney', 'active': true },
8205 * { 'user': 'fred', 'active': false },
8206 * { 'user': 'pebbles', 'active': false }
8209 * _.takeRightWhile(users, function(o) { return !o.active; });
8210 * // => objects for ['fred', 'pebbles']
8212 * // The `_.matches` iteratee shorthand.
8213 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
8214 * // => objects for ['pebbles']
8216 * // The `_.matchesProperty` iteratee shorthand.
8217 * _.takeRightWhile(users, ['active', false]);
8218 * // => objects for ['fred', 'pebbles']
8220 * // The `_.property` iteratee shorthand.
8221 * _.takeRightWhile(users, 'active');
8224 function takeRightWhile(array, predicate) {
8225 return (array && array.length)
8226 ? baseWhile(array, getIteratee(predicate, 3), false, true)
8231 * Creates a slice of `array` with elements taken from the beginning. Elements
8232 * are taken until `predicate` returns falsey. The predicate is invoked with
8233 * three arguments: (value, index, array).
8239 * @param {Array} array The array to query.
8240 * @param {Function} [predicate=_.identity] The function invoked per iteration.
8241 * @returns {Array} Returns the slice of `array`.
8245 * { 'user': 'barney', 'active': false },
8246 * { 'user': 'fred', 'active': false},
8247 * { 'user': 'pebbles', 'active': true }
8250 * _.takeWhile(users, function(o) { return !o.active; });
8251 * // => objects for ['barney', 'fred']
8253 * // The `_.matches` iteratee shorthand.
8254 * _.takeWhile(users, { 'user': 'barney', 'active': false });
8255 * // => objects for ['barney']
8257 * // The `_.matchesProperty` iteratee shorthand.
8258 * _.takeWhile(users, ['active', false]);
8259 * // => objects for ['barney', 'fred']
8261 * // The `_.property` iteratee shorthand.
8262 * _.takeWhile(users, 'active');
8265 function takeWhile(array, predicate) {
8266 return (array && array.length)
8267 ? baseWhile(array, getIteratee(predicate, 3))
8272 * Creates an array of unique values, in order, from all given arrays using
8273 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8274 * for equality comparisons.
8280 * @param {...Array} [arrays] The arrays to inspect.
8281 * @returns {Array} Returns the new array of combined values.
8284 * _.union([2], [1, 2]);
8287 var union = baseRest(function(arrays) {
8288 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
8292 * This method is like `_.union` except that it accepts `iteratee` which is
8293 * invoked for each element of each `arrays` to generate the criterion by
8294 * which uniqueness is computed. Result values are chosen from the first
8295 * array in which the value occurs. The iteratee is invoked with one argument:
8302 * @param {...Array} [arrays] The arrays to inspect.
8303 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8304 * @returns {Array} Returns the new array of combined values.
8307 * _.unionBy([2.1], [1.2, 2.3], Math.floor);
8310 * // The `_.property` iteratee shorthand.
8311 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8312 * // => [{ 'x': 1 }, { 'x': 2 }]
8314 var unionBy = baseRest(function(arrays) {
8315 var iteratee = last(arrays);
8316 if (isArrayLikeObject(iteratee)) {
8317 iteratee = undefined;
8319 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
8323 * This method is like `_.union` except that it accepts `comparator` which
8324 * is invoked to compare elements of `arrays`. Result values are chosen from
8325 * the first array in which the value occurs. The comparator is invoked
8326 * with two arguments: (arrVal, othVal).
8332 * @param {...Array} [arrays] The arrays to inspect.
8333 * @param {Function} [comparator] The comparator invoked per element.
8334 * @returns {Array} Returns the new array of combined values.
8337 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8338 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8340 * _.unionWith(objects, others, _.isEqual);
8341 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8343 var unionWith = baseRest(function(arrays) {
8344 var comparator = last(arrays);
8345 comparator = typeof comparator == 'function' ? comparator : undefined;
8346 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
8350 * Creates a duplicate-free version of an array, using
8351 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8352 * for equality comparisons, in which only the first occurrence of each element
8353 * is kept. The order of result values is determined by the order they occur
8360 * @param {Array} array The array to inspect.
8361 * @returns {Array} Returns the new duplicate free array.
8364 * _.uniq([2, 1, 2]);
8367 function uniq(array) {
8368 return (array && array.length) ? baseUniq(array) : [];
8372 * This method is like `_.uniq` except that it accepts `iteratee` which is
8373 * invoked for each element in `array` to generate the criterion by which
8374 * uniqueness is computed. The order of result values is determined by the
8375 * order they occur in the array. The iteratee is invoked with one argument:
8382 * @param {Array} array The array to inspect.
8383 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8384 * @returns {Array} Returns the new duplicate free array.
8387 * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
8390 * // The `_.property` iteratee shorthand.
8391 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
8392 * // => [{ 'x': 1 }, { 'x': 2 }]
8394 function uniqBy(array, iteratee) {
8395 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
8399 * This method is like `_.uniq` except that it accepts `comparator` which
8400 * is invoked to compare elements of `array`. The order of result values is
8401 * determined by the order they occur in the array.The comparator is invoked
8402 * with two arguments: (arrVal, othVal).
8408 * @param {Array} array The array to inspect.
8409 * @param {Function} [comparator] The comparator invoked per element.
8410 * @returns {Array} Returns the new duplicate free array.
8413 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
8415 * _.uniqWith(objects, _.isEqual);
8416 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
8418 function uniqWith(array, comparator) {
8419 comparator = typeof comparator == 'function' ? comparator : undefined;
8420 return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
8424 * This method is like `_.zip` except that it accepts an array of grouped
8425 * elements and creates an array regrouping the elements to their pre-zip
8432 * @param {Array} array The array of grouped elements to process.
8433 * @returns {Array} Returns the new array of regrouped elements.
8436 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
8437 * // => [['a', 1, true], ['b', 2, false]]
8440 * // => [['a', 'b'], [1, 2], [true, false]]
8442 function unzip(array) {
8443 if (!(array && array.length)) {
8447 array = arrayFilter(array, function(group) {
8448 if (isArrayLikeObject(group)) {
8449 length = nativeMax(group.length, length);
8453 return baseTimes(length, function(index) {
8454 return arrayMap(array, baseProperty(index));
8459 * This method is like `_.unzip` except that it accepts `iteratee` to specify
8460 * how regrouped values should be combined. The iteratee is invoked with the
8461 * elements of each group: (...group).
8467 * @param {Array} array The array of grouped elements to process.
8468 * @param {Function} [iteratee=_.identity] The function to combine
8470 * @returns {Array} Returns the new array of regrouped elements.
8473 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
8474 * // => [[1, 10, 100], [2, 20, 200]]
8476 * _.unzipWith(zipped, _.add);
8477 * // => [3, 30, 300]
8479 function unzipWith(array, iteratee) {
8480 if (!(array && array.length)) {
8483 var result = unzip(array);
8484 if (iteratee == null) {
8487 return arrayMap(result, function(group) {
8488 return apply(iteratee, undefined, group);
8493 * Creates an array excluding all given values using
8494 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
8495 * for equality comparisons.
8497 * **Note:** Unlike `_.pull`, this method returns a new array.
8503 * @param {Array} array The array to inspect.
8504 * @param {...*} [values] The values to exclude.
8505 * @returns {Array} Returns the new array of filtered values.
8506 * @see _.difference, _.xor
8509 * _.without([2, 1, 2, 3], 1, 2);
8512 var without = baseRest(function(array, values) {
8513 return isArrayLikeObject(array)
8514 ? baseDifference(array, values)
8519 * Creates an array of unique values that is the
8520 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
8521 * of the given arrays. The order of result values is determined by the order
8522 * they occur in the arrays.
8528 * @param {...Array} [arrays] The arrays to inspect.
8529 * @returns {Array} Returns the new array of filtered values.
8530 * @see _.difference, _.without
8533 * _.xor([2, 1], [2, 3]);
8536 var xor = baseRest(function(arrays) {
8537 return baseXor(arrayFilter(arrays, isArrayLikeObject));
8541 * This method is like `_.xor` except that it accepts `iteratee` which is
8542 * invoked for each element of each `arrays` to generate the criterion by
8543 * which by which they're compared. The order of result values is determined
8544 * by the order they occur in the arrays. The iteratee is invoked with one
8545 * argument: (value).
8551 * @param {...Array} [arrays] The arrays to inspect.
8552 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
8553 * @returns {Array} Returns the new array of filtered values.
8556 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
8559 * // The `_.property` iteratee shorthand.
8560 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
8561 * // => [{ 'x': 2 }]
8563 var xorBy = baseRest(function(arrays) {
8564 var iteratee = last(arrays);
8565 if (isArrayLikeObject(iteratee)) {
8566 iteratee = undefined;
8568 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
8572 * This method is like `_.xor` except that it accepts `comparator` which is
8573 * invoked to compare elements of `arrays`. The order of result values is
8574 * determined by the order they occur in the arrays. The comparator is invoked
8575 * with two arguments: (arrVal, othVal).
8581 * @param {...Array} [arrays] The arrays to inspect.
8582 * @param {Function} [comparator] The comparator invoked per element.
8583 * @returns {Array} Returns the new array of filtered values.
8586 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
8587 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
8589 * _.xorWith(objects, others, _.isEqual);
8590 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
8592 var xorWith = baseRest(function(arrays) {
8593 var comparator = last(arrays);
8594 comparator = typeof comparator == 'function' ? comparator : undefined;
8595 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
8599 * Creates an array of grouped elements, the first of which contains the
8600 * first elements of the given arrays, the second of which contains the
8601 * second elements of the given arrays, and so on.
8607 * @param {...Array} [arrays] The arrays to process.
8608 * @returns {Array} Returns the new array of grouped elements.
8611 * _.zip(['a', 'b'], [1, 2], [true, false]);
8612 * // => [['a', 1, true], ['b', 2, false]]
8614 var zip = baseRest(unzip);
8617 * This method is like `_.fromPairs` except that it accepts two arrays,
8618 * one of property identifiers and one of corresponding values.
8624 * @param {Array} [props=[]] The property identifiers.
8625 * @param {Array} [values=[]] The property values.
8626 * @returns {Object} Returns the new object.
8629 * _.zipObject(['a', 'b'], [1, 2]);
8630 * // => { 'a': 1, 'b': 2 }
8632 function zipObject(props, values) {
8633 return baseZipObject(props || [], values || [], assignValue);
8637 * This method is like `_.zipObject` except that it supports property paths.
8643 * @param {Array} [props=[]] The property identifiers.
8644 * @param {Array} [values=[]] The property values.
8645 * @returns {Object} Returns the new object.
8648 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
8649 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
8651 function zipObjectDeep(props, values) {
8652 return baseZipObject(props || [], values || [], baseSet);
8656 * This method is like `_.zip` except that it accepts `iteratee` to specify
8657 * how grouped values should be combined. The iteratee is invoked with the
8658 * elements of each group: (...group).
8664 * @param {...Array} [arrays] The arrays to process.
8665 * @param {Function} [iteratee=_.identity] The function to combine
8667 * @returns {Array} Returns the new array of grouped elements.
8670 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
8675 var zipWith = baseRest(function(arrays) {
8676 var length = arrays.length,
8677 iteratee = length > 1 ? arrays[length - 1] : undefined;
8679 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
8680 return unzipWith(arrays, iteratee);
8683 /*------------------------------------------------------------------------*/
8686 * Creates a `lodash` wrapper instance that wraps `value` with explicit method
8687 * chain sequences enabled. The result of such sequences must be unwrapped
8694 * @param {*} value The value to wrap.
8695 * @returns {Object} Returns the new `lodash` wrapper instance.
8699 * { 'user': 'barney', 'age': 36 },
8700 * { 'user': 'fred', 'age': 40 },
8701 * { 'user': 'pebbles', 'age': 1 }
8707 * .map(function(o) {
8708 * return o.user + ' is ' + o.age;
8712 * // => 'pebbles is 1'
8714 function chain(value) {
8715 var result = lodash(value);
8716 result.__chain__ = true;
8721 * This method invokes `interceptor` and returns `value`. The interceptor
8722 * is invoked with one argument; (value). The purpose of this method is to
8723 * "tap into" a method chain sequence in order to modify intermediate results.
8729 * @param {*} value The value to provide to `interceptor`.
8730 * @param {Function} interceptor The function to invoke.
8731 * @returns {*} Returns `value`.
8735 * .tap(function(array) {
8736 * // Mutate input array.
8743 function tap(value, interceptor) {
8749 * This method is like `_.tap` except that it returns the result of `interceptor`.
8750 * The purpose of this method is to "pass thru" values replacing intermediate
8751 * results in a method chain sequence.
8757 * @param {*} value The value to provide to `interceptor`.
8758 * @param {Function} interceptor The function to invoke.
8759 * @returns {*} Returns the result of `interceptor`.
8765 * .thru(function(value) {
8771 function thru(value, interceptor) {
8772 return interceptor(value);
8776 * This method is the wrapper version of `_.at`.
8782 * @param {...(string|string[])} [paths] The property paths of elements to pick.
8783 * @returns {Object} Returns the new `lodash` wrapper instance.
8786 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
8788 * _(object).at(['a[0].b.c', 'a[1]']).value();
8791 var wrapperAt = flatRest(function(paths) {
8792 var length = paths.length,
8793 start = length ? paths[0] : 0,
8794 value = this.__wrapped__,
8795 interceptor = function(object) { return baseAt(object, paths); };
8797 if (length > 1 || this.__actions__.length ||
8798 !(value instanceof LazyWrapper) || !isIndex(start)) {
8799 return this.thru(interceptor);
8801 value = value.slice(start, +start + (length ? 1 : 0));
8802 value.__actions__.push({
8804 'args': [interceptor],
8805 'thisArg': undefined
8807 return new LodashWrapper(value, this.__chain__).thru(function(array) {
8808 if (length && !array.length) {
8809 array.push(undefined);
8816 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
8822 * @returns {Object} Returns the new `lodash` wrapper instance.
8826 * { 'user': 'barney', 'age': 36 },
8827 * { 'user': 'fred', 'age': 40 }
8830 * // A sequence without explicit chaining.
8832 * // => { 'user': 'barney', 'age': 36 }
8834 * // A sequence with explicit chaining.
8840 * // => { 'user': 'barney' }
8842 function wrapperChain() {
8847 * Executes the chain sequence and returns the wrapped result.
8853 * @returns {Object} Returns the new `lodash` wrapper instance.
8856 * var array = [1, 2];
8857 * var wrapped = _(array).push(3);
8859 * console.log(array);
8862 * wrapped = wrapped.commit();
8863 * console.log(array);
8869 * console.log(array);
8872 function wrapperCommit() {
8873 return new LodashWrapper(this.value(), this.__chain__);
8877 * Gets the next value on a wrapped object following the
8878 * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
8884 * @returns {Object} Returns the next iterator value.
8887 * var wrapped = _([1, 2]);
8890 * // => { 'done': false, 'value': 1 }
8893 * // => { 'done': false, 'value': 2 }
8896 * // => { 'done': true, 'value': undefined }
8898 function wrapperNext() {
8899 if (this.__values__ === undefined) {
8900 this.__values__ = toArray(this.value());
8902 var done = this.__index__ >= this.__values__.length,
8903 value = done ? undefined : this.__values__[this.__index__++];
8905 return { 'done': done, 'value': value };
8909 * Enables the wrapper to be iterable.
8911 * @name Symbol.iterator
8915 * @returns {Object} Returns the wrapper object.
8918 * var wrapped = _([1, 2]);
8920 * wrapped[Symbol.iterator]() === wrapped;
8923 * Array.from(wrapped);
8926 function wrapperToIterator() {
8931 * Creates a clone of the chain sequence planting `value` as the wrapped value.
8937 * @param {*} value The value to plant.
8938 * @returns {Object} Returns the new `lodash` wrapper instance.
8941 * function square(n) {
8945 * var wrapped = _([1, 2]).map(square);
8946 * var other = wrapped.plant([3, 4]);
8954 function wrapperPlant(value) {
8958 while (parent instanceof baseLodash) {
8959 var clone = wrapperClone(parent);
8960 clone.__index__ = 0;
8961 clone.__values__ = undefined;
8963 previous.__wrapped__ = clone;
8967 var previous = clone;
8968 parent = parent.__wrapped__;
8970 previous.__wrapped__ = value;
8975 * This method is the wrapper version of `_.reverse`.
8977 * **Note:** This method mutates the wrapped array.
8983 * @returns {Object} Returns the new `lodash` wrapper instance.
8986 * var array = [1, 2, 3];
8988 * _(array).reverse().value()
8991 * console.log(array);
8994 function wrapperReverse() {
8995 var value = this.__wrapped__;
8996 if (value instanceof LazyWrapper) {
8997 var wrapped = value;
8998 if (this.__actions__.length) {
8999 wrapped = new LazyWrapper(this);
9001 wrapped = wrapped.reverse();
9002 wrapped.__actions__.push({
9005 'thisArg': undefined
9007 return new LodashWrapper(wrapped, this.__chain__);
9009 return this.thru(reverse);
9013 * Executes the chain sequence to resolve the unwrapped value.
9018 * @alias toJSON, valueOf
9020 * @returns {*} Returns the resolved unwrapped value.
9023 * _([1, 2, 3]).value();
9026 function wrapperValue() {
9027 return baseWrapperValue(this.__wrapped__, this.__actions__);
9030 /*------------------------------------------------------------------------*/
9033 * Creates an object composed of keys generated from the results of running
9034 * each element of `collection` thru `iteratee`. The corresponding value of
9035 * each key is the number of times the key was returned by `iteratee`. The
9036 * iteratee is invoked with one argument: (value).
9041 * @category Collection
9042 * @param {Array|Object} collection The collection to iterate over.
9043 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9044 * @returns {Object} Returns the composed aggregate object.
9047 * _.countBy([6.1, 4.2, 6.3], Math.floor);
9048 * // => { '4': 1, '6': 2 }
9050 * // The `_.property` iteratee shorthand.
9051 * _.countBy(['one', 'two', 'three'], 'length');
9052 * // => { '3': 2, '5': 1 }
9054 var countBy = createAggregator(function(result, value, key) {
9055 if (hasOwnProperty.call(result, key)) {
9058 baseAssignValue(result, key, 1);
9063 * Checks if `predicate` returns truthy for **all** elements of `collection`.
9064 * Iteration is stopped once `predicate` returns falsey. The predicate is
9065 * invoked with three arguments: (value, index|key, collection).
9067 * **Note:** This method returns `true` for
9068 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
9069 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
9070 * elements of empty collections.
9075 * @category Collection
9076 * @param {Array|Object} collection The collection to iterate over.
9077 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9078 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9079 * @returns {boolean} Returns `true` if all elements pass the predicate check,
9083 * _.every([true, 1, null, 'yes'], Boolean);
9087 * { 'user': 'barney', 'age': 36, 'active': false },
9088 * { 'user': 'fred', 'age': 40, 'active': false }
9091 * // The `_.matches` iteratee shorthand.
9092 * _.every(users, { 'user': 'barney', 'active': false });
9095 * // The `_.matchesProperty` iteratee shorthand.
9096 * _.every(users, ['active', false]);
9099 * // The `_.property` iteratee shorthand.
9100 * _.every(users, 'active');
9103 function every(collection, predicate, guard) {
9104 var func = isArray(collection) ? arrayEvery : baseEvery;
9105 if (guard && isIterateeCall(collection, predicate, guard)) {
9106 predicate = undefined;
9108 return func(collection, getIteratee(predicate, 3));
9112 * Iterates over elements of `collection`, returning an array of all elements
9113 * `predicate` returns truthy for. The predicate is invoked with three
9114 * arguments: (value, index|key, collection).
9116 * **Note:** Unlike `_.remove`, this method returns a new array.
9121 * @category Collection
9122 * @param {Array|Object} collection The collection to iterate over.
9123 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9124 * @returns {Array} Returns the new filtered array.
9129 * { 'user': 'barney', 'age': 36, 'active': true },
9130 * { 'user': 'fred', 'age': 40, 'active': false }
9133 * _.filter(users, function(o) { return !o.active; });
9134 * // => objects for ['fred']
9136 * // The `_.matches` iteratee shorthand.
9137 * _.filter(users, { 'age': 36, 'active': true });
9138 * // => objects for ['barney']
9140 * // The `_.matchesProperty` iteratee shorthand.
9141 * _.filter(users, ['active', false]);
9142 * // => objects for ['fred']
9144 * // The `_.property` iteratee shorthand.
9145 * _.filter(users, 'active');
9146 * // => objects for ['barney']
9148 function filter(collection, predicate) {
9149 var func = isArray(collection) ? arrayFilter : baseFilter;
9150 return func(collection, getIteratee(predicate, 3));
9154 * Iterates over elements of `collection`, returning the first element
9155 * `predicate` returns truthy for. The predicate is invoked with three
9156 * arguments: (value, index|key, collection).
9161 * @category Collection
9162 * @param {Array|Object} collection The collection to inspect.
9163 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9164 * @param {number} [fromIndex=0] The index to search from.
9165 * @returns {*} Returns the matched element, else `undefined`.
9169 * { 'user': 'barney', 'age': 36, 'active': true },
9170 * { 'user': 'fred', 'age': 40, 'active': false },
9171 * { 'user': 'pebbles', 'age': 1, 'active': true }
9174 * _.find(users, function(o) { return o.age < 40; });
9175 * // => object for 'barney'
9177 * // The `_.matches` iteratee shorthand.
9178 * _.find(users, { 'age': 1, 'active': true });
9179 * // => object for 'pebbles'
9181 * // The `_.matchesProperty` iteratee shorthand.
9182 * _.find(users, ['active', false]);
9183 * // => object for 'fred'
9185 * // The `_.property` iteratee shorthand.
9186 * _.find(users, 'active');
9187 * // => object for 'barney'
9189 var find = createFind(findIndex);
9192 * This method is like `_.find` except that it iterates over elements of
9193 * `collection` from right to left.
9198 * @category Collection
9199 * @param {Array|Object} collection The collection to inspect.
9200 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9201 * @param {number} [fromIndex=collection.length-1] The index to search from.
9202 * @returns {*} Returns the matched element, else `undefined`.
9205 * _.findLast([1, 2, 3, 4], function(n) {
9206 * return n % 2 == 1;
9210 var findLast = createFind(findLastIndex);
9213 * Creates a flattened array of values by running each element in `collection`
9214 * thru `iteratee` and flattening the mapped results. The iteratee is invoked
9215 * with three arguments: (value, index|key, collection).
9220 * @category Collection
9221 * @param {Array|Object} collection The collection to iterate over.
9222 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9223 * @returns {Array} Returns the new flattened array.
9226 * function duplicate(n) {
9230 * _.flatMap([1, 2], duplicate);
9231 * // => [1, 1, 2, 2]
9233 function flatMap(collection, iteratee) {
9234 return baseFlatten(map(collection, iteratee), 1);
9238 * This method is like `_.flatMap` except that it recursively flattens the
9244 * @category Collection
9245 * @param {Array|Object} collection The collection to iterate over.
9246 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9247 * @returns {Array} Returns the new flattened array.
9250 * function duplicate(n) {
9251 * return [[[n, n]]];
9254 * _.flatMapDeep([1, 2], duplicate);
9255 * // => [1, 1, 2, 2]
9257 function flatMapDeep(collection, iteratee) {
9258 return baseFlatten(map(collection, iteratee), INFINITY);
9262 * This method is like `_.flatMap` except that it recursively flattens the
9263 * mapped results up to `depth` times.
9268 * @category Collection
9269 * @param {Array|Object} collection The collection to iterate over.
9270 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9271 * @param {number} [depth=1] The maximum recursion depth.
9272 * @returns {Array} Returns the new flattened array.
9275 * function duplicate(n) {
9276 * return [[[n, n]]];
9279 * _.flatMapDepth([1, 2], duplicate, 2);
9280 * // => [[1, 1], [2, 2]]
9282 function flatMapDepth(collection, iteratee, depth) {
9283 depth = depth === undefined ? 1 : toInteger(depth);
9284 return baseFlatten(map(collection, iteratee), depth);
9288 * Iterates over elements of `collection` and invokes `iteratee` for each element.
9289 * The iteratee is invoked with three arguments: (value, index|key, collection).
9290 * Iteratee functions may exit iteration early by explicitly returning `false`.
9292 * **Note:** As with other "Collections" methods, objects with a "length"
9293 * property are iterated like arrays. To avoid this behavior use `_.forIn`
9294 * or `_.forOwn` for object iteration.
9300 * @category Collection
9301 * @param {Array|Object} collection The collection to iterate over.
9302 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9303 * @returns {Array|Object} Returns `collection`.
9304 * @see _.forEachRight
9307 * _.forEach([1, 2], function(value) {
9308 * console.log(value);
9310 * // => Logs `1` then `2`.
9312 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
9315 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
9317 function forEach(collection, iteratee) {
9318 var func = isArray(collection) ? arrayEach : baseEach;
9319 return func(collection, getIteratee(iteratee, 3));
9323 * This method is like `_.forEach` except that it iterates over elements of
9324 * `collection` from right to left.
9330 * @category Collection
9331 * @param {Array|Object} collection The collection to iterate over.
9332 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9333 * @returns {Array|Object} Returns `collection`.
9337 * _.forEachRight([1, 2], function(value) {
9338 * console.log(value);
9340 * // => Logs `2` then `1`.
9342 function forEachRight(collection, iteratee) {
9343 var func = isArray(collection) ? arrayEachRight : baseEachRight;
9344 return func(collection, getIteratee(iteratee, 3));
9348 * Creates an object composed of keys generated from the results of running
9349 * each element of `collection` thru `iteratee`. The order of grouped values
9350 * is determined by the order they occur in `collection`. The corresponding
9351 * value of each key is an array of elements responsible for generating the
9352 * key. The iteratee is invoked with one argument: (value).
9357 * @category Collection
9358 * @param {Array|Object} collection The collection to iterate over.
9359 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9360 * @returns {Object} Returns the composed aggregate object.
9363 * _.groupBy([6.1, 4.2, 6.3], Math.floor);
9364 * // => { '4': [4.2], '6': [6.1, 6.3] }
9366 * // The `_.property` iteratee shorthand.
9367 * _.groupBy(['one', 'two', 'three'], 'length');
9368 * // => { '3': ['one', 'two'], '5': ['three'] }
9370 var groupBy = createAggregator(function(result, value, key) {
9371 if (hasOwnProperty.call(result, key)) {
9372 result[key].push(value);
9374 baseAssignValue(result, key, [value]);
9379 * Checks if `value` is in `collection`. If `collection` is a string, it's
9380 * checked for a substring of `value`, otherwise
9381 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
9382 * is used for equality comparisons. If `fromIndex` is negative, it's used as
9383 * the offset from the end of `collection`.
9388 * @category Collection
9389 * @param {Array|Object|string} collection The collection to inspect.
9390 * @param {*} value The value to search for.
9391 * @param {number} [fromIndex=0] The index to search from.
9392 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9393 * @returns {boolean} Returns `true` if `value` is found, else `false`.
9396 * _.includes([1, 2, 3], 1);
9399 * _.includes([1, 2, 3], 1, 2);
9402 * _.includes({ 'a': 1, 'b': 2 }, 1);
9405 * _.includes('abcd', 'bc');
9408 function includes(collection, value, fromIndex, guard) {
9409 collection = isArrayLike(collection) ? collection : values(collection);
9410 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
9412 var length = collection.length;
9413 if (fromIndex < 0) {
9414 fromIndex = nativeMax(length + fromIndex, 0);
9416 return isString(collection)
9417 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
9418 : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
9422 * Invokes the method at `path` of each element in `collection`, returning
9423 * an array of the results of each invoked method. Any additional arguments
9424 * are provided to each invoked method. If `path` is a function, it's invoked
9425 * for, and `this` bound to, each element in `collection`.
9430 * @category Collection
9431 * @param {Array|Object} collection The collection to iterate over.
9432 * @param {Array|Function|string} path The path of the method to invoke or
9433 * the function invoked per iteration.
9434 * @param {...*} [args] The arguments to invoke each method with.
9435 * @returns {Array} Returns the array of results.
9438 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
9439 * // => [[1, 5, 7], [1, 2, 3]]
9441 * _.invokeMap([123, 456], String.prototype.split, '');
9442 * // => [['1', '2', '3'], ['4', '5', '6']]
9444 var invokeMap = baseRest(function(collection, path, args) {
9446 isFunc = typeof path == 'function',
9447 isProp = isKey(path),
9448 result = isArrayLike(collection) ? Array(collection.length) : [];
9450 baseEach(collection, function(value) {
9451 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
9452 result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
9458 * Creates an object composed of keys generated from the results of running
9459 * each element of `collection` thru `iteratee`. The corresponding value of
9460 * each key is the last element responsible for generating the key. The
9461 * iteratee is invoked with one argument: (value).
9466 * @category Collection
9467 * @param {Array|Object} collection The collection to iterate over.
9468 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
9469 * @returns {Object} Returns the composed aggregate object.
9473 * { 'dir': 'left', 'code': 97 },
9474 * { 'dir': 'right', 'code': 100 }
9477 * _.keyBy(array, function(o) {
9478 * return String.fromCharCode(o.code);
9480 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
9482 * _.keyBy(array, 'dir');
9483 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
9485 var keyBy = createAggregator(function(result, value, key) {
9486 baseAssignValue(result, key, value);
9490 * Creates an array of values by running each element in `collection` thru
9491 * `iteratee`. The iteratee is invoked with three arguments:
9492 * (value, index|key, collection).
9494 * Many lodash methods are guarded to work as iteratees for methods like
9495 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
9497 * The guarded methods are:
9498 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
9499 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
9500 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
9501 * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
9506 * @category Collection
9507 * @param {Array|Object} collection The collection to iterate over.
9508 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9509 * @returns {Array} Returns the new mapped array.
9512 * function square(n) {
9516 * _.map([4, 8], square);
9519 * _.map({ 'a': 4, 'b': 8 }, square);
9520 * // => [16, 64] (iteration order is not guaranteed)
9523 * { 'user': 'barney' },
9524 * { 'user': 'fred' }
9527 * // The `_.property` iteratee shorthand.
9528 * _.map(users, 'user');
9529 * // => ['barney', 'fred']
9531 function map(collection, iteratee) {
9532 var func = isArray(collection) ? arrayMap : baseMap;
9533 return func(collection, getIteratee(iteratee, 3));
9537 * This method is like `_.sortBy` except that it allows specifying the sort
9538 * orders of the iteratees to sort by. If `orders` is unspecified, all values
9539 * are sorted in ascending order. Otherwise, specify an order of "desc" for
9540 * descending or "asc" for ascending sort order of corresponding values.
9545 * @category Collection
9546 * @param {Array|Object} collection The collection to iterate over.
9547 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
9548 * The iteratees to sort by.
9549 * @param {string[]} [orders] The sort orders of `iteratees`.
9550 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
9551 * @returns {Array} Returns the new sorted array.
9555 * { 'user': 'fred', 'age': 48 },
9556 * { 'user': 'barney', 'age': 34 },
9557 * { 'user': 'fred', 'age': 40 },
9558 * { 'user': 'barney', 'age': 36 }
9561 * // Sort by `user` in ascending order and by `age` in descending order.
9562 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
9563 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9565 function orderBy(collection, iteratees, orders, guard) {
9566 if (collection == null) {
9569 if (!isArray(iteratees)) {
9570 iteratees = iteratees == null ? [] : [iteratees];
9572 orders = guard ? undefined : orders;
9573 if (!isArray(orders)) {
9574 orders = orders == null ? [] : [orders];
9576 return baseOrderBy(collection, iteratees, orders);
9580 * Creates an array of elements split into two groups, the first of which
9581 * contains elements `predicate` returns truthy for, the second of which
9582 * contains elements `predicate` returns falsey for. The predicate is
9583 * invoked with one argument: (value).
9588 * @category Collection
9589 * @param {Array|Object} collection The collection to iterate over.
9590 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9591 * @returns {Array} Returns the array of grouped elements.
9595 * { 'user': 'barney', 'age': 36, 'active': false },
9596 * { 'user': 'fred', 'age': 40, 'active': true },
9597 * { 'user': 'pebbles', 'age': 1, 'active': false }
9600 * _.partition(users, function(o) { return o.active; });
9601 * // => objects for [['fred'], ['barney', 'pebbles']]
9603 * // The `_.matches` iteratee shorthand.
9604 * _.partition(users, { 'age': 1, 'active': false });
9605 * // => objects for [['pebbles'], ['barney', 'fred']]
9607 * // The `_.matchesProperty` iteratee shorthand.
9608 * _.partition(users, ['active', false]);
9609 * // => objects for [['barney', 'pebbles'], ['fred']]
9611 * // The `_.property` iteratee shorthand.
9612 * _.partition(users, 'active');
9613 * // => objects for [['fred'], ['barney', 'pebbles']]
9615 var partition = createAggregator(function(result, value, key) {
9616 result[key ? 0 : 1].push(value);
9617 }, function() { return [[], []]; });
9620 * Reduces `collection` to a value which is the accumulated result of running
9621 * each element in `collection` thru `iteratee`, where each successive
9622 * invocation is supplied the return value of the previous. If `accumulator`
9623 * is not given, the first element of `collection` is used as the initial
9624 * value. The iteratee is invoked with four arguments:
9625 * (accumulator, value, index|key, collection).
9627 * Many lodash methods are guarded to work as iteratees for methods like
9628 * `_.reduce`, `_.reduceRight`, and `_.transform`.
9630 * The guarded methods are:
9631 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
9637 * @category Collection
9638 * @param {Array|Object} collection The collection to iterate over.
9639 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9640 * @param {*} [accumulator] The initial value.
9641 * @returns {*} Returns the accumulated value.
9642 * @see _.reduceRight
9645 * _.reduce([1, 2], function(sum, n) {
9650 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
9651 * (result[value] || (result[value] = [])).push(key);
9654 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
9656 function reduce(collection, iteratee, accumulator) {
9657 var func = isArray(collection) ? arrayReduce : baseReduce,
9658 initAccum = arguments.length < 3;
9660 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
9664 * This method is like `_.reduce` except that it iterates over elements of
9665 * `collection` from right to left.
9670 * @category Collection
9671 * @param {Array|Object} collection The collection to iterate over.
9672 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9673 * @param {*} [accumulator] The initial value.
9674 * @returns {*} Returns the accumulated value.
9678 * var array = [[0, 1], [2, 3], [4, 5]];
9680 * _.reduceRight(array, function(flattened, other) {
9681 * return flattened.concat(other);
9683 * // => [4, 5, 2, 3, 0, 1]
9685 function reduceRight(collection, iteratee, accumulator) {
9686 var func = isArray(collection) ? arrayReduceRight : baseReduce,
9687 initAccum = arguments.length < 3;
9689 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
9693 * The opposite of `_.filter`; this method returns the elements of `collection`
9694 * that `predicate` does **not** return truthy for.
9699 * @category Collection
9700 * @param {Array|Object} collection The collection to iterate over.
9701 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9702 * @returns {Array} Returns the new filtered array.
9707 * { 'user': 'barney', 'age': 36, 'active': false },
9708 * { 'user': 'fred', 'age': 40, 'active': true }
9711 * _.reject(users, function(o) { return !o.active; });
9712 * // => objects for ['fred']
9714 * // The `_.matches` iteratee shorthand.
9715 * _.reject(users, { 'age': 40, 'active': true });
9716 * // => objects for ['barney']
9718 * // The `_.matchesProperty` iteratee shorthand.
9719 * _.reject(users, ['active', false]);
9720 * // => objects for ['fred']
9722 * // The `_.property` iteratee shorthand.
9723 * _.reject(users, 'active');
9724 * // => objects for ['barney']
9726 function reject(collection, predicate) {
9727 var func = isArray(collection) ? arrayFilter : baseFilter;
9728 return func(collection, negate(getIteratee(predicate, 3)));
9732 * Gets a random element from `collection`.
9737 * @category Collection
9738 * @param {Array|Object} collection The collection to sample.
9739 * @returns {*} Returns the random element.
9742 * _.sample([1, 2, 3, 4]);
9745 function sample(collection) {
9746 var func = isArray(collection) ? arraySample : baseSample;
9747 return func(collection);
9751 * Gets `n` random elements at unique keys from `collection` up to the
9752 * size of `collection`.
9757 * @category Collection
9758 * @param {Array|Object} collection The collection to sample.
9759 * @param {number} [n=1] The number of elements to sample.
9760 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9761 * @returns {Array} Returns the random elements.
9764 * _.sampleSize([1, 2, 3], 2);
9767 * _.sampleSize([1, 2, 3], 4);
9770 function sampleSize(collection, n, guard) {
9771 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
9776 var func = isArray(collection) ? arraySampleSize : baseSampleSize;
9777 return func(collection, n);
9781 * Creates an array of shuffled values, using a version of the
9782 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
9787 * @category Collection
9788 * @param {Array|Object} collection The collection to shuffle.
9789 * @returns {Array} Returns the new shuffled array.
9792 * _.shuffle([1, 2, 3, 4]);
9793 * // => [4, 1, 3, 2]
9795 function shuffle(collection) {
9796 var func = isArray(collection) ? arrayShuffle : baseShuffle;
9797 return func(collection);
9801 * Gets the size of `collection` by returning its length for array-like
9802 * values or the number of own enumerable string keyed properties for objects.
9807 * @category Collection
9808 * @param {Array|Object|string} collection The collection to inspect.
9809 * @returns {number} Returns the collection size.
9812 * _.size([1, 2, 3]);
9815 * _.size({ 'a': 1, 'b': 2 });
9818 * _.size('pebbles');
9821 function size(collection) {
9822 if (collection == null) {
9825 if (isArrayLike(collection)) {
9826 return isString(collection) ? stringSize(collection) : collection.length;
9828 var tag = getTag(collection);
9829 if (tag == mapTag || tag == setTag) {
9830 return collection.size;
9832 return baseKeys(collection).length;
9836 * Checks if `predicate` returns truthy for **any** element of `collection`.
9837 * Iteration is stopped once `predicate` returns truthy. The predicate is
9838 * invoked with three arguments: (value, index|key, collection).
9843 * @category Collection
9844 * @param {Array|Object} collection The collection to iterate over.
9845 * @param {Function} [predicate=_.identity] The function invoked per iteration.
9846 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9847 * @returns {boolean} Returns `true` if any element passes the predicate check,
9851 * _.some([null, 0, 'yes', false], Boolean);
9855 * { 'user': 'barney', 'active': true },
9856 * { 'user': 'fred', 'active': false }
9859 * // The `_.matches` iteratee shorthand.
9860 * _.some(users, { 'user': 'barney', 'active': false });
9863 * // The `_.matchesProperty` iteratee shorthand.
9864 * _.some(users, ['active', false]);
9867 * // The `_.property` iteratee shorthand.
9868 * _.some(users, 'active');
9871 function some(collection, predicate, guard) {
9872 var func = isArray(collection) ? arraySome : baseSome;
9873 if (guard && isIterateeCall(collection, predicate, guard)) {
9874 predicate = undefined;
9876 return func(collection, getIteratee(predicate, 3));
9880 * Creates an array of elements, sorted in ascending order by the results of
9881 * running each element in a collection thru each iteratee. This method
9882 * performs a stable sort, that is, it preserves the original sort order of
9883 * equal elements. The iteratees are invoked with one argument: (value).
9888 * @category Collection
9889 * @param {Array|Object} collection The collection to iterate over.
9890 * @param {...(Function|Function[])} [iteratees=[_.identity]]
9891 * The iteratees to sort by.
9892 * @returns {Array} Returns the new sorted array.
9896 * { 'user': 'fred', 'age': 48 },
9897 * { 'user': 'barney', 'age': 36 },
9898 * { 'user': 'fred', 'age': 40 },
9899 * { 'user': 'barney', 'age': 34 }
9902 * _.sortBy(users, [function(o) { return o.user; }]);
9903 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
9905 * _.sortBy(users, ['user', 'age']);
9906 * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
9908 var sortBy = baseRest(function(collection, iteratees) {
9909 if (collection == null) {
9912 var length = iteratees.length;
9913 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
9915 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
9916 iteratees = [iteratees[0]];
9918 return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
9921 /*------------------------------------------------------------------------*/
9924 * Gets the timestamp of the number of milliseconds that have elapsed since
9925 * the Unix epoch (1 January 1970 00:00:00 UTC).
9931 * @returns {number} Returns the timestamp.
9934 * _.defer(function(stamp) {
9935 * console.log(_.now() - stamp);
9937 * // => Logs the number of milliseconds it took for the deferred invocation.
9939 var now = ctxNow || function() {
9940 return root.Date.now();
9943 /*------------------------------------------------------------------------*/
9946 * The opposite of `_.before`; this method creates a function that invokes
9947 * `func` once it's called `n` or more times.
9952 * @category Function
9953 * @param {number} n The number of calls before `func` is invoked.
9954 * @param {Function} func The function to restrict.
9955 * @returns {Function} Returns the new restricted function.
9958 * var saves = ['profile', 'settings'];
9960 * var done = _.after(saves.length, function() {
9961 * console.log('done saving!');
9964 * _.forEach(saves, function(type) {
9965 * asyncSave({ 'type': type, 'complete': done });
9967 * // => Logs 'done saving!' after the two async saves have completed.
9969 function after(n, func) {
9970 if (typeof func != 'function') {
9971 throw new TypeError(FUNC_ERROR_TEXT);
9976 return func.apply(this, arguments);
9982 * Creates a function that invokes `func`, with up to `n` arguments,
9983 * ignoring any additional arguments.
9988 * @category Function
9989 * @param {Function} func The function to cap arguments for.
9990 * @param {number} [n=func.length] The arity cap.
9991 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
9992 * @returns {Function} Returns the new capped function.
9995 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
9998 function ary(func, n, guard) {
9999 n = guard ? undefined : n;
10000 n = (func && n == null) ? func.length : n;
10001 return createWrap(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
10005 * Creates a function that invokes `func`, with the `this` binding and arguments
10006 * of the created function, while it's called less than `n` times. Subsequent
10007 * calls to the created function return the result of the last `func` invocation.
10012 * @category Function
10013 * @param {number} n The number of calls at which `func` is no longer invoked.
10014 * @param {Function} func The function to restrict.
10015 * @returns {Function} Returns the new restricted function.
10018 * jQuery(element).on('click', _.before(5, addContactToList));
10019 * // => Allows adding up to 4 contacts to the list.
10021 function before(n, func) {
10023 if (typeof func != 'function') {
10024 throw new TypeError(FUNC_ERROR_TEXT);
10027 return function() {
10029 result = func.apply(this, arguments);
10039 * Creates a function that invokes `func` with the `this` binding of `thisArg`
10040 * and `partials` prepended to the arguments it receives.
10042 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
10043 * may be used as a placeholder for partially applied arguments.
10045 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
10046 * property of bound functions.
10051 * @category Function
10052 * @param {Function} func The function to bind.
10053 * @param {*} thisArg The `this` binding of `func`.
10054 * @param {...*} [partials] The arguments to be partially applied.
10055 * @returns {Function} Returns the new bound function.
10058 * function greet(greeting, punctuation) {
10059 * return greeting + ' ' + this.user + punctuation;
10062 * var object = { 'user': 'fred' };
10064 * var bound = _.bind(greet, object, 'hi');
10068 * // Bound with placeholders.
10069 * var bound = _.bind(greet, object, _, '!');
10073 var bind = baseRest(function(func, thisArg, partials) {
10074 var bitmask = BIND_FLAG;
10075 if (partials.length) {
10076 var holders = replaceHolders(partials, getHolder(bind));
10077 bitmask |= PARTIAL_FLAG;
10079 return createWrap(func, bitmask, thisArg, partials, holders);
10083 * Creates a function that invokes the method at `object[key]` with `partials`
10084 * prepended to the arguments it receives.
10086 * This method differs from `_.bind` by allowing bound functions to reference
10087 * methods that may be redefined or don't yet exist. See
10088 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
10089 * for more details.
10091 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
10092 * builds, may be used as a placeholder for partially applied arguments.
10097 * @category Function
10098 * @param {Object} object The object to invoke the method on.
10099 * @param {string} key The key of the method.
10100 * @param {...*} [partials] The arguments to be partially applied.
10101 * @returns {Function} Returns the new bound function.
10106 * 'greet': function(greeting, punctuation) {
10107 * return greeting + ' ' + this.user + punctuation;
10111 * var bound = _.bindKey(object, 'greet', 'hi');
10115 * object.greet = function(greeting, punctuation) {
10116 * return greeting + 'ya ' + this.user + punctuation;
10120 * // => 'hiya fred!'
10122 * // Bound with placeholders.
10123 * var bound = _.bindKey(object, 'greet', _, '!');
10125 * // => 'hiya fred!'
10127 var bindKey = baseRest(function(object, key, partials) {
10128 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
10129 if (partials.length) {
10130 var holders = replaceHolders(partials, getHolder(bindKey));
10131 bitmask |= PARTIAL_FLAG;
10133 return createWrap(key, bitmask, object, partials, holders);
10137 * Creates a function that accepts arguments of `func` and either invokes
10138 * `func` returning its result, if at least `arity` number of arguments have
10139 * been provided, or returns a function that accepts the remaining `func`
10140 * arguments, and so on. The arity of `func` may be specified if `func.length`
10141 * is not sufficient.
10143 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
10144 * may be used as a placeholder for provided arguments.
10146 * **Note:** This method doesn't set the "length" property of curried functions.
10151 * @category Function
10152 * @param {Function} func The function to curry.
10153 * @param {number} [arity=func.length] The arity of `func`.
10154 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10155 * @returns {Function} Returns the new curried function.
10158 * var abc = function(a, b, c) {
10159 * return [a, b, c];
10162 * var curried = _.curry(abc);
10164 * curried(1)(2)(3);
10167 * curried(1, 2)(3);
10170 * curried(1, 2, 3);
10173 * // Curried with placeholders.
10174 * curried(1)(_, 3)(2);
10177 function curry(func, arity, guard) {
10178 arity = guard ? undefined : arity;
10179 var result = createWrap(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10180 result.placeholder = curry.placeholder;
10185 * This method is like `_.curry` except that arguments are applied to `func`
10186 * in the manner of `_.partialRight` instead of `_.partial`.
10188 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
10189 * builds, may be used as a placeholder for provided arguments.
10191 * **Note:** This method doesn't set the "length" property of curried functions.
10196 * @category Function
10197 * @param {Function} func The function to curry.
10198 * @param {number} [arity=func.length] The arity of `func`.
10199 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
10200 * @returns {Function} Returns the new curried function.
10203 * var abc = function(a, b, c) {
10204 * return [a, b, c];
10207 * var curried = _.curryRight(abc);
10209 * curried(3)(2)(1);
10212 * curried(2, 3)(1);
10215 * curried(1, 2, 3);
10218 * // Curried with placeholders.
10219 * curried(3)(1, _)(2);
10222 function curryRight(func, arity, guard) {
10223 arity = guard ? undefined : arity;
10224 var result = createWrap(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
10225 result.placeholder = curryRight.placeholder;
10230 * Creates a debounced function that delays invoking `func` until after `wait`
10231 * milliseconds have elapsed since the last time the debounced function was
10232 * invoked. The debounced function comes with a `cancel` method to cancel
10233 * delayed `func` invocations and a `flush` method to immediately invoke them.
10234 * Provide `options` to indicate whether `func` should be invoked on the
10235 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
10236 * with the last arguments provided to the debounced function. Subsequent
10237 * calls to the debounced function return the result of the last `func`
10240 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10241 * invoked on the trailing edge of the timeout only if the debounced function
10242 * is invoked more than once during the `wait` timeout.
10244 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10245 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10247 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10248 * for details over the differences between `_.debounce` and `_.throttle`.
10253 * @category Function
10254 * @param {Function} func The function to debounce.
10255 * @param {number} [wait=0] The number of milliseconds to delay.
10256 * @param {Object} [options={}] The options object.
10257 * @param {boolean} [options.leading=false]
10258 * Specify invoking on the leading edge of the timeout.
10259 * @param {number} [options.maxWait]
10260 * The maximum time `func` is allowed to be delayed before it's invoked.
10261 * @param {boolean} [options.trailing=true]
10262 * Specify invoking on the trailing edge of the timeout.
10263 * @returns {Function} Returns the new debounced function.
10266 * // Avoid costly calculations while the window size is in flux.
10267 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
10269 * // Invoke `sendMail` when clicked, debouncing subsequent calls.
10270 * jQuery(element).on('click', _.debounce(sendMail, 300, {
10272 * 'trailing': false
10275 * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
10276 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
10277 * var source = new EventSource('/stream');
10278 * jQuery(source).on('message', debounced);
10280 * // Cancel the trailing debounced invocation.
10281 * jQuery(window).on('popstate', debounced.cancel);
10283 function debounce(func, wait, options) {
10290 lastInvokeTime = 0,
10295 if (typeof func != 'function') {
10296 throw new TypeError(FUNC_ERROR_TEXT);
10298 wait = toNumber(wait) || 0;
10299 if (isObject(options)) {
10300 leading = !!options.leading;
10301 maxing = 'maxWait' in options;
10302 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
10303 trailing = 'trailing' in options ? !!options.trailing : trailing;
10306 function invokeFunc(time) {
10307 var args = lastArgs,
10308 thisArg = lastThis;
10310 lastArgs = lastThis = undefined;
10311 lastInvokeTime = time;
10312 result = func.apply(thisArg, args);
10316 function leadingEdge(time) {
10317 // Reset any `maxWait` timer.
10318 lastInvokeTime = time;
10319 // Start the timer for the trailing edge.
10320 timerId = setTimeout(timerExpired, wait);
10321 // Invoke the leading edge.
10322 return leading ? invokeFunc(time) : result;
10325 function remainingWait(time) {
10326 var timeSinceLastCall = time - lastCallTime,
10327 timeSinceLastInvoke = time - lastInvokeTime,
10328 result = wait - timeSinceLastCall;
10330 return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
10333 function shouldInvoke(time) {
10334 var timeSinceLastCall = time - lastCallTime,
10335 timeSinceLastInvoke = time - lastInvokeTime;
10337 // Either this is the first call, activity has stopped and we're at the
10338 // trailing edge, the system time has gone backwards and we're treating
10339 // it as the trailing edge, or we've hit the `maxWait` limit.
10340 return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
10341 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
10344 function timerExpired() {
10346 if (shouldInvoke(time)) {
10347 return trailingEdge(time);
10349 // Restart the timer.
10350 timerId = setTimeout(timerExpired, remainingWait(time));
10353 function trailingEdge(time) {
10354 timerId = undefined;
10356 // Only invoke if we have `lastArgs` which means `func` has been
10357 // debounced at least once.
10358 if (trailing && lastArgs) {
10359 return invokeFunc(time);
10361 lastArgs = lastThis = undefined;
10365 function cancel() {
10366 if (timerId !== undefined) {
10367 clearTimeout(timerId);
10369 lastInvokeTime = 0;
10370 lastArgs = lastCallTime = lastThis = timerId = undefined;
10374 return timerId === undefined ? result : trailingEdge(now());
10377 function debounced() {
10379 isInvoking = shouldInvoke(time);
10381 lastArgs = arguments;
10383 lastCallTime = time;
10386 if (timerId === undefined) {
10387 return leadingEdge(lastCallTime);
10390 // Handle invocations in a tight loop.
10391 timerId = setTimeout(timerExpired, wait);
10392 return invokeFunc(lastCallTime);
10395 if (timerId === undefined) {
10396 timerId = setTimeout(timerExpired, wait);
10400 debounced.cancel = cancel;
10401 debounced.flush = flush;
10406 * Defers invoking the `func` until the current call stack has cleared. Any
10407 * additional arguments are provided to `func` when it's invoked.
10412 * @category Function
10413 * @param {Function} func The function to defer.
10414 * @param {...*} [args] The arguments to invoke `func` with.
10415 * @returns {number} Returns the timer id.
10418 * _.defer(function(text) {
10419 * console.log(text);
10421 * // => Logs 'deferred' after one millisecond.
10423 var defer = baseRest(function(func, args) {
10424 return baseDelay(func, 1, args);
10428 * Invokes `func` after `wait` milliseconds. Any additional arguments are
10429 * provided to `func` when it's invoked.
10434 * @category Function
10435 * @param {Function} func The function to delay.
10436 * @param {number} wait The number of milliseconds to delay invocation.
10437 * @param {...*} [args] The arguments to invoke `func` with.
10438 * @returns {number} Returns the timer id.
10441 * _.delay(function(text) {
10442 * console.log(text);
10443 * }, 1000, 'later');
10444 * // => Logs 'later' after one second.
10446 var delay = baseRest(function(func, wait, args) {
10447 return baseDelay(func, toNumber(wait) || 0, args);
10451 * Creates a function that invokes `func` with arguments reversed.
10456 * @category Function
10457 * @param {Function} func The function to flip arguments for.
10458 * @returns {Function} Returns the new flipped function.
10461 * var flipped = _.flip(function() {
10462 * return _.toArray(arguments);
10465 * flipped('a', 'b', 'c', 'd');
10466 * // => ['d', 'c', 'b', 'a']
10468 function flip(func) {
10469 return createWrap(func, FLIP_FLAG);
10473 * Creates a function that memoizes the result of `func`. If `resolver` is
10474 * provided, it determines the cache key for storing the result based on the
10475 * arguments provided to the memoized function. By default, the first argument
10476 * provided to the memoized function is used as the map cache key. The `func`
10477 * is invoked with the `this` binding of the memoized function.
10479 * **Note:** The cache is exposed as the `cache` property on the memoized
10480 * function. Its creation may be customized by replacing the `_.memoize.Cache`
10481 * constructor with one whose instances implement the
10482 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
10483 * method interface of `clear`, `delete`, `get`, `has`, and `set`.
10488 * @category Function
10489 * @param {Function} func The function to have its output memoized.
10490 * @param {Function} [resolver] The function to resolve the cache key.
10491 * @returns {Function} Returns the new memoized function.
10494 * var object = { 'a': 1, 'b': 2 };
10495 * var other = { 'c': 3, 'd': 4 };
10497 * var values = _.memoize(_.values);
10508 * // Modify the result cache.
10509 * values.cache.set(object, ['a', 'b']);
10513 * // Replace `_.memoize.Cache`.
10514 * _.memoize.Cache = WeakMap;
10516 function memoize(func, resolver) {
10517 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
10518 throw new TypeError(FUNC_ERROR_TEXT);
10520 var memoized = function() {
10521 var args = arguments,
10522 key = resolver ? resolver.apply(this, args) : args[0],
10523 cache = memoized.cache;
10525 if (cache.has(key)) {
10526 return cache.get(key);
10528 var result = func.apply(this, args);
10529 memoized.cache = cache.set(key, result) || cache;
10532 memoized.cache = new (memoize.Cache || MapCache);
10536 // Expose `MapCache`.
10537 memoize.Cache = MapCache;
10540 * Creates a function that negates the result of the predicate `func`. The
10541 * `func` predicate is invoked with the `this` binding and arguments of the
10542 * created function.
10547 * @category Function
10548 * @param {Function} predicate The predicate to negate.
10549 * @returns {Function} Returns the new negated function.
10552 * function isEven(n) {
10553 * return n % 2 == 0;
10556 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
10559 function negate(predicate) {
10560 if (typeof predicate != 'function') {
10561 throw new TypeError(FUNC_ERROR_TEXT);
10563 return function() {
10564 var args = arguments;
10565 switch (args.length) {
10566 case 0: return !predicate.call(this);
10567 case 1: return !predicate.call(this, args[0]);
10568 case 2: return !predicate.call(this, args[0], args[1]);
10569 case 3: return !predicate.call(this, args[0], args[1], args[2]);
10571 return !predicate.apply(this, args);
10576 * Creates a function that is restricted to invoking `func` once. Repeat calls
10577 * to the function return the value of the first invocation. The `func` is
10578 * invoked with the `this` binding and arguments of the created function.
10583 * @category Function
10584 * @param {Function} func The function to restrict.
10585 * @returns {Function} Returns the new restricted function.
10588 * var initialize = _.once(createApplication);
10591 * // => `createApplication` is invoked once
10593 function once(func) {
10594 return before(2, func);
10598 * Creates a function that invokes `func` with its arguments transformed.
10603 * @category Function
10604 * @param {Function} func The function to wrap.
10605 * @param {...(Function|Function[])} [transforms=[_.identity]]
10606 * The argument transforms.
10607 * @returns {Function} Returns the new function.
10610 * function doubled(n) {
10614 * function square(n) {
10618 * var func = _.overArgs(function(x, y) {
10620 * }, [square, doubled]);
10628 var overArgs = castRest(function(func, transforms) {
10629 transforms = (transforms.length == 1 && isArray(transforms[0]))
10630 ? arrayMap(transforms[0], baseUnary(getIteratee()))
10631 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
10633 var funcsLength = transforms.length;
10634 return baseRest(function(args) {
10636 length = nativeMin(args.length, funcsLength);
10638 while (++index < length) {
10639 args[index] = transforms[index].call(this, args[index]);
10641 return apply(func, this, args);
10646 * Creates a function that invokes `func` with `partials` prepended to the
10647 * arguments it receives. This method is like `_.bind` except it does **not**
10648 * alter the `this` binding.
10650 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
10651 * builds, may be used as a placeholder for partially applied arguments.
10653 * **Note:** This method doesn't set the "length" property of partially
10654 * applied functions.
10659 * @category Function
10660 * @param {Function} func The function to partially apply arguments to.
10661 * @param {...*} [partials] The arguments to be partially applied.
10662 * @returns {Function} Returns the new partially applied function.
10665 * function greet(greeting, name) {
10666 * return greeting + ' ' + name;
10669 * var sayHelloTo = _.partial(greet, 'hello');
10670 * sayHelloTo('fred');
10671 * // => 'hello fred'
10673 * // Partially applied with placeholders.
10674 * var greetFred = _.partial(greet, _, 'fred');
10678 var partial = baseRest(function(func, partials) {
10679 var holders = replaceHolders(partials, getHolder(partial));
10680 return createWrap(func, PARTIAL_FLAG, undefined, partials, holders);
10684 * This method is like `_.partial` except that partially applied arguments
10685 * are appended to the arguments it receives.
10687 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
10688 * builds, may be used as a placeholder for partially applied arguments.
10690 * **Note:** This method doesn't set the "length" property of partially
10691 * applied functions.
10696 * @category Function
10697 * @param {Function} func The function to partially apply arguments to.
10698 * @param {...*} [partials] The arguments to be partially applied.
10699 * @returns {Function} Returns the new partially applied function.
10702 * function greet(greeting, name) {
10703 * return greeting + ' ' + name;
10706 * var greetFred = _.partialRight(greet, 'fred');
10710 * // Partially applied with placeholders.
10711 * var sayHelloTo = _.partialRight(greet, 'hello', _);
10712 * sayHelloTo('fred');
10713 * // => 'hello fred'
10715 var partialRight = baseRest(function(func, partials) {
10716 var holders = replaceHolders(partials, getHolder(partialRight));
10717 return createWrap(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
10721 * Creates a function that invokes `func` with arguments arranged according
10722 * to the specified `indexes` where the argument value at the first index is
10723 * provided as the first argument, the argument value at the second index is
10724 * provided as the second argument, and so on.
10729 * @category Function
10730 * @param {Function} func The function to rearrange arguments for.
10731 * @param {...(number|number[])} indexes The arranged argument indexes.
10732 * @returns {Function} Returns the new function.
10735 * var rearged = _.rearg(function(a, b, c) {
10736 * return [a, b, c];
10739 * rearged('b', 'c', 'a')
10740 * // => ['a', 'b', 'c']
10742 var rearg = flatRest(function(func, indexes) {
10743 return createWrap(func, REARG_FLAG, undefined, undefined, undefined, indexes);
10747 * Creates a function that invokes `func` with the `this` binding of the
10748 * created function and arguments from `start` and beyond provided as
10751 * **Note:** This method is based on the
10752 * [rest parameter](https://mdn.io/rest_parameters).
10757 * @category Function
10758 * @param {Function} func The function to apply a rest parameter to.
10759 * @param {number} [start=func.length-1] The start position of the rest parameter.
10760 * @returns {Function} Returns the new function.
10763 * var say = _.rest(function(what, names) {
10764 * return what + ' ' + _.initial(names).join(', ') +
10765 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
10768 * say('hello', 'fred', 'barney', 'pebbles');
10769 * // => 'hello fred, barney, & pebbles'
10771 function rest(func, start) {
10772 if (typeof func != 'function') {
10773 throw new TypeError(FUNC_ERROR_TEXT);
10775 start = start === undefined ? start : toInteger(start);
10776 return baseRest(func, start);
10780 * Creates a function that invokes `func` with the `this` binding of the
10781 * create function and an array of arguments much like
10782 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
10784 * **Note:** This method is based on the
10785 * [spread operator](https://mdn.io/spread_operator).
10790 * @category Function
10791 * @param {Function} func The function to spread arguments over.
10792 * @param {number} [start=0] The start position of the spread.
10793 * @returns {Function} Returns the new function.
10796 * var say = _.spread(function(who, what) {
10797 * return who + ' says ' + what;
10800 * say(['fred', 'hello']);
10801 * // => 'fred says hello'
10803 * var numbers = Promise.all([
10804 * Promise.resolve(40),
10805 * Promise.resolve(36)
10808 * numbers.then(_.spread(function(x, y) {
10811 * // => a Promise of 76
10813 function spread(func, start) {
10814 if (typeof func != 'function') {
10815 throw new TypeError(FUNC_ERROR_TEXT);
10817 start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
10818 return baseRest(function(args) {
10819 var array = args[start],
10820 otherArgs = castSlice(args, 0, start);
10823 arrayPush(otherArgs, array);
10825 return apply(func, this, otherArgs);
10830 * Creates a throttled function that only invokes `func` at most once per
10831 * every `wait` milliseconds. The throttled function comes with a `cancel`
10832 * method to cancel delayed `func` invocations and a `flush` method to
10833 * immediately invoke them. Provide `options` to indicate whether `func`
10834 * should be invoked on the leading and/or trailing edge of the `wait`
10835 * timeout. The `func` is invoked with the last arguments provided to the
10836 * throttled function. Subsequent calls to the throttled function return the
10837 * result of the last `func` invocation.
10839 * **Note:** If `leading` and `trailing` options are `true`, `func` is
10840 * invoked on the trailing edge of the timeout only if the throttled function
10841 * is invoked more than once during the `wait` timeout.
10843 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
10844 * until to the next tick, similar to `setTimeout` with a timeout of `0`.
10846 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
10847 * for details over the differences between `_.throttle` and `_.debounce`.
10852 * @category Function
10853 * @param {Function} func The function to throttle.
10854 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
10855 * @param {Object} [options={}] The options object.
10856 * @param {boolean} [options.leading=true]
10857 * Specify invoking on the leading edge of the timeout.
10858 * @param {boolean} [options.trailing=true]
10859 * Specify invoking on the trailing edge of the timeout.
10860 * @returns {Function} Returns the new throttled function.
10863 * // Avoid excessively updating the position while scrolling.
10864 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
10866 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
10867 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
10868 * jQuery(element).on('click', throttled);
10870 * // Cancel the trailing throttled invocation.
10871 * jQuery(window).on('popstate', throttled.cancel);
10873 function throttle(func, wait, options) {
10874 var leading = true,
10877 if (typeof func != 'function') {
10878 throw new TypeError(FUNC_ERROR_TEXT);
10880 if (isObject(options)) {
10881 leading = 'leading' in options ? !!options.leading : leading;
10882 trailing = 'trailing' in options ? !!options.trailing : trailing;
10884 return debounce(func, wait, {
10885 'leading': leading,
10887 'trailing': trailing
10892 * Creates a function that accepts up to one argument, ignoring any
10893 * additional arguments.
10898 * @category Function
10899 * @param {Function} func The function to cap arguments for.
10900 * @returns {Function} Returns the new capped function.
10903 * _.map(['6', '8', '10'], _.unary(parseInt));
10906 function unary(func) {
10907 return ary(func, 1);
10911 * Creates a function that provides `value` to `wrapper` as its first
10912 * argument. Any additional arguments provided to the function are appended
10913 * to those provided to the `wrapper`. The wrapper is invoked with the `this`
10914 * binding of the created function.
10919 * @category Function
10920 * @param {*} value The value to wrap.
10921 * @param {Function} [wrapper=identity] The wrapper function.
10922 * @returns {Function} Returns the new function.
10925 * var p = _.wrap(_.escape, function(func, text) {
10926 * return '<p>' + func(text) + '</p>';
10929 * p('fred, barney, & pebbles');
10930 * // => '<p>fred, barney, & pebbles</p>'
10932 function wrap(value, wrapper) {
10933 return partial(castFunction(wrapper), value);
10936 /*------------------------------------------------------------------------*/
10939 * Casts `value` as an array if it's not one.
10945 * @param {*} value The value to inspect.
10946 * @returns {Array} Returns the cast array.
10952 * _.castArray({ 'a': 1 });
10953 * // => [{ 'a': 1 }]
10955 * _.castArray('abc');
10958 * _.castArray(null);
10961 * _.castArray(undefined);
10962 * // => [undefined]
10967 * var array = [1, 2, 3];
10968 * console.log(_.castArray(array) === array);
10971 function castArray() {
10972 if (!arguments.length) {
10975 var value = arguments[0];
10976 return isArray(value) ? value : [value];
10980 * Creates a shallow clone of `value`.
10982 * **Note:** This method is loosely based on the
10983 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
10984 * and supports cloning arrays, array buffers, booleans, date objects, maps,
10985 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
10986 * arrays. The own enumerable properties of `arguments` objects are cloned
10987 * as plain objects. An empty object is returned for uncloneable values such
10988 * as error objects, functions, DOM nodes, and WeakMaps.
10994 * @param {*} value The value to clone.
10995 * @returns {*} Returns the cloned value.
10999 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11001 * var shallow = _.clone(objects);
11002 * console.log(shallow[0] === objects[0]);
11005 function clone(value) {
11006 return baseClone(value, false, true);
11010 * This method is like `_.clone` except that it accepts `customizer` which
11011 * is invoked to produce the cloned value. If `customizer` returns `undefined`,
11012 * cloning is handled by the method instead. The `customizer` is invoked with
11013 * up to four arguments; (value [, index|key, object, stack]).
11019 * @param {*} value The value to clone.
11020 * @param {Function} [customizer] The function to customize cloning.
11021 * @returns {*} Returns the cloned value.
11022 * @see _.cloneDeepWith
11025 * function customizer(value) {
11026 * if (_.isElement(value)) {
11027 * return value.cloneNode(false);
11031 * var el = _.cloneWith(document.body, customizer);
11033 * console.log(el === document.body);
11035 * console.log(el.nodeName);
11037 * console.log(el.childNodes.length);
11040 function cloneWith(value, customizer) {
11041 customizer = typeof customizer == 'function' ? customizer : undefined;
11042 return baseClone(value, false, true, customizer);
11046 * This method is like `_.clone` except that it recursively clones `value`.
11052 * @param {*} value The value to recursively clone.
11053 * @returns {*} Returns the deep cloned value.
11057 * var objects = [{ 'a': 1 }, { 'b': 2 }];
11059 * var deep = _.cloneDeep(objects);
11060 * console.log(deep[0] === objects[0]);
11063 function cloneDeep(value) {
11064 return baseClone(value, true, true);
11068 * This method is like `_.cloneWith` except that it recursively clones `value`.
11074 * @param {*} value The value to recursively clone.
11075 * @param {Function} [customizer] The function to customize cloning.
11076 * @returns {*} Returns the deep cloned value.
11080 * function customizer(value) {
11081 * if (_.isElement(value)) {
11082 * return value.cloneNode(true);
11086 * var el = _.cloneDeepWith(document.body, customizer);
11088 * console.log(el === document.body);
11090 * console.log(el.nodeName);
11092 * console.log(el.childNodes.length);
11095 function cloneDeepWith(value, customizer) {
11096 customizer = typeof customizer == 'function' ? customizer : undefined;
11097 return baseClone(value, true, true, customizer);
11101 * Checks if `object` conforms to `source` by invoking the predicate
11102 * properties of `source` with the corresponding property values of `object`.
11104 * **Note:** This method is equivalent to `_.conforms` when `source` is
11105 * partially applied.
11111 * @param {Object} object The object to inspect.
11112 * @param {Object} source The object of property predicates to conform to.
11113 * @returns {boolean} Returns `true` if `object` conforms, else `false`.
11116 * var object = { 'a': 1, 'b': 2 };
11118 * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
11121 * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
11124 function conformsTo(object, source) {
11125 return source == null || baseConformsTo(object, source, keys(source));
11130 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
11131 * comparison between two values to determine if they are equivalent.
11137 * @param {*} value The value to compare.
11138 * @param {*} other The other value to compare.
11139 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11142 * var object = { 'a': 1 };
11143 * var other = { 'a': 1 };
11145 * _.eq(object, object);
11148 * _.eq(object, other);
11154 * _.eq('a', Object('a'));
11160 function eq(value, other) {
11161 return value === other || (value !== value && other !== other);
11165 * Checks if `value` is greater than `other`.
11171 * @param {*} value The value to compare.
11172 * @param {*} other The other value to compare.
11173 * @returns {boolean} Returns `true` if `value` is greater than `other`,
11187 var gt = createRelationalOperation(baseGt);
11190 * Checks if `value` is greater than or equal to `other`.
11196 * @param {*} value The value to compare.
11197 * @param {*} other The other value to compare.
11198 * @returns {boolean} Returns `true` if `value` is greater than or equal to
11199 * `other`, else `false`.
11212 var gte = createRelationalOperation(function(value, other) {
11213 return value >= other;
11217 * Checks if `value` is likely an `arguments` object.
11223 * @param {*} value The value to check.
11224 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
11228 * _.isArguments(function() { return arguments; }());
11231 * _.isArguments([1, 2, 3]);
11234 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
11235 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
11236 !propertyIsEnumerable.call(value, 'callee');
11240 * Checks if `value` is classified as an `Array` object.
11246 * @param {*} value The value to check.
11247 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
11250 * _.isArray([1, 2, 3]);
11253 * _.isArray(document.body.children);
11256 * _.isArray('abc');
11259 * _.isArray(_.noop);
11262 var isArray = Array.isArray;
11265 * Checks if `value` is classified as an `ArrayBuffer` object.
11271 * @param {*} value The value to check.
11272 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
11275 * _.isArrayBuffer(new ArrayBuffer(2));
11278 * _.isArrayBuffer(new Array(2));
11281 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
11284 * Checks if `value` is array-like. A value is considered array-like if it's
11285 * not a function and has a `value.length` that's an integer greater than or
11286 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11292 * @param {*} value The value to check.
11293 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11296 * _.isArrayLike([1, 2, 3]);
11299 * _.isArrayLike(document.body.children);
11302 * _.isArrayLike('abc');
11305 * _.isArrayLike(_.noop);
11308 function isArrayLike(value) {
11309 return value != null && isLength(value.length) && !isFunction(value);
11313 * This method is like `_.isArrayLike` except that it also checks if `value`
11320 * @param {*} value The value to check.
11321 * @returns {boolean} Returns `true` if `value` is an array-like object,
11325 * _.isArrayLikeObject([1, 2, 3]);
11328 * _.isArrayLikeObject(document.body.children);
11331 * _.isArrayLikeObject('abc');
11334 * _.isArrayLikeObject(_.noop);
11337 function isArrayLikeObject(value) {
11338 return isObjectLike(value) && isArrayLike(value);
11342 * Checks if `value` is classified as a boolean primitive or object.
11348 * @param {*} value The value to check.
11349 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
11352 * _.isBoolean(false);
11355 * _.isBoolean(null);
11358 function isBoolean(value) {
11359 return value === true || value === false ||
11360 (isObjectLike(value) && baseGetTag(value) == boolTag);
11364 * Checks if `value` is a buffer.
11370 * @param {*} value The value to check.
11371 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
11374 * _.isBuffer(new Buffer(2));
11377 * _.isBuffer(new Uint8Array(2));
11380 var isBuffer = nativeIsBuffer || stubFalse;
11383 * Checks if `value` is classified as a `Date` object.
11389 * @param {*} value The value to check.
11390 * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
11393 * _.isDate(new Date);
11396 * _.isDate('Mon April 23 2012');
11399 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
11402 * Checks if `value` is likely a DOM element.
11408 * @param {*} value The value to check.
11409 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
11412 * _.isElement(document.body);
11415 * _.isElement('<body>');
11418 function isElement(value) {
11419 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
11423 * Checks if `value` is an empty object, collection, map, or set.
11425 * Objects are considered empty if they have no own enumerable string keyed
11428 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
11429 * jQuery-like collections are considered empty if they have a `length` of `0`.
11430 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
11436 * @param {*} value The value to check.
11437 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
11449 * _.isEmpty([1, 2, 3]);
11452 * _.isEmpty({ 'a': 1 });
11455 function isEmpty(value) {
11456 if (value == null) {
11459 if (isArrayLike(value) &&
11460 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
11461 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
11462 return !value.length;
11464 var tag = getTag(value);
11465 if (tag == mapTag || tag == setTag) {
11466 return !value.size;
11468 if (isPrototype(value)) {
11469 return !baseKeys(value).length;
11471 for (var key in value) {
11472 if (hasOwnProperty.call(value, key)) {
11480 * Performs a deep comparison between two values to determine if they are
11483 * **Note:** This method supports comparing arrays, array buffers, booleans,
11484 * date objects, error objects, maps, numbers, `Object` objects, regexes,
11485 * sets, strings, symbols, and typed arrays. `Object` objects are compared
11486 * by their own, not inherited, enumerable properties. Functions and DOM
11487 * nodes are **not** supported.
11493 * @param {*} value The value to compare.
11494 * @param {*} other The other value to compare.
11495 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11498 * var object = { 'a': 1 };
11499 * var other = { 'a': 1 };
11501 * _.isEqual(object, other);
11504 * object === other;
11507 function isEqual(value, other) {
11508 return baseIsEqual(value, other);
11512 * This method is like `_.isEqual` except that it accepts `customizer` which
11513 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11514 * are handled by the method instead. The `customizer` is invoked with up to
11515 * six arguments: (objValue, othValue [, index|key, object, other, stack]).
11521 * @param {*} value The value to compare.
11522 * @param {*} other The other value to compare.
11523 * @param {Function} [customizer] The function to customize comparisons.
11524 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
11527 * function isGreeting(value) {
11528 * return /^h(?:i|ello)$/.test(value);
11531 * function customizer(objValue, othValue) {
11532 * if (isGreeting(objValue) && isGreeting(othValue)) {
11537 * var array = ['hello', 'goodbye'];
11538 * var other = ['hi', 'goodbye'];
11540 * _.isEqualWith(array, other, customizer);
11543 function isEqualWith(value, other, customizer) {
11544 customizer = typeof customizer == 'function' ? customizer : undefined;
11545 var result = customizer ? customizer(value, other) : undefined;
11546 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
11550 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
11551 * `SyntaxError`, `TypeError`, or `URIError` object.
11557 * @param {*} value The value to check.
11558 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
11561 * _.isError(new Error);
11564 * _.isError(Error);
11567 function isError(value) {
11568 if (!isObjectLike(value)) {
11571 var tag = baseGetTag(value);
11572 return tag == errorTag || tag == domExcTag ||
11573 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
11577 * Checks if `value` is a finite primitive number.
11579 * **Note:** This method is based on
11580 * [`Number.isFinite`](https://mdn.io/Number/isFinite).
11586 * @param {*} value The value to check.
11587 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
11593 * _.isFinite(Number.MIN_VALUE);
11596 * _.isFinite(Infinity);
11602 function isFinite(value) {
11603 return typeof value == 'number' && nativeIsFinite(value);
11607 * Checks if `value` is classified as a `Function` object.
11613 * @param {*} value The value to check.
11614 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
11620 * _.isFunction(/abc/);
11623 function isFunction(value) {
11624 if (!isObject(value)) {
11627 // The use of `Object#toString` avoids issues with the `typeof` operator
11628 // in Safari 9 which returns 'object' for typed arrays and other constructors.
11629 var tag = baseGetTag(value);
11630 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
11634 * Checks if `value` is an integer.
11636 * **Note:** This method is based on
11637 * [`Number.isInteger`](https://mdn.io/Number/isInteger).
11643 * @param {*} value The value to check.
11644 * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
11650 * _.isInteger(Number.MIN_VALUE);
11653 * _.isInteger(Infinity);
11656 * _.isInteger('3');
11659 function isInteger(value) {
11660 return typeof value == 'number' && value == toInteger(value);
11664 * Checks if `value` is a valid array-like length.
11666 * **Note:** This method is loosely based on
11667 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
11673 * @param {*} value The value to check.
11674 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11680 * _.isLength(Number.MIN_VALUE);
11683 * _.isLength(Infinity);
11689 function isLength(value) {
11690 return typeof value == 'number' &&
11691 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11695 * Checks if `value` is the
11696 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
11697 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11703 * @param {*} value The value to check.
11704 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11710 * _.isObject([1, 2, 3]);
11713 * _.isObject(_.noop);
11716 * _.isObject(null);
11719 function isObject(value) {
11720 var type = typeof value;
11721 return value != null && (type == 'object' || type == 'function');
11725 * Checks if `value` is object-like. A value is object-like if it's not `null`
11726 * and has a `typeof` result of "object".
11732 * @param {*} value The value to check.
11733 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11736 * _.isObjectLike({});
11739 * _.isObjectLike([1, 2, 3]);
11742 * _.isObjectLike(_.noop);
11745 * _.isObjectLike(null);
11748 function isObjectLike(value) {
11749 return value != null && typeof value == 'object';
11753 * Checks if `value` is classified as a `Map` object.
11759 * @param {*} value The value to check.
11760 * @returns {boolean} Returns `true` if `value` is a map, else `false`.
11763 * _.isMap(new Map);
11766 * _.isMap(new WeakMap);
11769 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
11772 * Performs a partial deep comparison between `object` and `source` to
11773 * determine if `object` contains equivalent property values.
11775 * **Note:** This method is equivalent to `_.matches` when `source` is
11776 * partially applied.
11778 * Partial comparisons will match empty array and empty object `source`
11779 * values against any array or object value, respectively. See `_.isEqual`
11780 * for a list of supported value comparisons.
11786 * @param {Object} object The object to inspect.
11787 * @param {Object} source The object of property values to match.
11788 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11791 * var object = { 'a': 1, 'b': 2 };
11793 * _.isMatch(object, { 'b': 2 });
11796 * _.isMatch(object, { 'b': 1 });
11799 function isMatch(object, source) {
11800 return object === source || baseIsMatch(object, source, getMatchData(source));
11804 * This method is like `_.isMatch` except that it accepts `customizer` which
11805 * is invoked to compare values. If `customizer` returns `undefined`, comparisons
11806 * are handled by the method instead. The `customizer` is invoked with five
11807 * arguments: (objValue, srcValue, index|key, object, source).
11813 * @param {Object} object The object to inspect.
11814 * @param {Object} source The object of property values to match.
11815 * @param {Function} [customizer] The function to customize comparisons.
11816 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
11819 * function isGreeting(value) {
11820 * return /^h(?:i|ello)$/.test(value);
11823 * function customizer(objValue, srcValue) {
11824 * if (isGreeting(objValue) && isGreeting(srcValue)) {
11829 * var object = { 'greeting': 'hello' };
11830 * var source = { 'greeting': 'hi' };
11832 * _.isMatchWith(object, source, customizer);
11835 function isMatchWith(object, source, customizer) {
11836 customizer = typeof customizer == 'function' ? customizer : undefined;
11837 return baseIsMatch(object, source, getMatchData(source), customizer);
11841 * Checks if `value` is `NaN`.
11843 * **Note:** This method is based on
11844 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
11845 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
11846 * `undefined` and other non-number values.
11852 * @param {*} value The value to check.
11853 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
11859 * _.isNaN(new Number(NaN));
11862 * isNaN(undefined);
11865 * _.isNaN(undefined);
11868 function isNaN(value) {
11869 // An `NaN` primitive is the only value that is not equal to itself.
11870 // Perform the `toStringTag` check first to avoid errors with some
11871 // ActiveX objects in IE.
11872 return isNumber(value) && value != +value;
11876 * Checks if `value` is a pristine native function.
11878 * **Note:** This method can't reliably detect native functions in the presence
11879 * of the core-js package because core-js circumvents this kind of detection.
11880 * Despite multiple requests, the core-js maintainer has made it clear: any
11881 * attempt to fix the detection will be obstructed. As a result, we're left
11882 * with little choice but to throw an error. Unfortunately, this also affects
11883 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
11884 * which rely on core-js.
11890 * @param {*} value The value to check.
11891 * @returns {boolean} Returns `true` if `value` is a native function,
11895 * _.isNative(Array.prototype.push);
11901 function isNative(value) {
11902 if (isMaskable(value)) {
11903 throw new Error(CORE_ERROR_TEXT);
11905 return baseIsNative(value);
11909 * Checks if `value` is `null`.
11915 * @param {*} value The value to check.
11916 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
11922 * _.isNull(void 0);
11925 function isNull(value) {
11926 return value === null;
11930 * Checks if `value` is `null` or `undefined`.
11936 * @param {*} value The value to check.
11937 * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
11949 function isNil(value) {
11950 return value == null;
11954 * Checks if `value` is classified as a `Number` primitive or object.
11956 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
11957 * classified as numbers, use the `_.isFinite` method.
11963 * @param {*} value The value to check.
11964 * @returns {boolean} Returns `true` if `value` is a number, else `false`.
11970 * _.isNumber(Number.MIN_VALUE);
11973 * _.isNumber(Infinity);
11979 function isNumber(value) {
11980 return typeof value == 'number' ||
11981 (isObjectLike(value) && baseGetTag(value) == numberTag);
11985 * Checks if `value` is a plain object, that is, an object created by the
11986 * `Object` constructor or one with a `[[Prototype]]` of `null`.
11992 * @param {*} value The value to check.
11993 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12000 * _.isPlainObject(new Foo);
12003 * _.isPlainObject([1, 2, 3]);
12006 * _.isPlainObject({ 'x': 0, 'y': 0 });
12009 * _.isPlainObject(Object.create(null));
12012 function isPlainObject(value) {
12013 if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
12016 var proto = getPrototype(value);
12017 if (proto === null) {
12020 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
12021 return typeof Ctor == 'function' && Ctor instanceof Ctor &&
12022 funcToString.call(Ctor) == objectCtorString;
12026 * Checks if `value` is classified as a `RegExp` object.
12032 * @param {*} value The value to check.
12033 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
12036 * _.isRegExp(/abc/);
12039 * _.isRegExp('/abc/');
12042 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
12045 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
12046 * double precision number which isn't the result of a rounded unsafe integer.
12048 * **Note:** This method is based on
12049 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
12055 * @param {*} value The value to check.
12056 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
12059 * _.isSafeInteger(3);
12062 * _.isSafeInteger(Number.MIN_VALUE);
12065 * _.isSafeInteger(Infinity);
12068 * _.isSafeInteger('3');
12071 function isSafeInteger(value) {
12072 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
12076 * Checks if `value` is classified as a `Set` object.
12082 * @param {*} value The value to check.
12083 * @returns {boolean} Returns `true` if `value` is a set, else `false`.
12086 * _.isSet(new Set);
12089 * _.isSet(new WeakSet);
12092 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
12095 * Checks if `value` is classified as a `String` primitive or object.
12101 * @param {*} value The value to check.
12102 * @returns {boolean} Returns `true` if `value` is a string, else `false`.
12105 * _.isString('abc');
12111 function isString(value) {
12112 return typeof value == 'string' ||
12113 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
12117 * Checks if `value` is classified as a `Symbol` primitive or object.
12123 * @param {*} value The value to check.
12124 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
12127 * _.isSymbol(Symbol.iterator);
12130 * _.isSymbol('abc');
12133 function isSymbol(value) {
12134 return typeof value == 'symbol' ||
12135 (isObjectLike(value) && baseGetTag(value) == symbolTag);
12139 * Checks if `value` is classified as a typed array.
12145 * @param {*} value The value to check.
12146 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
12149 * _.isTypedArray(new Uint8Array);
12152 * _.isTypedArray([]);
12155 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
12158 * Checks if `value` is `undefined`.
12164 * @param {*} value The value to check.
12165 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
12168 * _.isUndefined(void 0);
12171 * _.isUndefined(null);
12174 function isUndefined(value) {
12175 return value === undefined;
12179 * Checks if `value` is classified as a `WeakMap` object.
12185 * @param {*} value The value to check.
12186 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
12189 * _.isWeakMap(new WeakMap);
12192 * _.isWeakMap(new Map);
12195 function isWeakMap(value) {
12196 return isObjectLike(value) && getTag(value) == weakMapTag;
12200 * Checks if `value` is classified as a `WeakSet` object.
12206 * @param {*} value The value to check.
12207 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
12210 * _.isWeakSet(new WeakSet);
12213 * _.isWeakSet(new Set);
12216 function isWeakSet(value) {
12217 return isObjectLike(value) && baseGetTag(value) == weakSetTag;
12221 * Checks if `value` is less than `other`.
12227 * @param {*} value The value to compare.
12228 * @param {*} other The other value to compare.
12229 * @returns {boolean} Returns `true` if `value` is less than `other`,
12243 var lt = createRelationalOperation(baseLt);
12246 * Checks if `value` is less than or equal to `other`.
12252 * @param {*} value The value to compare.
12253 * @param {*} other The other value to compare.
12254 * @returns {boolean} Returns `true` if `value` is less than or equal to
12255 * `other`, else `false`.
12268 var lte = createRelationalOperation(function(value, other) {
12269 return value <= other;
12273 * Converts `value` to an array.
12279 * @param {*} value The value to convert.
12280 * @returns {Array} Returns the converted array.
12283 * _.toArray({ 'a': 1, 'b': 2 });
12286 * _.toArray('abc');
12287 * // => ['a', 'b', 'c']
12295 function toArray(value) {
12299 if (isArrayLike(value)) {
12300 return isString(value) ? stringToArray(value) : copyArray(value);
12302 if (symIterator && value[symIterator]) {
12303 return iteratorToArray(value[symIterator]());
12305 var tag = getTag(value),
12306 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
12308 return func(value);
12312 * Converts `value` to a finite number.
12318 * @param {*} value The value to convert.
12319 * @returns {number} Returns the converted number.
12325 * _.toFinite(Number.MIN_VALUE);
12328 * _.toFinite(Infinity);
12329 * // => 1.7976931348623157e+308
12331 * _.toFinite('3.2');
12334 function toFinite(value) {
12336 return value === 0 ? value : 0;
12338 value = toNumber(value);
12339 if (value === INFINITY || value === -INFINITY) {
12340 var sign = (value < 0 ? -1 : 1);
12341 return sign * MAX_INTEGER;
12343 return value === value ? value : 0;
12347 * Converts `value` to an integer.
12349 * **Note:** This method is loosely based on
12350 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
12356 * @param {*} value The value to convert.
12357 * @returns {number} Returns the converted integer.
12360 * _.toInteger(3.2);
12363 * _.toInteger(Number.MIN_VALUE);
12366 * _.toInteger(Infinity);
12367 * // => 1.7976931348623157e+308
12369 * _.toInteger('3.2');
12372 function toInteger(value) {
12373 var result = toFinite(value),
12374 remainder = result % 1;
12376 return result === result ? (remainder ? result - remainder : result) : 0;
12380 * Converts `value` to an integer suitable for use as the length of an
12381 * array-like object.
12383 * **Note:** This method is based on
12384 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
12390 * @param {*} value The value to convert.
12391 * @returns {number} Returns the converted integer.
12397 * _.toLength(Number.MIN_VALUE);
12400 * _.toLength(Infinity);
12403 * _.toLength('3.2');
12406 function toLength(value) {
12407 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
12411 * Converts `value` to a number.
12417 * @param {*} value The value to process.
12418 * @returns {number} Returns the number.
12424 * _.toNumber(Number.MIN_VALUE);
12427 * _.toNumber(Infinity);
12430 * _.toNumber('3.2');
12433 function toNumber(value) {
12434 if (typeof value == 'number') {
12437 if (isSymbol(value)) {
12440 if (isObject(value)) {
12441 var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
12442 value = isObject(other) ? (other + '') : other;
12444 if (typeof value != 'string') {
12445 return value === 0 ? value : +value;
12447 value = value.replace(reTrim, '');
12448 var isBinary = reIsBinary.test(value);
12449 return (isBinary || reIsOctal.test(value))
12450 ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
12451 : (reIsBadHex.test(value) ? NAN : +value);
12455 * Converts `value` to a plain object flattening inherited enumerable string
12456 * keyed properties of `value` to own properties of the plain object.
12462 * @param {*} value The value to convert.
12463 * @returns {Object} Returns the converted plain object.
12470 * Foo.prototype.c = 3;
12472 * _.assign({ 'a': 1 }, new Foo);
12473 * // => { 'a': 1, 'b': 2 }
12475 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12476 * // => { 'a': 1, 'b': 2, 'c': 3 }
12478 function toPlainObject(value) {
12479 return copyObject(value, keysIn(value));
12483 * Converts `value` to a safe integer. A safe integer can be compared and
12484 * represented correctly.
12490 * @param {*} value The value to convert.
12491 * @returns {number} Returns the converted integer.
12494 * _.toSafeInteger(3.2);
12497 * _.toSafeInteger(Number.MIN_VALUE);
12500 * _.toSafeInteger(Infinity);
12501 * // => 9007199254740991
12503 * _.toSafeInteger('3.2');
12506 function toSafeInteger(value) {
12507 return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
12511 * Converts `value` to a string. An empty string is returned for `null`
12512 * and `undefined` values. The sign of `-0` is preserved.
12518 * @param {*} value The value to convert.
12519 * @returns {string} Returns the converted string.
12522 * _.toString(null);
12528 * _.toString([1, 2, 3]);
12531 function toString(value) {
12532 return value == null ? '' : baseToString(value);
12535 /*------------------------------------------------------------------------*/
12538 * Assigns own enumerable string keyed properties of source objects to the
12539 * destination object. Source objects are applied from left to right.
12540 * Subsequent sources overwrite property assignments of previous sources.
12542 * **Note:** This method mutates `object` and is loosely based on
12543 * [`Object.assign`](https://mdn.io/Object/assign).
12549 * @param {Object} object The destination object.
12550 * @param {...Object} [sources] The source objects.
12551 * @returns {Object} Returns `object`.
12563 * Foo.prototype.b = 2;
12564 * Bar.prototype.d = 4;
12566 * _.assign({ 'a': 0 }, new Foo, new Bar);
12567 * // => { 'a': 1, 'c': 3 }
12569 var assign = createAssigner(function(object, source) {
12570 if (isPrototype(source) || isArrayLike(source)) {
12571 copyObject(source, keys(source), object);
12574 for (var key in source) {
12575 if (hasOwnProperty.call(source, key)) {
12576 assignValue(object, key, source[key]);
12582 * This method is like `_.assign` except that it iterates over own and
12583 * inherited source properties.
12585 * **Note:** This method mutates `object`.
12592 * @param {Object} object The destination object.
12593 * @param {...Object} [sources] The source objects.
12594 * @returns {Object} Returns `object`.
12606 * Foo.prototype.b = 2;
12607 * Bar.prototype.d = 4;
12609 * _.assignIn({ 'a': 0 }, new Foo, new Bar);
12610 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
12612 var assignIn = createAssigner(function(object, source) {
12613 copyObject(source, keysIn(source), object);
12617 * This method is like `_.assignIn` except that it accepts `customizer`
12618 * which is invoked to produce the assigned values. If `customizer` returns
12619 * `undefined`, assignment is handled by the method instead. The `customizer`
12620 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12622 * **Note:** This method mutates `object`.
12627 * @alias extendWith
12629 * @param {Object} object The destination object.
12630 * @param {...Object} sources The source objects.
12631 * @param {Function} [customizer] The function to customize assigned values.
12632 * @returns {Object} Returns `object`.
12633 * @see _.assignWith
12636 * function customizer(objValue, srcValue) {
12637 * return _.isUndefined(objValue) ? srcValue : objValue;
12640 * var defaults = _.partialRight(_.assignInWith, customizer);
12642 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12643 * // => { 'a': 1, 'b': 2 }
12645 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
12646 copyObject(source, keysIn(source), object, customizer);
12650 * This method is like `_.assign` except that it accepts `customizer`
12651 * which is invoked to produce the assigned values. If `customizer` returns
12652 * `undefined`, assignment is handled by the method instead. The `customizer`
12653 * is invoked with five arguments: (objValue, srcValue, key, object, source).
12655 * **Note:** This method mutates `object`.
12661 * @param {Object} object The destination object.
12662 * @param {...Object} sources The source objects.
12663 * @param {Function} [customizer] The function to customize assigned values.
12664 * @returns {Object} Returns `object`.
12665 * @see _.assignInWith
12668 * function customizer(objValue, srcValue) {
12669 * return _.isUndefined(objValue) ? srcValue : objValue;
12672 * var defaults = _.partialRight(_.assignWith, customizer);
12674 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12675 * // => { 'a': 1, 'b': 2 }
12677 var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
12678 copyObject(source, keys(source), object, customizer);
12682 * Creates an array of values corresponding to `paths` of `object`.
12688 * @param {Object} object The object to iterate over.
12689 * @param {...(string|string[])} [paths] The property paths of elements to pick.
12690 * @returns {Array} Returns the picked values.
12693 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
12695 * _.at(object, ['a[0].b.c', 'a[1]']);
12698 var at = flatRest(baseAt);
12701 * Creates an object that inherits from the `prototype` object. If a
12702 * `properties` object is given, its own enumerable string keyed properties
12703 * are assigned to the created object.
12709 * @param {Object} prototype The object to inherit from.
12710 * @param {Object} [properties] The properties to assign to the object.
12711 * @returns {Object} Returns the new object.
12714 * function Shape() {
12719 * function Circle() {
12720 * Shape.call(this);
12723 * Circle.prototype = _.create(Shape.prototype, {
12724 * 'constructor': Circle
12727 * var circle = new Circle;
12728 * circle instanceof Circle;
12731 * circle instanceof Shape;
12734 function create(prototype, properties) {
12735 var result = baseCreate(prototype);
12736 return properties == null ? result : baseAssign(result, properties);
12740 * Assigns own and inherited enumerable string keyed properties of source
12741 * objects to the destination object for all destination properties that
12742 * resolve to `undefined`. Source objects are applied from left to right.
12743 * Once a property is set, additional values of the same property are ignored.
12745 * **Note:** This method mutates `object`.
12751 * @param {Object} object The destination object.
12752 * @param {...Object} [sources] The source objects.
12753 * @returns {Object} Returns `object`.
12754 * @see _.defaultsDeep
12757 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
12758 * // => { 'a': 1, 'b': 2 }
12760 var defaults = baseRest(function(args) {
12761 args.push(undefined, assignInDefaults);
12762 return apply(assignInWith, undefined, args);
12766 * This method is like `_.defaults` except that it recursively assigns
12767 * default properties.
12769 * **Note:** This method mutates `object`.
12775 * @param {Object} object The destination object.
12776 * @param {...Object} [sources] The source objects.
12777 * @returns {Object} Returns `object`.
12781 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
12782 * // => { 'a': { 'b': 2, 'c': 3 } }
12784 var defaultsDeep = baseRest(function(args) {
12785 args.push(undefined, mergeDefaults);
12786 return apply(mergeWith, undefined, args);
12790 * This method is like `_.find` except that it returns the key of the first
12791 * element `predicate` returns truthy for instead of the element itself.
12797 * @param {Object} object The object to inspect.
12798 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12799 * @returns {string|undefined} Returns the key of the matched element,
12800 * else `undefined`.
12804 * 'barney': { 'age': 36, 'active': true },
12805 * 'fred': { 'age': 40, 'active': false },
12806 * 'pebbles': { 'age': 1, 'active': true }
12809 * _.findKey(users, function(o) { return o.age < 40; });
12810 * // => 'barney' (iteration order is not guaranteed)
12812 * // The `_.matches` iteratee shorthand.
12813 * _.findKey(users, { 'age': 1, 'active': true });
12816 * // The `_.matchesProperty` iteratee shorthand.
12817 * _.findKey(users, ['active', false]);
12820 * // The `_.property` iteratee shorthand.
12821 * _.findKey(users, 'active');
12824 function findKey(object, predicate) {
12825 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
12829 * This method is like `_.findKey` except that it iterates over elements of
12830 * a collection in the opposite order.
12836 * @param {Object} object The object to inspect.
12837 * @param {Function} [predicate=_.identity] The function invoked per iteration.
12838 * @returns {string|undefined} Returns the key of the matched element,
12839 * else `undefined`.
12843 * 'barney': { 'age': 36, 'active': true },
12844 * 'fred': { 'age': 40, 'active': false },
12845 * 'pebbles': { 'age': 1, 'active': true }
12848 * _.findLastKey(users, function(o) { return o.age < 40; });
12849 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
12851 * // The `_.matches` iteratee shorthand.
12852 * _.findLastKey(users, { 'age': 36, 'active': true });
12855 * // The `_.matchesProperty` iteratee shorthand.
12856 * _.findLastKey(users, ['active', false]);
12859 * // The `_.property` iteratee shorthand.
12860 * _.findLastKey(users, 'active');
12863 function findLastKey(object, predicate) {
12864 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
12868 * Iterates over own and inherited enumerable string keyed properties of an
12869 * object and invokes `iteratee` for each property. The iteratee is invoked
12870 * with three arguments: (value, key, object). Iteratee functions may exit
12871 * iteration early by explicitly returning `false`.
12877 * @param {Object} object The object to iterate over.
12878 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12879 * @returns {Object} Returns `object`.
12880 * @see _.forInRight
12888 * Foo.prototype.c = 3;
12890 * _.forIn(new Foo, function(value, key) {
12891 * console.log(key);
12893 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
12895 function forIn(object, iteratee) {
12896 return object == null
12898 : baseFor(object, getIteratee(iteratee, 3), keysIn);
12902 * This method is like `_.forIn` except that it iterates over properties of
12903 * `object` in the opposite order.
12909 * @param {Object} object The object to iterate over.
12910 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12911 * @returns {Object} Returns `object`.
12920 * Foo.prototype.c = 3;
12922 * _.forInRight(new Foo, function(value, key) {
12923 * console.log(key);
12925 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
12927 function forInRight(object, iteratee) {
12928 return object == null
12930 : baseForRight(object, getIteratee(iteratee, 3), keysIn);
12934 * Iterates over own enumerable string keyed properties of an object and
12935 * invokes `iteratee` for each property. The iteratee is invoked with three
12936 * arguments: (value, key, object). Iteratee functions may exit iteration
12937 * early by explicitly returning `false`.
12943 * @param {Object} object The object to iterate over.
12944 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12945 * @returns {Object} Returns `object`.
12946 * @see _.forOwnRight
12954 * Foo.prototype.c = 3;
12956 * _.forOwn(new Foo, function(value, key) {
12957 * console.log(key);
12959 * // => Logs 'a' then 'b' (iteration order is not guaranteed).
12961 function forOwn(object, iteratee) {
12962 return object && baseForOwn(object, getIteratee(iteratee, 3));
12966 * This method is like `_.forOwn` except that it iterates over properties of
12967 * `object` in the opposite order.
12973 * @param {Object} object The object to iterate over.
12974 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
12975 * @returns {Object} Returns `object`.
12984 * Foo.prototype.c = 3;
12986 * _.forOwnRight(new Foo, function(value, key) {
12987 * console.log(key);
12989 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
12991 function forOwnRight(object, iteratee) {
12992 return object && baseForOwnRight(object, getIteratee(iteratee, 3));
12996 * Creates an array of function property names from own enumerable properties
13003 * @param {Object} object The object to inspect.
13004 * @returns {Array} Returns the function names.
13005 * @see _.functionsIn
13009 * this.a = _.constant('a');
13010 * this.b = _.constant('b');
13013 * Foo.prototype.c = _.constant('c');
13015 * _.functions(new Foo);
13018 function functions(object) {
13019 return object == null ? [] : baseFunctions(object, keys(object));
13023 * Creates an array of function property names from own and inherited
13024 * enumerable properties of `object`.
13030 * @param {Object} object The object to inspect.
13031 * @returns {Array} Returns the function names.
13036 * this.a = _.constant('a');
13037 * this.b = _.constant('b');
13040 * Foo.prototype.c = _.constant('c');
13042 * _.functionsIn(new Foo);
13043 * // => ['a', 'b', 'c']
13045 function functionsIn(object) {
13046 return object == null ? [] : baseFunctions(object, keysIn(object));
13050 * Gets the value at `path` of `object`. If the resolved value is
13051 * `undefined`, the `defaultValue` is returned in its place.
13057 * @param {Object} object The object to query.
13058 * @param {Array|string} path The path of the property to get.
13059 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13060 * @returns {*} Returns the resolved value.
13063 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13065 * _.get(object, 'a[0].b.c');
13068 * _.get(object, ['a', '0', 'b', 'c']);
13071 * _.get(object, 'a.b.c', 'default');
13074 function get(object, path, defaultValue) {
13075 var result = object == null ? undefined : baseGet(object, path);
13076 return result === undefined ? defaultValue : result;
13080 * Checks if `path` is a direct property of `object`.
13086 * @param {Object} object The object to query.
13087 * @param {Array|string} path The path to check.
13088 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13091 * var object = { 'a': { 'b': 2 } };
13092 * var other = _.create({ 'a': _.create({ 'b': 2 }) });
13094 * _.has(object, 'a');
13097 * _.has(object, 'a.b');
13100 * _.has(object, ['a', 'b']);
13103 * _.has(other, 'a');
13106 function has(object, path) {
13107 return object != null && hasPath(object, path, baseHas);
13111 * Checks if `path` is a direct or inherited property of `object`.
13117 * @param {Object} object The object to query.
13118 * @param {Array|string} path The path to check.
13119 * @returns {boolean} Returns `true` if `path` exists, else `false`.
13122 * var object = _.create({ 'a': _.create({ 'b': 2 }) });
13124 * _.hasIn(object, 'a');
13127 * _.hasIn(object, 'a.b');
13130 * _.hasIn(object, ['a', 'b']);
13133 * _.hasIn(object, 'b');
13136 function hasIn(object, path) {
13137 return object != null && hasPath(object, path, baseHasIn);
13141 * Creates an object composed of the inverted keys and values of `object`.
13142 * If `object` contains duplicate values, subsequent values overwrite
13143 * property assignments of previous values.
13149 * @param {Object} object The object to invert.
13150 * @returns {Object} Returns the new inverted object.
13153 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13155 * _.invert(object);
13156 * // => { '1': 'c', '2': 'b' }
13158 var invert = createInverter(function(result, value, key) {
13159 result[value] = key;
13160 }, constant(identity));
13163 * This method is like `_.invert` except that the inverted object is generated
13164 * from the results of running each element of `object` thru `iteratee`. The
13165 * corresponding inverted value of each inverted key is an array of keys
13166 * responsible for generating the inverted value. The iteratee is invoked
13167 * with one argument: (value).
13173 * @param {Object} object The object to invert.
13174 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
13175 * @returns {Object} Returns the new inverted object.
13178 * var object = { 'a': 1, 'b': 2, 'c': 1 };
13180 * _.invertBy(object);
13181 * // => { '1': ['a', 'c'], '2': ['b'] }
13183 * _.invertBy(object, function(value) {
13184 * return 'group' + value;
13186 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
13188 var invertBy = createInverter(function(result, value, key) {
13189 if (hasOwnProperty.call(result, value)) {
13190 result[value].push(key);
13192 result[value] = [key];
13197 * Invokes the method at `path` of `object`.
13203 * @param {Object} object The object to query.
13204 * @param {Array|string} path The path of the method to invoke.
13205 * @param {...*} [args] The arguments to invoke the method with.
13206 * @returns {*} Returns the result of the invoked method.
13209 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
13211 * _.invoke(object, 'a[0].b.c.slice', 1, 3);
13214 var invoke = baseRest(baseInvoke);
13217 * Creates an array of the own enumerable property names of `object`.
13219 * **Note:** Non-object values are coerced to objects. See the
13220 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
13221 * for more details.
13227 * @param {Object} object The object to query.
13228 * @returns {Array} Returns the array of property names.
13236 * Foo.prototype.c = 3;
13239 * // => ['a', 'b'] (iteration order is not guaranteed)
13244 function keys(object) {
13245 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
13249 * Creates an array of the own and inherited enumerable property names of `object`.
13251 * **Note:** Non-object values are coerced to objects.
13257 * @param {Object} object The object to query.
13258 * @returns {Array} Returns the array of property names.
13266 * Foo.prototype.c = 3;
13268 * _.keysIn(new Foo);
13269 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
13271 function keysIn(object) {
13272 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
13276 * The opposite of `_.mapValues`; this method creates an object with the
13277 * same values as `object` and keys generated by running each own enumerable
13278 * string keyed property of `object` thru `iteratee`. The iteratee is invoked
13279 * with three arguments: (value, key, object).
13285 * @param {Object} object The object to iterate over.
13286 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13287 * @returns {Object} Returns the new mapped object.
13291 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
13292 * return key + value;
13294 * // => { 'a1': 1, 'b2': 2 }
13296 function mapKeys(object, iteratee) {
13298 iteratee = getIteratee(iteratee, 3);
13300 baseForOwn(object, function(value, key, object) {
13301 baseAssignValue(result, iteratee(value, key, object), value);
13307 * Creates an object with the same keys as `object` and values generated
13308 * by running each own enumerable string keyed property of `object` thru
13309 * `iteratee`. The iteratee is invoked with three arguments:
13310 * (value, key, object).
13316 * @param {Object} object The object to iterate over.
13317 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13318 * @returns {Object} Returns the new mapped object.
13323 * 'fred': { 'user': 'fred', 'age': 40 },
13324 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
13327 * _.mapValues(users, function(o) { return o.age; });
13328 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13330 * // The `_.property` iteratee shorthand.
13331 * _.mapValues(users, 'age');
13332 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
13334 function mapValues(object, iteratee) {
13336 iteratee = getIteratee(iteratee, 3);
13338 baseForOwn(object, function(value, key, object) {
13339 baseAssignValue(result, key, iteratee(value, key, object));
13345 * This method is like `_.assign` except that it recursively merges own and
13346 * inherited enumerable string keyed properties of source objects into the
13347 * destination object. Source properties that resolve to `undefined` are
13348 * skipped if a destination value exists. Array and plain object properties
13349 * are merged recursively. Other objects and value types are overridden by
13350 * assignment. Source objects are applied from left to right. Subsequent
13351 * sources overwrite property assignments of previous sources.
13353 * **Note:** This method mutates `object`.
13359 * @param {Object} object The destination object.
13360 * @param {...Object} [sources] The source objects.
13361 * @returns {Object} Returns `object`.
13365 * 'a': [{ 'b': 2 }, { 'd': 4 }]
13369 * 'a': [{ 'c': 3 }, { 'e': 5 }]
13372 * _.merge(object, other);
13373 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
13375 var merge = createAssigner(function(object, source, srcIndex) {
13376 baseMerge(object, source, srcIndex);
13380 * This method is like `_.merge` except that it accepts `customizer` which
13381 * is invoked to produce the merged values of the destination and source
13382 * properties. If `customizer` returns `undefined`, merging is handled by the
13383 * method instead. The `customizer` is invoked with six arguments:
13384 * (objValue, srcValue, key, object, source, stack).
13386 * **Note:** This method mutates `object`.
13392 * @param {Object} object The destination object.
13393 * @param {...Object} sources The source objects.
13394 * @param {Function} customizer The function to customize assigned values.
13395 * @returns {Object} Returns `object`.
13398 * function customizer(objValue, srcValue) {
13399 * if (_.isArray(objValue)) {
13400 * return objValue.concat(srcValue);
13404 * var object = { 'a': [1], 'b': [2] };
13405 * var other = { 'a': [3], 'b': [4] };
13407 * _.mergeWith(object, other, customizer);
13408 * // => { 'a': [1, 3], 'b': [2, 4] }
13410 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
13411 baseMerge(object, source, srcIndex, customizer);
13415 * The opposite of `_.pick`; this method creates an object composed of the
13416 * own and inherited enumerable string keyed properties of `object` that are
13423 * @param {Object} object The source object.
13424 * @param {...(string|string[])} [props] The property identifiers to omit.
13425 * @returns {Object} Returns the new object.
13428 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13430 * _.omit(object, ['a', 'c']);
13431 * // => { 'b': '2' }
13433 var omit = flatRest(function(object, props) {
13434 if (object == null) {
13437 props = arrayMap(props, toKey);
13438 return basePick(object, baseDifference(getAllKeysIn(object), props));
13442 * The opposite of `_.pickBy`; this method creates an object composed of
13443 * the own and inherited enumerable string keyed properties of `object` that
13444 * `predicate` doesn't return truthy for. The predicate is invoked with two
13445 * arguments: (value, key).
13451 * @param {Object} object The source object.
13452 * @param {Function} [predicate=_.identity] The function invoked per property.
13453 * @returns {Object} Returns the new object.
13456 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13458 * _.omitBy(object, _.isNumber);
13459 * // => { 'b': '2' }
13461 function omitBy(object, predicate) {
13462 return pickBy(object, negate(getIteratee(predicate)));
13466 * Creates an object composed of the picked `object` properties.
13472 * @param {Object} object The source object.
13473 * @param {...(string|string[])} [props] The property identifiers to pick.
13474 * @returns {Object} Returns the new object.
13477 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13479 * _.pick(object, ['a', 'c']);
13480 * // => { 'a': 1, 'c': 3 }
13482 var pick = flatRest(function(object, props) {
13483 return object == null ? {} : basePick(object, arrayMap(props, toKey));
13487 * Creates an object composed of the `object` properties `predicate` returns
13488 * truthy for. The predicate is invoked with two arguments: (value, key).
13494 * @param {Object} object The source object.
13495 * @param {Function} [predicate=_.identity] The function invoked per property.
13496 * @returns {Object} Returns the new object.
13499 * var object = { 'a': 1, 'b': '2', 'c': 3 };
13501 * _.pickBy(object, _.isNumber);
13502 * // => { 'a': 1, 'c': 3 }
13504 function pickBy(object, predicate) {
13505 return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate));
13509 * This method is like `_.get` except that if the resolved value is a
13510 * function it's invoked with the `this` binding of its parent object and
13511 * its result is returned.
13517 * @param {Object} object The object to query.
13518 * @param {Array|string} path The path of the property to resolve.
13519 * @param {*} [defaultValue] The value returned for `undefined` resolved values.
13520 * @returns {*} Returns the resolved value.
13523 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
13525 * _.result(object, 'a[0].b.c1');
13528 * _.result(object, 'a[0].b.c2');
13531 * _.result(object, 'a[0].b.c3', 'default');
13534 * _.result(object, 'a[0].b.c3', _.constant('default'));
13537 function result(object, path, defaultValue) {
13538 path = isKey(path, object) ? [path] : castPath(path);
13541 length = path.length;
13543 // Ensure the loop is entered when path is empty.
13545 object = undefined;
13548 while (++index < length) {
13549 var value = object == null ? undefined : object[toKey(path[index])];
13550 if (value === undefined) {
13552 value = defaultValue;
13554 object = isFunction(value) ? value.call(object) : value;
13560 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
13561 * it's created. Arrays are created for missing index properties while objects
13562 * are created for all other missing properties. Use `_.setWith` to customize
13565 * **Note:** This method mutates `object`.
13571 * @param {Object} object The object to modify.
13572 * @param {Array|string} path The path of the property to set.
13573 * @param {*} value The value to set.
13574 * @returns {Object} Returns `object`.
13577 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13579 * _.set(object, 'a[0].b.c', 4);
13580 * console.log(object.a[0].b.c);
13583 * _.set(object, ['x', '0', 'y', 'z'], 5);
13584 * console.log(object.x[0].y.z);
13587 function set(object, path, value) {
13588 return object == null ? object : baseSet(object, path, value);
13592 * This method is like `_.set` except that it accepts `customizer` which is
13593 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13594 * path creation is handled by the method instead. The `customizer` is invoked
13595 * with three arguments: (nsValue, key, nsObject).
13597 * **Note:** This method mutates `object`.
13603 * @param {Object} object The object to modify.
13604 * @param {Array|string} path The path of the property to set.
13605 * @param {*} value The value to set.
13606 * @param {Function} [customizer] The function to customize assigned values.
13607 * @returns {Object} Returns `object`.
13612 * _.setWith(object, '[0][1]', 'a', Object);
13613 * // => { '0': { '1': 'a' } }
13615 function setWith(object, path, value, customizer) {
13616 customizer = typeof customizer == 'function' ? customizer : undefined;
13617 return object == null ? object : baseSet(object, path, value, customizer);
13621 * Creates an array of own enumerable string keyed-value pairs for `object`
13622 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
13623 * entries are returned.
13630 * @param {Object} object The object to query.
13631 * @returns {Array} Returns the key-value pairs.
13639 * Foo.prototype.c = 3;
13641 * _.toPairs(new Foo);
13642 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
13644 var toPairs = createToPairs(keys);
13647 * Creates an array of own and inherited enumerable string keyed-value pairs
13648 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
13649 * or set, its entries are returned.
13656 * @param {Object} object The object to query.
13657 * @returns {Array} Returns the key-value pairs.
13665 * Foo.prototype.c = 3;
13667 * _.toPairsIn(new Foo);
13668 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
13670 var toPairsIn = createToPairs(keysIn);
13673 * An alternative to `_.reduce`; this method transforms `object` to a new
13674 * `accumulator` object which is the result of running each of its own
13675 * enumerable string keyed properties thru `iteratee`, with each invocation
13676 * potentially mutating the `accumulator` object. If `accumulator` is not
13677 * provided, a new object with the same `[[Prototype]]` will be used. The
13678 * iteratee is invoked with four arguments: (accumulator, value, key, object).
13679 * Iteratee functions may exit iteration early by explicitly returning `false`.
13685 * @param {Object} object The object to iterate over.
13686 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
13687 * @param {*} [accumulator] The custom accumulator value.
13688 * @returns {*} Returns the accumulated value.
13691 * _.transform([2, 3, 4], function(result, n) {
13692 * result.push(n *= n);
13693 * return n % 2 == 0;
13697 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
13698 * (result[value] || (result[value] = [])).push(key);
13700 * // => { '1': ['a', 'c'], '2': ['b'] }
13702 function transform(object, iteratee, accumulator) {
13703 var isArr = isArray(object),
13704 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13706 iteratee = getIteratee(iteratee, 4);
13707 if (accumulator == null) {
13708 var Ctor = object && object.constructor;
13710 accumulator = isArr ? new Ctor : [];
13712 else if (isObject(object)) {
13713 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13719 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13720 return iteratee(accumulator, value, index, object);
13722 return accumulator;
13726 * Removes the property at `path` of `object`.
13728 * **Note:** This method mutates `object`.
13734 * @param {Object} object The object to modify.
13735 * @param {Array|string} path The path of the property to unset.
13736 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
13739 * var object = { 'a': [{ 'b': { 'c': 7 } }] };
13740 * _.unset(object, 'a[0].b.c');
13743 * console.log(object);
13744 * // => { 'a': [{ 'b': {} }] };
13746 * _.unset(object, ['a', '0', 'b', 'c']);
13749 * console.log(object);
13750 * // => { 'a': [{ 'b': {} }] };
13752 function unset(object, path) {
13753 return object == null ? true : baseUnset(object, path);
13757 * This method is like `_.set` except that accepts `updater` to produce the
13758 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
13759 * is invoked with one argument: (value).
13761 * **Note:** This method mutates `object`.
13767 * @param {Object} object The object to modify.
13768 * @param {Array|string} path The path of the property to set.
13769 * @param {Function} updater The function to produce the updated value.
13770 * @returns {Object} Returns `object`.
13773 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
13775 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
13776 * console.log(object.a[0].b.c);
13779 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
13780 * console.log(object.x[0].y.z);
13783 function update(object, path, updater) {
13784 return object == null ? object : baseUpdate(object, path, castFunction(updater));
13788 * This method is like `_.update` except that it accepts `customizer` which is
13789 * invoked to produce the objects of `path`. If `customizer` returns `undefined`
13790 * path creation is handled by the method instead. The `customizer` is invoked
13791 * with three arguments: (nsValue, key, nsObject).
13793 * **Note:** This method mutates `object`.
13799 * @param {Object} object The object to modify.
13800 * @param {Array|string} path The path of the property to set.
13801 * @param {Function} updater The function to produce the updated value.
13802 * @param {Function} [customizer] The function to customize assigned values.
13803 * @returns {Object} Returns `object`.
13808 * _.updateWith(object, '[0][1]', _.constant('a'), Object);
13809 * // => { '0': { '1': 'a' } }
13811 function updateWith(object, path, updater, customizer) {
13812 customizer = typeof customizer == 'function' ? customizer : undefined;
13813 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
13817 * Creates an array of the own enumerable string keyed property values of `object`.
13819 * **Note:** Non-object values are coerced to objects.
13825 * @param {Object} object The object to query.
13826 * @returns {Array} Returns the array of property values.
13834 * Foo.prototype.c = 3;
13836 * _.values(new Foo);
13837 * // => [1, 2] (iteration order is not guaranteed)
13842 function values(object) {
13843 return object == null ? [] : baseValues(object, keys(object));
13847 * Creates an array of the own and inherited enumerable string keyed property
13848 * values of `object`.
13850 * **Note:** Non-object values are coerced to objects.
13856 * @param {Object} object The object to query.
13857 * @returns {Array} Returns the array of property values.
13865 * Foo.prototype.c = 3;
13867 * _.valuesIn(new Foo);
13868 * // => [1, 2, 3] (iteration order is not guaranteed)
13870 function valuesIn(object) {
13871 return object == null ? [] : baseValues(object, keysIn(object));
13874 /*------------------------------------------------------------------------*/
13877 * Clamps `number` within the inclusive `lower` and `upper` bounds.
13883 * @param {number} number The number to clamp.
13884 * @param {number} [lower] The lower bound.
13885 * @param {number} upper The upper bound.
13886 * @returns {number} Returns the clamped number.
13889 * _.clamp(-10, -5, 5);
13892 * _.clamp(10, -5, 5);
13895 function clamp(number, lower, upper) {
13896 if (upper === undefined) {
13900 if (upper !== undefined) {
13901 upper = toNumber(upper);
13902 upper = upper === upper ? upper : 0;
13904 if (lower !== undefined) {
13905 lower = toNumber(lower);
13906 lower = lower === lower ? lower : 0;
13908 return baseClamp(toNumber(number), lower, upper);
13912 * Checks if `n` is between `start` and up to, but not including, `end`. If
13913 * `end` is not specified, it's set to `start` with `start` then set to `0`.
13914 * If `start` is greater than `end` the params are swapped to support
13921 * @param {number} number The number to check.
13922 * @param {number} [start=0] The start of the range.
13923 * @param {number} end The end of the range.
13924 * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
13925 * @see _.range, _.rangeRight
13928 * _.inRange(3, 2, 4);
13940 * _.inRange(1.2, 2);
13943 * _.inRange(5.2, 4);
13946 * _.inRange(-3, -2, -6);
13949 function inRange(number, start, end) {
13950 start = toFinite(start);
13951 if (end === undefined) {
13955 end = toFinite(end);
13957 number = toNumber(number);
13958 return baseInRange(number, start, end);
13962 * Produces a random number between the inclusive `lower` and `upper` bounds.
13963 * If only one argument is provided a number between `0` and the given number
13964 * is returned. If `floating` is `true`, or either `lower` or `upper` are
13965 * floats, a floating-point number is returned instead of an integer.
13967 * **Note:** JavaScript follows the IEEE-754 standard for resolving
13968 * floating-point values which can produce unexpected results.
13974 * @param {number} [lower=0] The lower bound.
13975 * @param {number} [upper=1] The upper bound.
13976 * @param {boolean} [floating] Specify returning a floating-point number.
13977 * @returns {number} Returns the random number.
13981 * // => an integer between 0 and 5
13984 * // => also an integer between 0 and 5
13986 * _.random(5, true);
13987 * // => a floating-point number between 0 and 5
13989 * _.random(1.2, 5.2);
13990 * // => a floating-point number between 1.2 and 5.2
13992 function random(lower, upper, floating) {
13993 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
13994 upper = floating = undefined;
13996 if (floating === undefined) {
13997 if (typeof upper == 'boolean') {
14001 else if (typeof lower == 'boolean') {
14006 if (lower === undefined && upper === undefined) {
14011 lower = toFinite(lower);
14012 if (upper === undefined) {
14016 upper = toFinite(upper);
14019 if (lower > upper) {
14024 if (floating || lower % 1 || upper % 1) {
14025 var rand = nativeRandom();
14026 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
14028 return baseRandom(lower, upper);
14031 /*------------------------------------------------------------------------*/
14034 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14040 * @param {string} [string=''] The string to convert.
14041 * @returns {string} Returns the camel cased string.
14044 * _.camelCase('Foo Bar');
14047 * _.camelCase('--foo-bar--');
14050 * _.camelCase('__FOO_BAR__');
14053 var camelCase = createCompounder(function(result, word, index) {
14054 word = word.toLowerCase();
14055 return result + (index ? capitalize(word) : word);
14059 * Converts the first character of `string` to upper case and the remaining
14066 * @param {string} [string=''] The string to capitalize.
14067 * @returns {string} Returns the capitalized string.
14070 * _.capitalize('FRED');
14073 function capitalize(string) {
14074 return upperFirst(toString(string).toLowerCase());
14078 * Deburrs `string` by converting
14079 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
14080 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
14081 * letters to basic Latin letters and removing
14082 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
14088 * @param {string} [string=''] The string to deburr.
14089 * @returns {string} Returns the deburred string.
14092 * _.deburr('déjà vu');
14095 function deburr(string) {
14096 string = toString(string);
14097 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
14101 * Checks if `string` ends with the given target string.
14107 * @param {string} [string=''] The string to inspect.
14108 * @param {string} [target] The string to search for.
14109 * @param {number} [position=string.length] The position to search up to.
14110 * @returns {boolean} Returns `true` if `string` ends with `target`,
14114 * _.endsWith('abc', 'c');
14117 * _.endsWith('abc', 'b');
14120 * _.endsWith('abc', 'b', 2);
14123 function endsWith(string, target, position) {
14124 string = toString(string);
14125 target = baseToString(target);
14127 var length = string.length;
14128 position = position === undefined
14130 : baseClamp(toInteger(position), 0, length);
14132 var end = position;
14133 position -= target.length;
14134 return position >= 0 && string.slice(position, end) == target;
14138 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
14139 * corresponding HTML entities.
14141 * **Note:** No other characters are escaped. To escape additional
14142 * characters use a third-party library like [_he_](https://mths.be/he).
14144 * Though the ">" character is escaped for symmetry, characters like
14145 * ">" and "/" don't need escaping in HTML and have no special meaning
14146 * unless they're part of a tag or unquoted attribute value. See
14147 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
14148 * (under "semi-related fun fact") for more details.
14150 * When working with HTML you should always
14151 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
14158 * @param {string} [string=''] The string to escape.
14159 * @returns {string} Returns the escaped string.
14162 * _.escape('fred, barney, & pebbles');
14163 * // => 'fred, barney, & pebbles'
14165 function escape(string) {
14166 string = toString(string);
14167 return (string && reHasUnescapedHtml.test(string))
14168 ? string.replace(reUnescapedHtml, escapeHtmlChar)
14173 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
14174 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
14180 * @param {string} [string=''] The string to escape.
14181 * @returns {string} Returns the escaped string.
14184 * _.escapeRegExp('[lodash](https://lodash.com/)');
14185 * // => '\[lodash\]\(https://lodash\.com/\)'
14187 function escapeRegExp(string) {
14188 string = toString(string);
14189 return (string && reHasRegExpChar.test(string))
14190 ? string.replace(reRegExpChar, '\\$&')
14195 * Converts `string` to
14196 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
14202 * @param {string} [string=''] The string to convert.
14203 * @returns {string} Returns the kebab cased string.
14206 * _.kebabCase('Foo Bar');
14209 * _.kebabCase('fooBar');
14212 * _.kebabCase('__FOO_BAR__');
14215 var kebabCase = createCompounder(function(result, word, index) {
14216 return result + (index ? '-' : '') + word.toLowerCase();
14220 * Converts `string`, as space separated words, to lower case.
14226 * @param {string} [string=''] The string to convert.
14227 * @returns {string} Returns the lower cased string.
14230 * _.lowerCase('--Foo-Bar--');
14233 * _.lowerCase('fooBar');
14236 * _.lowerCase('__FOO_BAR__');
14239 var lowerCase = createCompounder(function(result, word, index) {
14240 return result + (index ? ' ' : '') + word.toLowerCase();
14244 * Converts the first character of `string` to lower case.
14250 * @param {string} [string=''] The string to convert.
14251 * @returns {string} Returns the converted string.
14254 * _.lowerFirst('Fred');
14257 * _.lowerFirst('FRED');
14260 var lowerFirst = createCaseFirst('toLowerCase');
14263 * Pads `string` on the left and right sides if it's shorter than `length`.
14264 * Padding characters are truncated if they can't be evenly divided by `length`.
14270 * @param {string} [string=''] The string to pad.
14271 * @param {number} [length=0] The padding length.
14272 * @param {string} [chars=' '] The string used as padding.
14273 * @returns {string} Returns the padded string.
14279 * _.pad('abc', 8, '_-');
14285 function pad(string, length, chars) {
14286 string = toString(string);
14287 length = toInteger(length);
14289 var strLength = length ? stringSize(string) : 0;
14290 if (!length || strLength >= length) {
14293 var mid = (length - strLength) / 2;
14295 createPadding(nativeFloor(mid), chars) +
14297 createPadding(nativeCeil(mid), chars)
14302 * Pads `string` on the right side if it's shorter than `length`. Padding
14303 * characters are truncated if they exceed `length`.
14309 * @param {string} [string=''] The string to pad.
14310 * @param {number} [length=0] The padding length.
14311 * @param {string} [chars=' '] The string used as padding.
14312 * @returns {string} Returns the padded string.
14315 * _.padEnd('abc', 6);
14318 * _.padEnd('abc', 6, '_-');
14321 * _.padEnd('abc', 3);
14324 function padEnd(string, length, chars) {
14325 string = toString(string);
14326 length = toInteger(length);
14328 var strLength = length ? stringSize(string) : 0;
14329 return (length && strLength < length)
14330 ? (string + createPadding(length - strLength, chars))
14335 * Pads `string` on the left side if it's shorter than `length`. Padding
14336 * characters are truncated if they exceed `length`.
14342 * @param {string} [string=''] The string to pad.
14343 * @param {number} [length=0] The padding length.
14344 * @param {string} [chars=' '] The string used as padding.
14345 * @returns {string} Returns the padded string.
14348 * _.padStart('abc', 6);
14351 * _.padStart('abc', 6, '_-');
14354 * _.padStart('abc', 3);
14357 function padStart(string, length, chars) {
14358 string = toString(string);
14359 length = toInteger(length);
14361 var strLength = length ? stringSize(string) : 0;
14362 return (length && strLength < length)
14363 ? (createPadding(length - strLength, chars) + string)
14368 * Converts `string` to an integer of the specified radix. If `radix` is
14369 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
14370 * hexadecimal, in which case a `radix` of `16` is used.
14372 * **Note:** This method aligns with the
14373 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
14379 * @param {string} string The string to convert.
14380 * @param {number} [radix=10] The radix to interpret `value` by.
14381 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14382 * @returns {number} Returns the converted integer.
14385 * _.parseInt('08');
14388 * _.map(['6', '08', '10'], _.parseInt);
14391 function parseInt(string, radix, guard) {
14392 if (guard || radix == null) {
14394 } else if (radix) {
14397 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
14401 * Repeats the given string `n` times.
14407 * @param {string} [string=''] The string to repeat.
14408 * @param {number} [n=1] The number of times to repeat the string.
14409 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14410 * @returns {string} Returns the repeated string.
14413 * _.repeat('*', 3);
14416 * _.repeat('abc', 2);
14419 * _.repeat('abc', 0);
14422 function repeat(string, n, guard) {
14423 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
14428 return baseRepeat(toString(string), n);
14432 * Replaces matches for `pattern` in `string` with `replacement`.
14434 * **Note:** This method is based on
14435 * [`String#replace`](https://mdn.io/String/replace).
14441 * @param {string} [string=''] The string to modify.
14442 * @param {RegExp|string} pattern The pattern to replace.
14443 * @param {Function|string} replacement The match replacement.
14444 * @returns {string} Returns the modified string.
14447 * _.replace('Hi Fred', 'Fred', 'Barney');
14448 * // => 'Hi Barney'
14450 function replace() {
14451 var args = arguments,
14452 string = toString(args[0]);
14454 return args.length < 3 ? string : string.replace(args[1], args[2]);
14458 * Converts `string` to
14459 * [snake case](https://en.wikipedia.org/wiki/Snake_case).
14465 * @param {string} [string=''] The string to convert.
14466 * @returns {string} Returns the snake cased string.
14469 * _.snakeCase('Foo Bar');
14472 * _.snakeCase('fooBar');
14475 * _.snakeCase('--FOO-BAR--');
14478 var snakeCase = createCompounder(function(result, word, index) {
14479 return result + (index ? '_' : '') + word.toLowerCase();
14483 * Splits `string` by `separator`.
14485 * **Note:** This method is based on
14486 * [`String#split`](https://mdn.io/String/split).
14492 * @param {string} [string=''] The string to split.
14493 * @param {RegExp|string} separator The separator pattern to split by.
14494 * @param {number} [limit] The length to truncate results to.
14495 * @returns {Array} Returns the string segments.
14498 * _.split('a-b-c', '-', 2);
14501 function split(string, separator, limit) {
14502 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
14503 separator = limit = undefined;
14505 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
14509 string = toString(string);
14511 typeof separator == 'string' ||
14512 (separator != null && !isRegExp(separator))
14514 separator = baseToString(separator);
14515 if (!separator && hasUnicode(string)) {
14516 return castSlice(stringToArray(string), 0, limit);
14519 return string.split(separator, limit);
14523 * Converts `string` to
14524 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
14530 * @param {string} [string=''] The string to convert.
14531 * @returns {string} Returns the start cased string.
14534 * _.startCase('--foo-bar--');
14537 * _.startCase('fooBar');
14540 * _.startCase('__FOO_BAR__');
14543 var startCase = createCompounder(function(result, word, index) {
14544 return result + (index ? ' ' : '') + upperFirst(word);
14548 * Checks if `string` starts with the given target string.
14554 * @param {string} [string=''] The string to inspect.
14555 * @param {string} [target] The string to search for.
14556 * @param {number} [position=0] The position to search from.
14557 * @returns {boolean} Returns `true` if `string` starts with `target`,
14561 * _.startsWith('abc', 'a');
14564 * _.startsWith('abc', 'b');
14567 * _.startsWith('abc', 'b', 1);
14570 function startsWith(string, target, position) {
14571 string = toString(string);
14572 position = baseClamp(toInteger(position), 0, string.length);
14573 target = baseToString(target);
14574 return string.slice(position, position + target.length) == target;
14578 * Creates a compiled template function that can interpolate data properties
14579 * in "interpolate" delimiters, HTML-escape interpolated data properties in
14580 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
14581 * properties may be accessed as free variables in the template. If a setting
14582 * object is given, it takes precedence over `_.templateSettings` values.
14584 * **Note:** In the development build `_.template` utilizes
14585 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
14586 * for easier debugging.
14588 * For more information on precompiling templates see
14589 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
14591 * For more information on Chrome extension sandboxes see
14592 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
14598 * @param {string} [string=''] The template string.
14599 * @param {Object} [options={}] The options object.
14600 * @param {RegExp} [options.escape=_.templateSettings.escape]
14601 * The HTML "escape" delimiter.
14602 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
14603 * The "evaluate" delimiter.
14604 * @param {Object} [options.imports=_.templateSettings.imports]
14605 * An object to import into the template as free variables.
14606 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
14607 * The "interpolate" delimiter.
14608 * @param {string} [options.sourceURL='lodash.templateSources[n]']
14609 * The sourceURL of the compiled template.
14610 * @param {string} [options.variable='obj']
14611 * The data object variable name.
14612 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14613 * @returns {Function} Returns the compiled template function.
14616 * // Use the "interpolate" delimiter to create a compiled template.
14617 * var compiled = _.template('hello <%= user %>!');
14618 * compiled({ 'user': 'fred' });
14619 * // => 'hello fred!'
14621 * // Use the HTML "escape" delimiter to escape data property values.
14622 * var compiled = _.template('<b><%- value %></b>');
14623 * compiled({ 'value': '<script>' });
14624 * // => '<b><script></b>'
14626 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
14627 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
14628 * compiled({ 'users': ['fred', 'barney'] });
14629 * // => '<li>fred</li><li>barney</li>'
14631 * // Use the internal `print` function in "evaluate" delimiters.
14632 * var compiled = _.template('<% print("hello " + user); %>!');
14633 * compiled({ 'user': 'barney' });
14634 * // => 'hello barney!'
14636 * // Use the ES template literal delimiter as an "interpolate" delimiter.
14637 * // Disable support by replacing the "interpolate" delimiter.
14638 * var compiled = _.template('hello ${ user }!');
14639 * compiled({ 'user': 'pebbles' });
14640 * // => 'hello pebbles!'
14642 * // Use backslashes to treat delimiters as plain text.
14643 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
14644 * compiled({ 'value': 'ignored' });
14645 * // => '<%- value %>'
14647 * // Use the `imports` option to import `jQuery` as `jq`.
14648 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
14649 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
14650 * compiled({ 'users': ['fred', 'barney'] });
14651 * // => '<li>fred</li><li>barney</li>'
14653 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
14654 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
14656 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
14658 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
14659 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
14661 * // => function(data) {
14662 * // var __t, __p = '';
14663 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
14667 * // Use custom template delimiters.
14668 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
14669 * var compiled = _.template('hello {{ user }}!');
14670 * compiled({ 'user': 'mustache' });
14671 * // => 'hello mustache!'
14673 * // Use the `source` property to inline compiled templates for meaningful
14674 * // line numbers in error messages and stack traces.
14675 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
14677 * "main": ' + _.template(mainText).source + '\
14681 function template(string, options, guard) {
14682 // Based on John Resig's `tmpl` implementation
14683 // (http://ejohn.org/blog/javascript-micro-templating/)
14684 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
14685 var settings = lodash.templateSettings;
14687 if (guard && isIterateeCall(string, options, guard)) {
14688 options = undefined;
14690 string = toString(string);
14691 options = assignInWith({}, options, settings, assignInDefaults);
14693 var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
14694 importsKeys = keys(imports),
14695 importsValues = baseValues(imports, importsKeys);
14700 interpolate = options.interpolate || reNoMatch,
14701 source = "__p += '";
14703 // Compile the regexp to match each delimiter.
14704 var reDelimiters = RegExp(
14705 (options.escape || reNoMatch).source + '|' +
14706 interpolate.source + '|' +
14707 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
14708 (options.evaluate || reNoMatch).source + '|$'
14711 // Use a sourceURL for easier debugging.
14712 var sourceURL = '//# sourceURL=' +
14713 ('sourceURL' in options
14714 ? options.sourceURL
14715 : ('lodash.templateSources[' + (++templateCounter) + ']')
14718 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
14719 interpolateValue || (interpolateValue = esTemplateValue);
14721 // Escape characters that can't be included in string literals.
14722 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
14724 // Replace delimiters with snippets.
14727 source += "' +\n__e(" + escapeValue + ") +\n'";
14729 if (evaluateValue) {
14730 isEvaluating = true;
14731 source += "';\n" + evaluateValue + ";\n__p += '";
14733 if (interpolateValue) {
14734 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
14736 index = offset + match.length;
14738 // The JS engine embedded in Adobe products needs `match` returned in
14739 // order to produce the correct `offset` value.
14745 // If `variable` is not specified wrap a with-statement around the generated
14746 // code to add the data object to the top of the scope chain.
14747 var variable = options.variable;
14749 source = 'with (obj) {\n' + source + '\n}\n';
14751 // Cleanup code by stripping empty strings.
14752 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
14753 .replace(reEmptyStringMiddle, '$1')
14754 .replace(reEmptyStringTrailing, '$1;');
14756 // Frame code as the function body.
14757 source = 'function(' + (variable || 'obj') + ') {\n' +
14760 : 'obj || (obj = {});\n'
14762 "var __t, __p = ''" +
14764 ? ', __e = _.escape'
14768 ? ', __j = Array.prototype.join;\n' +
14769 "function print() { __p += __j.call(arguments, '') }\n"
14775 var result = attempt(function() {
14776 return Function(importsKeys, sourceURL + 'return ' + source)
14777 .apply(undefined, importsValues);
14780 // Provide the compiled function's source by its `toString` method or
14781 // the `source` property as a convenience for inlining compiled templates.
14782 result.source = source;
14783 if (isError(result)) {
14790 * Converts `string`, as a whole, to lower case just like
14791 * [String#toLowerCase](https://mdn.io/toLowerCase).
14797 * @param {string} [string=''] The string to convert.
14798 * @returns {string} Returns the lower cased string.
14801 * _.toLower('--Foo-Bar--');
14802 * // => '--foo-bar--'
14804 * _.toLower('fooBar');
14807 * _.toLower('__FOO_BAR__');
14808 * // => '__foo_bar__'
14810 function toLower(value) {
14811 return toString(value).toLowerCase();
14815 * Converts `string`, as a whole, to upper case just like
14816 * [String#toUpperCase](https://mdn.io/toUpperCase).
14822 * @param {string} [string=''] The string to convert.
14823 * @returns {string} Returns the upper cased string.
14826 * _.toUpper('--foo-bar--');
14827 * // => '--FOO-BAR--'
14829 * _.toUpper('fooBar');
14832 * _.toUpper('__foo_bar__');
14833 * // => '__FOO_BAR__'
14835 function toUpper(value) {
14836 return toString(value).toUpperCase();
14840 * Removes leading and trailing whitespace or specified characters from `string`.
14846 * @param {string} [string=''] The string to trim.
14847 * @param {string} [chars=whitespace] The characters to trim.
14848 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14849 * @returns {string} Returns the trimmed string.
14855 * _.trim('-_-abc-_-', '_-');
14858 * _.map([' foo ', ' bar '], _.trim);
14859 * // => ['foo', 'bar']
14861 function trim(string, chars, guard) {
14862 string = toString(string);
14863 if (string && (guard || chars === undefined)) {
14864 return string.replace(reTrim, '');
14866 if (!string || !(chars = baseToString(chars))) {
14869 var strSymbols = stringToArray(string),
14870 chrSymbols = stringToArray(chars),
14871 start = charsStartIndex(strSymbols, chrSymbols),
14872 end = charsEndIndex(strSymbols, chrSymbols) + 1;
14874 return castSlice(strSymbols, start, end).join('');
14878 * Removes trailing whitespace or specified characters from `string`.
14884 * @param {string} [string=''] The string to trim.
14885 * @param {string} [chars=whitespace] The characters to trim.
14886 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14887 * @returns {string} Returns the trimmed string.
14890 * _.trimEnd(' abc ');
14893 * _.trimEnd('-_-abc-_-', '_-');
14896 function trimEnd(string, chars, guard) {
14897 string = toString(string);
14898 if (string && (guard || chars === undefined)) {
14899 return string.replace(reTrimEnd, '');
14901 if (!string || !(chars = baseToString(chars))) {
14904 var strSymbols = stringToArray(string),
14905 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
14907 return castSlice(strSymbols, 0, end).join('');
14911 * Removes leading whitespace or specified characters from `string`.
14917 * @param {string} [string=''] The string to trim.
14918 * @param {string} [chars=whitespace] The characters to trim.
14919 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
14920 * @returns {string} Returns the trimmed string.
14923 * _.trimStart(' abc ');
14926 * _.trimStart('-_-abc-_-', '_-');
14929 function trimStart(string, chars, guard) {
14930 string = toString(string);
14931 if (string && (guard || chars === undefined)) {
14932 return string.replace(reTrimStart, '');
14934 if (!string || !(chars = baseToString(chars))) {
14937 var strSymbols = stringToArray(string),
14938 start = charsStartIndex(strSymbols, stringToArray(chars));
14940 return castSlice(strSymbols, start).join('');
14944 * Truncates `string` if it's longer than the given maximum string length.
14945 * The last characters of the truncated string are replaced with the omission
14946 * string which defaults to "...".
14952 * @param {string} [string=''] The string to truncate.
14953 * @param {Object} [options={}] The options object.
14954 * @param {number} [options.length=30] The maximum string length.
14955 * @param {string} [options.omission='...'] The string to indicate text is omitted.
14956 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
14957 * @returns {string} Returns the truncated string.
14960 * _.truncate('hi-diddly-ho there, neighborino');
14961 * // => 'hi-diddly-ho there, neighbo...'
14963 * _.truncate('hi-diddly-ho there, neighborino', {
14967 * // => 'hi-diddly-ho there,...'
14969 * _.truncate('hi-diddly-ho there, neighborino', {
14971 * 'separator': /,? +/
14973 * // => 'hi-diddly-ho there...'
14975 * _.truncate('hi-diddly-ho there, neighborino', {
14976 * 'omission': ' [...]'
14978 * // => 'hi-diddly-ho there, neig [...]'
14980 function truncate(string, options) {
14981 var length = DEFAULT_TRUNC_LENGTH,
14982 omission = DEFAULT_TRUNC_OMISSION;
14984 if (isObject(options)) {
14985 var separator = 'separator' in options ? options.separator : separator;
14986 length = 'length' in options ? toInteger(options.length) : length;
14987 omission = 'omission' in options ? baseToString(options.omission) : omission;
14989 string = toString(string);
14991 var strLength = string.length;
14992 if (hasUnicode(string)) {
14993 var strSymbols = stringToArray(string);
14994 strLength = strSymbols.length;
14996 if (length >= strLength) {
14999 var end = length - stringSize(omission);
15003 var result = strSymbols
15004 ? castSlice(strSymbols, 0, end).join('')
15005 : string.slice(0, end);
15007 if (separator === undefined) {
15008 return result + omission;
15011 end += (result.length - end);
15013 if (isRegExp(separator)) {
15014 if (string.slice(end).search(separator)) {
15016 substring = result;
15018 if (!separator.global) {
15019 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
15021 separator.lastIndex = 0;
15022 while ((match = separator.exec(substring))) {
15023 var newEnd = match.index;
15025 result = result.slice(0, newEnd === undefined ? end : newEnd);
15027 } else if (string.indexOf(baseToString(separator), end) != end) {
15028 var index = result.lastIndexOf(separator);
15030 result = result.slice(0, index);
15033 return result + omission;
15037 * The inverse of `_.escape`; this method converts the HTML entities
15038 * `&`, `<`, `>`, `"`, and `'` in `string` to
15039 * their corresponding characters.
15041 * **Note:** No other HTML entities are unescaped. To unescape additional
15042 * HTML entities use a third-party library like [_he_](https://mths.be/he).
15048 * @param {string} [string=''] The string to unescape.
15049 * @returns {string} Returns the unescaped string.
15052 * _.unescape('fred, barney, & pebbles');
15053 * // => 'fred, barney, & pebbles'
15055 function unescape(string) {
15056 string = toString(string);
15057 return (string && reHasEscapedHtml.test(string))
15058 ? string.replace(reEscapedHtml, unescapeHtmlChar)
15063 * Converts `string`, as space separated words, to upper case.
15069 * @param {string} [string=''] The string to convert.
15070 * @returns {string} Returns the upper cased string.
15073 * _.upperCase('--foo-bar');
15076 * _.upperCase('fooBar');
15079 * _.upperCase('__foo_bar__');
15082 var upperCase = createCompounder(function(result, word, index) {
15083 return result + (index ? ' ' : '') + word.toUpperCase();
15087 * Converts the first character of `string` to upper case.
15093 * @param {string} [string=''] The string to convert.
15094 * @returns {string} Returns the converted string.
15097 * _.upperFirst('fred');
15100 * _.upperFirst('FRED');
15103 var upperFirst = createCaseFirst('toUpperCase');
15106 * Splits `string` into an array of its words.
15112 * @param {string} [string=''] The string to inspect.
15113 * @param {RegExp|string} [pattern] The pattern to match words.
15114 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
15115 * @returns {Array} Returns the words of `string`.
15118 * _.words('fred, barney, & pebbles');
15119 * // => ['fred', 'barney', 'pebbles']
15121 * _.words('fred, barney, & pebbles', /[^, ]+/g);
15122 * // => ['fred', 'barney', '&', 'pebbles']
15124 function words(string, pattern, guard) {
15125 string = toString(string);
15126 pattern = guard ? undefined : pattern;
15128 if (pattern === undefined) {
15129 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
15131 return string.match(pattern) || [];
15134 /*------------------------------------------------------------------------*/
15137 * Attempts to invoke `func`, returning either the result or the caught error
15138 * object. Any additional arguments are provided to `func` when it's invoked.
15144 * @param {Function} func The function to attempt.
15145 * @param {...*} [args] The arguments to invoke `func` with.
15146 * @returns {*} Returns the `func` result or error object.
15149 * // Avoid throwing errors for invalid selectors.
15150 * var elements = _.attempt(function(selector) {
15151 * return document.querySelectorAll(selector);
15154 * if (_.isError(elements)) {
15158 var attempt = baseRest(function(func, args) {
15160 return apply(func, undefined, args);
15162 return isError(e) ? e : new Error(e);
15167 * Binds methods of an object to the object itself, overwriting the existing
15170 * **Note:** This method doesn't set the "length" property of bound functions.
15176 * @param {Object} object The object to bind and assign the bound methods to.
15177 * @param {...(string|string[])} methodNames The object method names to bind.
15178 * @returns {Object} Returns `object`.
15183 * 'click': function() {
15184 * console.log('clicked ' + this.label);
15188 * _.bindAll(view, ['click']);
15189 * jQuery(element).on('click', view.click);
15190 * // => Logs 'clicked docs' when clicked.
15192 var bindAll = flatRest(function(object, methodNames) {
15193 arrayEach(methodNames, function(key) {
15195 baseAssignValue(object, key, bind(object[key], object));
15201 * Creates a function that iterates over `pairs` and invokes the corresponding
15202 * function of the first predicate to return truthy. The predicate-function
15203 * pairs are invoked with the `this` binding and arguments of the created
15210 * @param {Array} pairs The predicate-function pairs.
15211 * @returns {Function} Returns the new composite function.
15214 * var func = _.cond([
15215 * [_.matches({ 'a': 1 }), _.constant('matches A')],
15216 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
15217 * [_.stubTrue, _.constant('no match')]
15220 * func({ 'a': 1, 'b': 2 });
15221 * // => 'matches A'
15223 * func({ 'a': 0, 'b': 1 });
15224 * // => 'matches B'
15226 * func({ 'a': '1', 'b': '2' });
15229 function cond(pairs) {
15230 var length = pairs == null ? 0 : pairs.length,
15231 toIteratee = getIteratee();
15233 pairs = !length ? [] : arrayMap(pairs, function(pair) {
15234 if (typeof pair[1] != 'function') {
15235 throw new TypeError(FUNC_ERROR_TEXT);
15237 return [toIteratee(pair[0]), pair[1]];
15240 return baseRest(function(args) {
15242 while (++index < length) {
15243 var pair = pairs[index];
15244 if (apply(pair[0], this, args)) {
15245 return apply(pair[1], this, args);
15252 * Creates a function that invokes the predicate properties of `source` with
15253 * the corresponding property values of a given object, returning `true` if
15254 * all predicates return truthy, else `false`.
15256 * **Note:** The created function is equivalent to `_.conformsTo` with
15257 * `source` partially applied.
15263 * @param {Object} source The object of property predicates to conform to.
15264 * @returns {Function} Returns the new spec function.
15268 * { 'a': 2, 'b': 1 },
15269 * { 'a': 1, 'b': 2 }
15272 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
15273 * // => [{ 'a': 1, 'b': 2 }]
15275 function conforms(source) {
15276 return baseConforms(baseClone(source, true));
15280 * Creates a function that returns `value`.
15286 * @param {*} value The value to return from the new function.
15287 * @returns {Function} Returns the new constant function.
15290 * var objects = _.times(2, _.constant({ 'a': 1 }));
15292 * console.log(objects);
15293 * // => [{ 'a': 1 }, { 'a': 1 }]
15295 * console.log(objects[0] === objects[1]);
15298 function constant(value) {
15299 return function() {
15305 * Checks `value` to determine whether a default value should be returned in
15306 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
15313 * @param {*} value The value to check.
15314 * @param {*} defaultValue The default value.
15315 * @returns {*} Returns the resolved value.
15318 * _.defaultTo(1, 10);
15321 * _.defaultTo(undefined, 10);
15324 function defaultTo(value, defaultValue) {
15325 return (value == null || value !== value) ? defaultValue : value;
15329 * Creates a function that returns the result of invoking the given functions
15330 * with the `this` binding of the created function, where each successive
15331 * invocation is supplied the return value of the previous.
15337 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15338 * @returns {Function} Returns the new composite function.
15342 * function square(n) {
15346 * var addSquare = _.flow([_.add, square]);
15350 var flow = createFlow();
15353 * This method is like `_.flow` except that it creates a function that
15354 * invokes the given functions from right to left.
15360 * @param {...(Function|Function[])} [funcs] The functions to invoke.
15361 * @returns {Function} Returns the new composite function.
15365 * function square(n) {
15369 * var addSquare = _.flowRight([square, _.add]);
15373 var flowRight = createFlow(true);
15376 * This method returns the first argument it receives.
15382 * @param {*} value Any value.
15383 * @returns {*} Returns `value`.
15386 * var object = { 'a': 1 };
15388 * console.log(_.identity(object) === object);
15391 function identity(value) {
15396 * Creates a function that invokes `func` with the arguments of the created
15397 * function. If `func` is a property name, the created function returns the
15398 * property value for a given element. If `func` is an array or object, the
15399 * created function returns `true` for elements that contain the equivalent
15400 * source properties, otherwise it returns `false`.
15406 * @param {*} [func=_.identity] The value to convert to a callback.
15407 * @returns {Function} Returns the callback.
15411 * { 'user': 'barney', 'age': 36, 'active': true },
15412 * { 'user': 'fred', 'age': 40, 'active': false }
15415 * // The `_.matches` iteratee shorthand.
15416 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
15417 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
15419 * // The `_.matchesProperty` iteratee shorthand.
15420 * _.filter(users, _.iteratee(['user', 'fred']));
15421 * // => [{ 'user': 'fred', 'age': 40 }]
15423 * // The `_.property` iteratee shorthand.
15424 * _.map(users, _.iteratee('user'));
15425 * // => ['barney', 'fred']
15427 * // Create custom iteratee shorthands.
15428 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
15429 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
15430 * return func.test(string);
15434 * _.filter(['abc', 'def'], /ef/);
15437 function iteratee(func) {
15438 return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
15442 * Creates a function that performs a partial deep comparison between a given
15443 * object and `source`, returning `true` if the given object has equivalent
15444 * property values, else `false`.
15446 * **Note:** The created function is equivalent to `_.isMatch` with `source`
15447 * partially applied.
15449 * Partial comparisons will match empty array and empty object `source`
15450 * values against any array or object value, respectively. See `_.isEqual`
15451 * for a list of supported value comparisons.
15457 * @param {Object} source The object of property values to match.
15458 * @returns {Function} Returns the new spec function.
15462 * { 'a': 1, 'b': 2, 'c': 3 },
15463 * { 'a': 4, 'b': 5, 'c': 6 }
15466 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
15467 * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15469 function matches(source) {
15470 return baseMatches(baseClone(source, true));
15474 * Creates a function that performs a partial deep comparison between the
15475 * value at `path` of a given object to `srcValue`, returning `true` if the
15476 * object value is equivalent, else `false`.
15478 * **Note:** Partial comparisons will match empty array and empty object
15479 * `srcValue` values against any array or object value, respectively. See
15480 * `_.isEqual` for a list of supported value comparisons.
15486 * @param {Array|string} path The path of the property to get.
15487 * @param {*} srcValue The value to match.
15488 * @returns {Function} Returns the new spec function.
15492 * { 'a': 1, 'b': 2, 'c': 3 },
15493 * { 'a': 4, 'b': 5, 'c': 6 }
15496 * _.find(objects, _.matchesProperty('a', 4));
15497 * // => { 'a': 4, 'b': 5, 'c': 6 }
15499 function matchesProperty(path, srcValue) {
15500 return baseMatchesProperty(path, baseClone(srcValue, true));
15504 * Creates a function that invokes the method at `path` of a given object.
15505 * Any additional arguments are provided to the invoked method.
15511 * @param {Array|string} path The path of the method to invoke.
15512 * @param {...*} [args] The arguments to invoke the method with.
15513 * @returns {Function} Returns the new invoker function.
15517 * { 'a': { 'b': _.constant(2) } },
15518 * { 'a': { 'b': _.constant(1) } }
15521 * _.map(objects, _.method('a.b'));
15524 * _.map(objects, _.method(['a', 'b']));
15527 var method = baseRest(function(path, args) {
15528 return function(object) {
15529 return baseInvoke(object, path, args);
15534 * The opposite of `_.method`; this method creates a function that invokes
15535 * the method at a given path of `object`. Any additional arguments are
15536 * provided to the invoked method.
15542 * @param {Object} object The object to query.
15543 * @param {...*} [args] The arguments to invoke the method with.
15544 * @returns {Function} Returns the new invoker function.
15547 * var array = _.times(3, _.constant),
15548 * object = { 'a': array, 'b': array, 'c': array };
15550 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
15553 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
15556 var methodOf = baseRest(function(object, args) {
15557 return function(path) {
15558 return baseInvoke(object, path, args);
15563 * Adds all own enumerable string keyed function properties of a source
15564 * object to the destination object. If `object` is a function, then methods
15565 * are added to its prototype as well.
15567 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15568 * avoid conflicts caused by modifying the original.
15574 * @param {Function|Object} [object=lodash] The destination object.
15575 * @param {Object} source The object of functions to add.
15576 * @param {Object} [options={}] The options object.
15577 * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
15578 * @returns {Function|Object} Returns `object`.
15581 * function vowels(string) {
15582 * return _.filter(string, function(v) {
15583 * return /[aeiou]/i.test(v);
15587 * _.mixin({ 'vowels': vowels });
15588 * _.vowels('fred');
15591 * _('fred').vowels().value();
15594 * _.mixin({ 'vowels': vowels }, { 'chain': false });
15595 * _('fred').vowels();
15598 function mixin(object, source, options) {
15599 var props = keys(source),
15600 methodNames = baseFunctions(source, props);
15602 if (options == null &&
15603 !(isObject(source) && (methodNames.length || !props.length))) {
15607 methodNames = baseFunctions(source, keys(source));
15609 var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
15610 isFunc = isFunction(object);
15612 arrayEach(methodNames, function(methodName) {
15613 var func = source[methodName];
15614 object[methodName] = func;
15616 object.prototype[methodName] = function() {
15617 var chainAll = this.__chain__;
15618 if (chain || chainAll) {
15619 var result = object(this.__wrapped__),
15620 actions = result.__actions__ = copyArray(this.__actions__);
15622 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
15623 result.__chain__ = chainAll;
15626 return func.apply(object, arrayPush([this.value()], arguments));
15635 * Reverts the `_` variable to its previous value and returns a reference to
15636 * the `lodash` function.
15642 * @returns {Function} Returns the `lodash` function.
15645 * var lodash = _.noConflict();
15647 function noConflict() {
15648 if (root._ === this) {
15655 * This method returns `undefined`.
15663 * _.times(2, _.noop);
15664 * // => [undefined, undefined]
15667 // No operation performed.
15671 * Creates a function that gets the argument at index `n`. If `n` is negative,
15672 * the nth argument from the end is returned.
15678 * @param {number} [n=0] The index of the argument to return.
15679 * @returns {Function} Returns the new pass-thru function.
15682 * var func = _.nthArg(1);
15683 * func('a', 'b', 'c', 'd');
15686 * var func = _.nthArg(-2);
15687 * func('a', 'b', 'c', 'd');
15690 function nthArg(n) {
15692 return baseRest(function(args) {
15693 return baseNth(args, n);
15698 * Creates a function that invokes `iteratees` with the arguments it receives
15699 * and returns their results.
15705 * @param {...(Function|Function[])} [iteratees=[_.identity]]
15706 * The iteratees to invoke.
15707 * @returns {Function} Returns the new function.
15710 * var func = _.over([Math.max, Math.min]);
15712 * func(1, 2, 3, 4);
15715 var over = createOver(arrayMap);
15718 * Creates a function that checks if **all** of the `predicates` return
15719 * truthy when invoked with the arguments it receives.
15725 * @param {...(Function|Function[])} [predicates=[_.identity]]
15726 * The predicates to check.
15727 * @returns {Function} Returns the new function.
15730 * var func = _.overEvery([Boolean, isFinite]);
15741 var overEvery = createOver(arrayEvery);
15744 * Creates a function that checks if **any** of the `predicates` return
15745 * truthy when invoked with the arguments it receives.
15751 * @param {...(Function|Function[])} [predicates=[_.identity]]
15752 * The predicates to check.
15753 * @returns {Function} Returns the new function.
15756 * var func = _.overSome([Boolean, isFinite]);
15767 var overSome = createOver(arraySome);
15770 * Creates a function that returns the value at `path` of a given object.
15776 * @param {Array|string} path The path of the property to get.
15777 * @returns {Function} Returns the new accessor function.
15781 * { 'a': { 'b': 2 } },
15782 * { 'a': { 'b': 1 } }
15785 * _.map(objects, _.property('a.b'));
15788 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
15791 function property(path) {
15792 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
15796 * The opposite of `_.property`; this method creates a function that returns
15797 * the value at a given path of `object`.
15803 * @param {Object} object The object to query.
15804 * @returns {Function} Returns the new accessor function.
15807 * var array = [0, 1, 2],
15808 * object = { 'a': array, 'b': array, 'c': array };
15810 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
15813 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
15816 function propertyOf(object) {
15817 return function(path) {
15818 return object == null ? undefined : baseGet(object, path);
15823 * Creates an array of numbers (positive and/or negative) progressing from
15824 * `start` up to, but not including, `end`. A step of `-1` is used if a negative
15825 * `start` is specified without an `end` or `step`. If `end` is not specified,
15826 * it's set to `start` with `start` then set to `0`.
15828 * **Note:** JavaScript follows the IEEE-754 standard for resolving
15829 * floating-point values which can produce unexpected results.
15835 * @param {number} [start=0] The start of the range.
15836 * @param {number} end The end of the range.
15837 * @param {number} [step=1] The value to increment or decrement by.
15838 * @returns {Array} Returns the range of numbers.
15839 * @see _.inRange, _.rangeRight
15843 * // => [0, 1, 2, 3]
15846 * // => [0, -1, -2, -3]
15849 * // => [1, 2, 3, 4]
15851 * _.range(0, 20, 5);
15852 * // => [0, 5, 10, 15]
15854 * _.range(0, -4, -1);
15855 * // => [0, -1, -2, -3]
15857 * _.range(1, 4, 0);
15863 var range = createRange();
15866 * This method is like `_.range` except that it populates values in
15867 * descending order.
15873 * @param {number} [start=0] The start of the range.
15874 * @param {number} end The end of the range.
15875 * @param {number} [step=1] The value to increment or decrement by.
15876 * @returns {Array} Returns the range of numbers.
15877 * @see _.inRange, _.range
15881 * // => [3, 2, 1, 0]
15883 * _.rangeRight(-4);
15884 * // => [-3, -2, -1, 0]
15886 * _.rangeRight(1, 5);
15887 * // => [4, 3, 2, 1]
15889 * _.rangeRight(0, 20, 5);
15890 * // => [15, 10, 5, 0]
15892 * _.rangeRight(0, -4, -1);
15893 * // => [-3, -2, -1, 0]
15895 * _.rangeRight(1, 4, 0);
15901 var rangeRight = createRange(true);
15904 * This method returns a new empty array.
15910 * @returns {Array} Returns the new empty array.
15913 * var arrays = _.times(2, _.stubArray);
15915 * console.log(arrays);
15918 * console.log(arrays[0] === arrays[1]);
15921 function stubArray() {
15926 * This method returns `false`.
15932 * @returns {boolean} Returns `false`.
15935 * _.times(2, _.stubFalse);
15936 * // => [false, false]
15938 function stubFalse() {
15943 * This method returns a new empty object.
15949 * @returns {Object} Returns the new empty object.
15952 * var objects = _.times(2, _.stubObject);
15954 * console.log(objects);
15957 * console.log(objects[0] === objects[1]);
15960 function stubObject() {
15965 * This method returns an empty string.
15971 * @returns {string} Returns the empty string.
15974 * _.times(2, _.stubString);
15977 function stubString() {
15982 * This method returns `true`.
15988 * @returns {boolean} Returns `true`.
15991 * _.times(2, _.stubTrue);
15992 * // => [true, true]
15994 function stubTrue() {
15999 * Invokes the iteratee `n` times, returning an array of the results of
16000 * each invocation. The iteratee is invoked with one argument; (index).
16006 * @param {number} n The number of times to invoke `iteratee`.
16007 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16008 * @returns {Array} Returns the array of results.
16011 * _.times(3, String);
16012 * // => ['0', '1', '2']
16014 * _.times(4, _.constant(0));
16015 * // => [0, 0, 0, 0]
16017 function times(n, iteratee) {
16019 if (n < 1 || n > MAX_SAFE_INTEGER) {
16022 var index = MAX_ARRAY_LENGTH,
16023 length = nativeMin(n, MAX_ARRAY_LENGTH);
16025 iteratee = getIteratee(iteratee);
16026 n -= MAX_ARRAY_LENGTH;
16028 var result = baseTimes(length, iteratee);
16029 while (++index < n) {
16036 * Converts `value` to a property path array.
16042 * @param {*} value The value to convert.
16043 * @returns {Array} Returns the new property path array.
16046 * _.toPath('a.b.c');
16047 * // => ['a', 'b', 'c']
16049 * _.toPath('a[0].b.c');
16050 * // => ['a', '0', 'b', 'c']
16052 function toPath(value) {
16053 if (isArray(value)) {
16054 return arrayMap(value, toKey);
16056 return isSymbol(value) ? [value] : copyArray(stringToPath(value));
16060 * Generates a unique ID. If `prefix` is given, the ID is appended to it.
16066 * @param {string} [prefix=''] The value to prefix the ID with.
16067 * @returns {string} Returns the unique ID.
16070 * _.uniqueId('contact_');
16071 * // => 'contact_104'
16076 function uniqueId(prefix) {
16077 var id = ++idCounter;
16078 return toString(prefix) + id;
16081 /*------------------------------------------------------------------------*/
16084 * Adds two numbers.
16090 * @param {number} augend The first number in an addition.
16091 * @param {number} addend The second number in an addition.
16092 * @returns {number} Returns the total.
16098 var add = createMathOperation(function(augend, addend) {
16099 return augend + addend;
16103 * Computes `number` rounded up to `precision`.
16109 * @param {number} number The number to round up.
16110 * @param {number} [precision=0] The precision to round up to.
16111 * @returns {number} Returns the rounded up number.
16117 * _.ceil(6.004, 2);
16120 * _.ceil(6040, -2);
16123 var ceil = createRound('ceil');
16126 * Divide two numbers.
16132 * @param {number} dividend The first number in a division.
16133 * @param {number} divisor The second number in a division.
16134 * @returns {number} Returns the quotient.
16140 var divide = createMathOperation(function(dividend, divisor) {
16141 return dividend / divisor;
16145 * Computes `number` rounded down to `precision`.
16151 * @param {number} number The number to round down.
16152 * @param {number} [precision=0] The precision to round down to.
16153 * @returns {number} Returns the rounded down number.
16159 * _.floor(0.046, 2);
16162 * _.floor(4060, -2);
16165 var floor = createRound('floor');
16168 * Computes the maximum value of `array`. If `array` is empty or falsey,
16169 * `undefined` is returned.
16175 * @param {Array} array The array to iterate over.
16176 * @returns {*} Returns the maximum value.
16179 * _.max([4, 2, 8, 6]);
16185 function max(array) {
16186 return (array && array.length)
16187 ? baseExtremum(array, identity, baseGt)
16192 * This method is like `_.max` except that it accepts `iteratee` which is
16193 * invoked for each element in `array` to generate the criterion by which
16194 * the value is ranked. The iteratee is invoked with one argument: (value).
16200 * @param {Array} array The array to iterate over.
16201 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16202 * @returns {*} Returns the maximum value.
16205 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16207 * _.maxBy(objects, function(o) { return o.n; });
16210 * // The `_.property` iteratee shorthand.
16211 * _.maxBy(objects, 'n');
16214 function maxBy(array, iteratee) {
16215 return (array && array.length)
16216 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
16221 * Computes the mean of the values in `array`.
16227 * @param {Array} array The array to iterate over.
16228 * @returns {number} Returns the mean.
16231 * _.mean([4, 2, 8, 6]);
16234 function mean(array) {
16235 return baseMean(array, identity);
16239 * This method is like `_.mean` except that it accepts `iteratee` which is
16240 * invoked for each element in `array` to generate the value to be averaged.
16241 * The iteratee is invoked with one argument: (value).
16247 * @param {Array} array The array to iterate over.
16248 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16249 * @returns {number} Returns the mean.
16252 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16254 * _.meanBy(objects, function(o) { return o.n; });
16257 * // The `_.property` iteratee shorthand.
16258 * _.meanBy(objects, 'n');
16261 function meanBy(array, iteratee) {
16262 return baseMean(array, getIteratee(iteratee, 2));
16266 * Computes the minimum value of `array`. If `array` is empty or falsey,
16267 * `undefined` is returned.
16273 * @param {Array} array The array to iterate over.
16274 * @returns {*} Returns the minimum value.
16277 * _.min([4, 2, 8, 6]);
16283 function min(array) {
16284 return (array && array.length)
16285 ? baseExtremum(array, identity, baseLt)
16290 * This method is like `_.min` except that it accepts `iteratee` which is
16291 * invoked for each element in `array` to generate the criterion by which
16292 * the value is ranked. The iteratee is invoked with one argument: (value).
16298 * @param {Array} array The array to iterate over.
16299 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16300 * @returns {*} Returns the minimum value.
16303 * var objects = [{ 'n': 1 }, { 'n': 2 }];
16305 * _.minBy(objects, function(o) { return o.n; });
16308 * // The `_.property` iteratee shorthand.
16309 * _.minBy(objects, 'n');
16312 function minBy(array, iteratee) {
16313 return (array && array.length)
16314 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
16319 * Multiply two numbers.
16325 * @param {number} multiplier The first number in a multiplication.
16326 * @param {number} multiplicand The second number in a multiplication.
16327 * @returns {number} Returns the product.
16330 * _.multiply(6, 4);
16333 var multiply = createMathOperation(function(multiplier, multiplicand) {
16334 return multiplier * multiplicand;
16338 * Computes `number` rounded to `precision`.
16344 * @param {number} number The number to round.
16345 * @param {number} [precision=0] The precision to round to.
16346 * @returns {number} Returns the rounded number.
16352 * _.round(4.006, 2);
16355 * _.round(4060, -2);
16358 var round = createRound('round');
16361 * Subtract two numbers.
16367 * @param {number} minuend The first number in a subtraction.
16368 * @param {number} subtrahend The second number in a subtraction.
16369 * @returns {number} Returns the difference.
16372 * _.subtract(6, 4);
16375 var subtract = createMathOperation(function(minuend, subtrahend) {
16376 return minuend - subtrahend;
16380 * Computes the sum of the values in `array`.
16386 * @param {Array} array The array to iterate over.
16387 * @returns {number} Returns the sum.
16390 * _.sum([4, 2, 8, 6]);
16393 function sum(array) {
16394 return (array && array.length)
16395 ? baseSum(array, identity)
16400 * This method is like `_.sum` except that it accepts `iteratee` which is
16401 * invoked for each element in `array` to generate the value to be summed.
16402 * The iteratee is invoked with one argument: (value).
16408 * @param {Array} array The array to iterate over.
16409 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16410 * @returns {number} Returns the sum.
16413 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
16415 * _.sumBy(objects, function(o) { return o.n; });
16418 * // The `_.property` iteratee shorthand.
16419 * _.sumBy(objects, 'n');
16422 function sumBy(array, iteratee) {
16423 return (array && array.length)
16424 ? baseSum(array, getIteratee(iteratee, 2))
16428 /*------------------------------------------------------------------------*/
16430 // Add methods that return wrapped values in chain sequences.
16431 lodash.after = after;
16433 lodash.assign = assign;
16434 lodash.assignIn = assignIn;
16435 lodash.assignInWith = assignInWith;
16436 lodash.assignWith = assignWith;
16438 lodash.before = before;
16439 lodash.bind = bind;
16440 lodash.bindAll = bindAll;
16441 lodash.bindKey = bindKey;
16442 lodash.castArray = castArray;
16443 lodash.chain = chain;
16444 lodash.chunk = chunk;
16445 lodash.compact = compact;
16446 lodash.concat = concat;
16447 lodash.cond = cond;
16448 lodash.conforms = conforms;
16449 lodash.constant = constant;
16450 lodash.countBy = countBy;
16451 lodash.create = create;
16452 lodash.curry = curry;
16453 lodash.curryRight = curryRight;
16454 lodash.debounce = debounce;
16455 lodash.defaults = defaults;
16456 lodash.defaultsDeep = defaultsDeep;
16457 lodash.defer = defer;
16458 lodash.delay = delay;
16459 lodash.difference = difference;
16460 lodash.differenceBy = differenceBy;
16461 lodash.differenceWith = differenceWith;
16462 lodash.drop = drop;
16463 lodash.dropRight = dropRight;
16464 lodash.dropRightWhile = dropRightWhile;
16465 lodash.dropWhile = dropWhile;
16466 lodash.fill = fill;
16467 lodash.filter = filter;
16468 lodash.flatMap = flatMap;
16469 lodash.flatMapDeep = flatMapDeep;
16470 lodash.flatMapDepth = flatMapDepth;
16471 lodash.flatten = flatten;
16472 lodash.flattenDeep = flattenDeep;
16473 lodash.flattenDepth = flattenDepth;
16474 lodash.flip = flip;
16475 lodash.flow = flow;
16476 lodash.flowRight = flowRight;
16477 lodash.fromPairs = fromPairs;
16478 lodash.functions = functions;
16479 lodash.functionsIn = functionsIn;
16480 lodash.groupBy = groupBy;
16481 lodash.initial = initial;
16482 lodash.intersection = intersection;
16483 lodash.intersectionBy = intersectionBy;
16484 lodash.intersectionWith = intersectionWith;
16485 lodash.invert = invert;
16486 lodash.invertBy = invertBy;
16487 lodash.invokeMap = invokeMap;
16488 lodash.iteratee = iteratee;
16489 lodash.keyBy = keyBy;
16490 lodash.keys = keys;
16491 lodash.keysIn = keysIn;
16493 lodash.mapKeys = mapKeys;
16494 lodash.mapValues = mapValues;
16495 lodash.matches = matches;
16496 lodash.matchesProperty = matchesProperty;
16497 lodash.memoize = memoize;
16498 lodash.merge = merge;
16499 lodash.mergeWith = mergeWith;
16500 lodash.method = method;
16501 lodash.methodOf = methodOf;
16502 lodash.mixin = mixin;
16503 lodash.negate = negate;
16504 lodash.nthArg = nthArg;
16505 lodash.omit = omit;
16506 lodash.omitBy = omitBy;
16507 lodash.once = once;
16508 lodash.orderBy = orderBy;
16509 lodash.over = over;
16510 lodash.overArgs = overArgs;
16511 lodash.overEvery = overEvery;
16512 lodash.overSome = overSome;
16513 lodash.partial = partial;
16514 lodash.partialRight = partialRight;
16515 lodash.partition = partition;
16516 lodash.pick = pick;
16517 lodash.pickBy = pickBy;
16518 lodash.property = property;
16519 lodash.propertyOf = propertyOf;
16520 lodash.pull = pull;
16521 lodash.pullAll = pullAll;
16522 lodash.pullAllBy = pullAllBy;
16523 lodash.pullAllWith = pullAllWith;
16524 lodash.pullAt = pullAt;
16525 lodash.range = range;
16526 lodash.rangeRight = rangeRight;
16527 lodash.rearg = rearg;
16528 lodash.reject = reject;
16529 lodash.remove = remove;
16530 lodash.rest = rest;
16531 lodash.reverse = reverse;
16532 lodash.sampleSize = sampleSize;
16534 lodash.setWith = setWith;
16535 lodash.shuffle = shuffle;
16536 lodash.slice = slice;
16537 lodash.sortBy = sortBy;
16538 lodash.sortedUniq = sortedUniq;
16539 lodash.sortedUniqBy = sortedUniqBy;
16540 lodash.split = split;
16541 lodash.spread = spread;
16542 lodash.tail = tail;
16543 lodash.take = take;
16544 lodash.takeRight = takeRight;
16545 lodash.takeRightWhile = takeRightWhile;
16546 lodash.takeWhile = takeWhile;
16548 lodash.throttle = throttle;
16549 lodash.thru = thru;
16550 lodash.toArray = toArray;
16551 lodash.toPairs = toPairs;
16552 lodash.toPairsIn = toPairsIn;
16553 lodash.toPath = toPath;
16554 lodash.toPlainObject = toPlainObject;
16555 lodash.transform = transform;
16556 lodash.unary = unary;
16557 lodash.union = union;
16558 lodash.unionBy = unionBy;
16559 lodash.unionWith = unionWith;
16560 lodash.uniq = uniq;
16561 lodash.uniqBy = uniqBy;
16562 lodash.uniqWith = uniqWith;
16563 lodash.unset = unset;
16564 lodash.unzip = unzip;
16565 lodash.unzipWith = unzipWith;
16566 lodash.update = update;
16567 lodash.updateWith = updateWith;
16568 lodash.values = values;
16569 lodash.valuesIn = valuesIn;
16570 lodash.without = without;
16571 lodash.words = words;
16572 lodash.wrap = wrap;
16574 lodash.xorBy = xorBy;
16575 lodash.xorWith = xorWith;
16577 lodash.zipObject = zipObject;
16578 lodash.zipObjectDeep = zipObjectDeep;
16579 lodash.zipWith = zipWith;
16582 lodash.entries = toPairs;
16583 lodash.entriesIn = toPairsIn;
16584 lodash.extend = assignIn;
16585 lodash.extendWith = assignInWith;
16587 // Add methods to `lodash.prototype`.
16588 mixin(lodash, lodash);
16590 /*------------------------------------------------------------------------*/
16592 // Add methods that return unwrapped values in chain sequences.
16594 lodash.attempt = attempt;
16595 lodash.camelCase = camelCase;
16596 lodash.capitalize = capitalize;
16597 lodash.ceil = ceil;
16598 lodash.clamp = clamp;
16599 lodash.clone = clone;
16600 lodash.cloneDeep = cloneDeep;
16601 lodash.cloneDeepWith = cloneDeepWith;
16602 lodash.cloneWith = cloneWith;
16603 lodash.conformsTo = conformsTo;
16604 lodash.deburr = deburr;
16605 lodash.defaultTo = defaultTo;
16606 lodash.divide = divide;
16607 lodash.endsWith = endsWith;
16609 lodash.escape = escape;
16610 lodash.escapeRegExp = escapeRegExp;
16611 lodash.every = every;
16612 lodash.find = find;
16613 lodash.findIndex = findIndex;
16614 lodash.findKey = findKey;
16615 lodash.findLast = findLast;
16616 lodash.findLastIndex = findLastIndex;
16617 lodash.findLastKey = findLastKey;
16618 lodash.floor = floor;
16619 lodash.forEach = forEach;
16620 lodash.forEachRight = forEachRight;
16621 lodash.forIn = forIn;
16622 lodash.forInRight = forInRight;
16623 lodash.forOwn = forOwn;
16624 lodash.forOwnRight = forOwnRight;
16629 lodash.hasIn = hasIn;
16630 lodash.head = head;
16631 lodash.identity = identity;
16632 lodash.includes = includes;
16633 lodash.indexOf = indexOf;
16634 lodash.inRange = inRange;
16635 lodash.invoke = invoke;
16636 lodash.isArguments = isArguments;
16637 lodash.isArray = isArray;
16638 lodash.isArrayBuffer = isArrayBuffer;
16639 lodash.isArrayLike = isArrayLike;
16640 lodash.isArrayLikeObject = isArrayLikeObject;
16641 lodash.isBoolean = isBoolean;
16642 lodash.isBuffer = isBuffer;
16643 lodash.isDate = isDate;
16644 lodash.isElement = isElement;
16645 lodash.isEmpty = isEmpty;
16646 lodash.isEqual = isEqual;
16647 lodash.isEqualWith = isEqualWith;
16648 lodash.isError = isError;
16649 lodash.isFinite = isFinite;
16650 lodash.isFunction = isFunction;
16651 lodash.isInteger = isInteger;
16652 lodash.isLength = isLength;
16653 lodash.isMap = isMap;
16654 lodash.isMatch = isMatch;
16655 lodash.isMatchWith = isMatchWith;
16656 lodash.isNaN = isNaN;
16657 lodash.isNative = isNative;
16658 lodash.isNil = isNil;
16659 lodash.isNull = isNull;
16660 lodash.isNumber = isNumber;
16661 lodash.isObject = isObject;
16662 lodash.isObjectLike = isObjectLike;
16663 lodash.isPlainObject = isPlainObject;
16664 lodash.isRegExp = isRegExp;
16665 lodash.isSafeInteger = isSafeInteger;
16666 lodash.isSet = isSet;
16667 lodash.isString = isString;
16668 lodash.isSymbol = isSymbol;
16669 lodash.isTypedArray = isTypedArray;
16670 lodash.isUndefined = isUndefined;
16671 lodash.isWeakMap = isWeakMap;
16672 lodash.isWeakSet = isWeakSet;
16673 lodash.join = join;
16674 lodash.kebabCase = kebabCase;
16675 lodash.last = last;
16676 lodash.lastIndexOf = lastIndexOf;
16677 lodash.lowerCase = lowerCase;
16678 lodash.lowerFirst = lowerFirst;
16682 lodash.maxBy = maxBy;
16683 lodash.mean = mean;
16684 lodash.meanBy = meanBy;
16686 lodash.minBy = minBy;
16687 lodash.stubArray = stubArray;
16688 lodash.stubFalse = stubFalse;
16689 lodash.stubObject = stubObject;
16690 lodash.stubString = stubString;
16691 lodash.stubTrue = stubTrue;
16692 lodash.multiply = multiply;
16694 lodash.noConflict = noConflict;
16695 lodash.noop = noop;
16698 lodash.padEnd = padEnd;
16699 lodash.padStart = padStart;
16700 lodash.parseInt = parseInt;
16701 lodash.random = random;
16702 lodash.reduce = reduce;
16703 lodash.reduceRight = reduceRight;
16704 lodash.repeat = repeat;
16705 lodash.replace = replace;
16706 lodash.result = result;
16707 lodash.round = round;
16708 lodash.runInContext = runInContext;
16709 lodash.sample = sample;
16710 lodash.size = size;
16711 lodash.snakeCase = snakeCase;
16712 lodash.some = some;
16713 lodash.sortedIndex = sortedIndex;
16714 lodash.sortedIndexBy = sortedIndexBy;
16715 lodash.sortedIndexOf = sortedIndexOf;
16716 lodash.sortedLastIndex = sortedLastIndex;
16717 lodash.sortedLastIndexBy = sortedLastIndexBy;
16718 lodash.sortedLastIndexOf = sortedLastIndexOf;
16719 lodash.startCase = startCase;
16720 lodash.startsWith = startsWith;
16721 lodash.subtract = subtract;
16723 lodash.sumBy = sumBy;
16724 lodash.template = template;
16725 lodash.times = times;
16726 lodash.toFinite = toFinite;
16727 lodash.toInteger = toInteger;
16728 lodash.toLength = toLength;
16729 lodash.toLower = toLower;
16730 lodash.toNumber = toNumber;
16731 lodash.toSafeInteger = toSafeInteger;
16732 lodash.toString = toString;
16733 lodash.toUpper = toUpper;
16734 lodash.trim = trim;
16735 lodash.trimEnd = trimEnd;
16736 lodash.trimStart = trimStart;
16737 lodash.truncate = truncate;
16738 lodash.unescape = unescape;
16739 lodash.uniqueId = uniqueId;
16740 lodash.upperCase = upperCase;
16741 lodash.upperFirst = upperFirst;
16744 lodash.each = forEach;
16745 lodash.eachRight = forEachRight;
16746 lodash.first = head;
16748 mixin(lodash, (function() {
16750 baseForOwn(lodash, function(func, methodName) {
16751 if (!hasOwnProperty.call(lodash.prototype, methodName)) {
16752 source[methodName] = func;
16756 }()), { 'chain': false });
16758 /*------------------------------------------------------------------------*/
16761 * The semantic version number.
16767 lodash.VERSION = VERSION;
16769 // Assign default placeholders.
16770 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
16771 lodash[methodName].placeholder = lodash;
16774 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
16775 arrayEach(['drop', 'take'], function(methodName, index) {
16776 LazyWrapper.prototype[methodName] = function(n) {
16777 var filtered = this.__filtered__;
16778 if (filtered && !index) {
16779 return new LazyWrapper(this);
16781 n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
16783 var result = this.clone();
16785 result.__takeCount__ = nativeMin(n, result.__takeCount__);
16787 result.__views__.push({
16788 'size': nativeMin(n, MAX_ARRAY_LENGTH),
16789 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
16795 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
16796 return this.reverse()[methodName](n).reverse();
16800 // Add `LazyWrapper` methods that accept an `iteratee` value.
16801 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
16802 var type = index + 1,
16803 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
16805 LazyWrapper.prototype[methodName] = function(iteratee) {
16806 var result = this.clone();
16807 result.__iteratees__.push({
16808 'iteratee': getIteratee(iteratee, 3),
16811 result.__filtered__ = result.__filtered__ || isFilter;
16816 // Add `LazyWrapper` methods for `_.head` and `_.last`.
16817 arrayEach(['head', 'last'], function(methodName, index) {
16818 var takeName = 'take' + (index ? 'Right' : '');
16820 LazyWrapper.prototype[methodName] = function() {
16821 return this[takeName](1).value()[0];
16825 // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
16826 arrayEach(['initial', 'tail'], function(methodName, index) {
16827 var dropName = 'drop' + (index ? '' : 'Right');
16829 LazyWrapper.prototype[methodName] = function() {
16830 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
16834 LazyWrapper.prototype.compact = function() {
16835 return this.filter(identity);
16838 LazyWrapper.prototype.find = function(predicate) {
16839 return this.filter(predicate).head();
16842 LazyWrapper.prototype.findLast = function(predicate) {
16843 return this.reverse().find(predicate);
16846 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
16847 if (typeof path == 'function') {
16848 return new LazyWrapper(this);
16850 return this.map(function(value) {
16851 return baseInvoke(value, path, args);
16855 LazyWrapper.prototype.reject = function(predicate) {
16856 return this.filter(negate(getIteratee(predicate)));
16859 LazyWrapper.prototype.slice = function(start, end) {
16860 start = toInteger(start);
16863 if (result.__filtered__ && (start > 0 || end < 0)) {
16864 return new LazyWrapper(result);
16867 result = result.takeRight(-start);
16868 } else if (start) {
16869 result = result.drop(start);
16871 if (end !== undefined) {
16872 end = toInteger(end);
16873 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
16878 LazyWrapper.prototype.takeRightWhile = function(predicate) {
16879 return this.reverse().takeWhile(predicate).reverse();
16882 LazyWrapper.prototype.toArray = function() {
16883 return this.take(MAX_ARRAY_LENGTH);
16886 // Add `LazyWrapper` methods to `lodash.prototype`.
16887 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16888 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
16889 isTaker = /^(?:head|last)$/.test(methodName),
16890 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
16891 retUnwrapped = isTaker || /^find/.test(methodName);
16896 lodash.prototype[methodName] = function() {
16897 var value = this.__wrapped__,
16898 args = isTaker ? [1] : arguments,
16899 isLazy = value instanceof LazyWrapper,
16900 iteratee = args[0],
16901 useLazy = isLazy || isArray(value);
16903 var interceptor = function(value) {
16904 var result = lodashFunc.apply(lodash, arrayPush([value], args));
16905 return (isTaker && chainAll) ? result[0] : result;
16908 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
16909 // Avoid lazy use if the iteratee has a "length" value other than `1`.
16910 isLazy = useLazy = false;
16912 var chainAll = this.__chain__,
16913 isHybrid = !!this.__actions__.length,
16914 isUnwrapped = retUnwrapped && !chainAll,
16915 onlyLazy = isLazy && !isHybrid;
16917 if (!retUnwrapped && useLazy) {
16918 value = onlyLazy ? value : new LazyWrapper(this);
16919 var result = func.apply(value, args);
16920 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
16921 return new LodashWrapper(result, chainAll);
16923 if (isUnwrapped && onlyLazy) {
16924 return func.apply(this, args);
16926 result = this.thru(interceptor);
16927 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
16931 // Add `Array` methods to `lodash.prototype`.
16932 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
16933 var func = arrayProto[methodName],
16934 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
16935 retUnwrapped = /^(?:pop|shift)$/.test(methodName);
16937 lodash.prototype[methodName] = function() {
16938 var args = arguments;
16939 if (retUnwrapped && !this.__chain__) {
16940 var value = this.value();
16941 return func.apply(isArray(value) ? value : [], args);
16943 return this[chainName](function(value) {
16944 return func.apply(isArray(value) ? value : [], args);
16949 // Map minified method names to their real names.
16950 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
16951 var lodashFunc = lodash[methodName];
16953 var key = (lodashFunc.name + ''),
16954 names = realNames[key] || (realNames[key] = []);
16956 names.push({ 'name': methodName, 'func': lodashFunc });
16960 realNames[createHybrid(undefined, BIND_KEY_FLAG).name] = [{
16965 // Add methods to `LazyWrapper`.
16966 LazyWrapper.prototype.clone = lazyClone;
16967 LazyWrapper.prototype.reverse = lazyReverse;
16968 LazyWrapper.prototype.value = lazyValue;
16970 // Add chain sequence methods to the `lodash` wrapper.
16971 lodash.prototype.at = wrapperAt;
16972 lodash.prototype.chain = wrapperChain;
16973 lodash.prototype.commit = wrapperCommit;
16974 lodash.prototype.next = wrapperNext;
16975 lodash.prototype.plant = wrapperPlant;
16976 lodash.prototype.reverse = wrapperReverse;
16977 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
16979 // Add lazy aliases.
16980 lodash.prototype.first = lodash.prototype.head;
16983 lodash.prototype[symIterator] = wrapperToIterator;
16988 /*--------------------------------------------------------------------------*/
16991 var _ = runInContext();
16993 // Some AMD build optimizers, like r.js, check for condition patterns like:
16994 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
16995 // Expose Lodash on the global object to prevent errors when Lodash is
16996 // loaded by a script tag in the presence of an AMD loader.
16997 // See http://requirejs.org/docs/errors.html#mismatch for more details.
16998 // Use `_.noConflict` to remove Lodash from the global object.
17001 // Define as an anonymous module so, through path mapping, it can be
17002 // referenced as the "underscore" module.
17003 define(function() {
17007 // Check for `exports` after `define` in case a build optimizer adds it.
17008 else if (freeModule) {
17009 // Export for Node.js.
17010 (freeModule.exports = _)._ = _;
17011 // Export for CommonJS support.
17015 // Export to the global object.