3 * lodash 3.10.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash modern -d -o ./index.js`
5 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
15 /** Used as the semantic version number. */
16 var VERSION = '3.10.1';
18 /** Used to compose bitmasks for wrapper metadata. */
23 CURRY_RIGHT_FLAG = 16,
25 PARTIAL_RIGHT_FLAG = 64,
29 /** Used as default options for `_.trunc`. */
30 var DEFAULT_TRUNC_LENGTH = 30,
31 DEFAULT_TRUNC_OMISSION = '...';
33 /** Used to detect when a function becomes hot. */
37 /** Used as the size to enable large array optimizations. */
38 var LARGE_ARRAY_SIZE = 200;
40 /** Used to indicate the type of lazy iteratees. */
41 var LAZY_FILTER_FLAG = 1,
44 /** Used as the `TypeError` message for "Functions" methods. */
45 var FUNC_ERROR_TEXT = 'Expected a function';
47 /** Used as the internal argument placeholder. */
48 var PLACEHOLDER = '__lodash_placeholder__';
50 /** `Object#toString` result references. */
51 var argsTag = '[object Arguments]',
52 arrayTag = '[object Array]',
53 boolTag = '[object Boolean]',
54 dateTag = '[object Date]',
55 errorTag = '[object Error]',
56 funcTag = '[object Function]',
57 mapTag = '[object Map]',
58 numberTag = '[object Number]',
59 objectTag = '[object Object]',
60 regexpTag = '[object RegExp]',
61 setTag = '[object Set]',
62 stringTag = '[object String]',
63 weakMapTag = '[object WeakMap]';
65 var arrayBufferTag = '[object ArrayBuffer]',
66 float32Tag = '[object Float32Array]',
67 float64Tag = '[object Float64Array]',
68 int8Tag = '[object Int8Array]',
69 int16Tag = '[object Int16Array]',
70 int32Tag = '[object Int32Array]',
71 uint8Tag = '[object Uint8Array]',
72 uint8ClampedTag = '[object Uint8ClampedArray]',
73 uint16Tag = '[object Uint16Array]',
74 uint32Tag = '[object Uint32Array]';
76 /** Used to match empty string literals in compiled template source. */
77 var reEmptyStringLeading = /\b__p \+= '';/g,
78 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
79 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
81 /** Used to match HTML entities and HTML characters. */
82 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
83 reUnescapedHtml = /[&<>"'`]/g,
84 reHasEscapedHtml = RegExp(reEscapedHtml.source),
85 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
87 /** Used to match template delimiters. */
88 var reEscape = /<%-([\s\S]+?)%>/g,
89 reEvaluate = /<%([\s\S]+?)%>/g,
90 reInterpolate = /<%=([\s\S]+?)%>/g;
92 /** Used to match property names within property paths. */
93 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
94 reIsPlainProp = /^\w*$/,
95 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
98 * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
99 * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
101 var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
102 reHasRegExpChars = RegExp(reRegExpChars.source);
104 /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
105 var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
107 /** Used to match backslashes in property paths. */
108 var reEscapeChar = /\\(\\)?/g;
110 /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
111 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
113 /** Used to match `RegExp` flags from their coerced string values. */
114 var reFlags = /\w*$/;
116 /** Used to detect hexadecimal string values. */
117 var reHasHexPrefix = /^0[xX]/;
119 /** Used to detect host constructors (Safari > 5). */
120 var reIsHostCtor = /^\[object .+?Constructor\]$/;
122 /** Used to detect unsigned integer values. */
123 var reIsUint = /^\d+$/;
125 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
126 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
128 /** Used to ensure capturing order of template delimiters. */
129 var reNoMatch = /($^)/;
131 /** Used to match unescaped characters in compiled string literals. */
132 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
134 /** Used to match words to create compound words. */
135 var reWords = (function() {
136 var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
137 lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
139 return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
142 /** Used to assign default `context` object properties. */
144 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
145 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
146 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
147 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
148 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
151 /** Used to make template sourceURLs easier to identify. */
152 var templateCounter = -1;
154 /** Used to identify `toStringTag` values of typed arrays. */
155 var typedArrayTags = {};
156 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
157 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
158 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
159 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
160 typedArrayTags[uint32Tag] = true;
161 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
162 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
163 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
164 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
165 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
166 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
167 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
169 /** Used to identify `toStringTag` values supported by `_.clone`. */
170 var cloneableTags = {};
171 cloneableTags[argsTag] = cloneableTags[arrayTag] =
172 cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
173 cloneableTags[dateTag] = cloneableTags[float32Tag] =
174 cloneableTags[float64Tag] = cloneableTags[int8Tag] =
175 cloneableTags[int16Tag] = cloneableTags[int32Tag] =
176 cloneableTags[numberTag] = cloneableTags[objectTag] =
177 cloneableTags[regexpTag] = cloneableTags[stringTag] =
178 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
179 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
180 cloneableTags[errorTag] = cloneableTags[funcTag] =
181 cloneableTags[mapTag] = cloneableTags[setTag] =
182 cloneableTags[weakMapTag] = false;
184 /** Used to map latin-1 supplementary letters to basic latin letters. */
185 var deburredLetters = {
186 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
187 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
188 '\xc7': 'C', '\xe7': 'c',
189 '\xd0': 'D', '\xf0': 'd',
190 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
191 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
192 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
193 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
194 '\xd1': 'N', '\xf1': 'n',
195 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
196 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
197 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
198 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
199 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
200 '\xc6': 'Ae', '\xe6': 'ae',
201 '\xde': 'Th', '\xfe': 'th',
205 /** Used to map characters to HTML entities. */
215 /** Used to map HTML entities to characters. */
216 var htmlUnescapes = {
225 /** Used to determine if values are of the language type `Object`. */
231 /** Used to escape characters for inclusion in compiled regexes. */
232 var regexpEscapes = {
233 '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
234 '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
235 'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
236 'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
237 'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
240 /** Used to escape characters for inclusion in compiled string literals. */
241 var stringEscapes = {
250 /** Detect free variable `exports`. */
251 var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
253 /** Detect free variable `module`. */
254 var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
256 /** Detect free variable `global` from Node.js. */
257 var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
259 /** Detect free variable `self`. */
260 var freeSelf = objectTypes[typeof self] && self && self.Object && self;
262 /** Detect free variable `window`. */
263 var freeWindow = objectTypes[typeof window] && window && window.Object && window;
265 /** Detect the popular CommonJS extension `module.exports`. */
266 var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
269 * Used as a reference to the global object.
271 * The `this` value is used if it's the global object to avoid Greasemonkey's
272 * restricted `window` object, otherwise the `window` object is used.
274 var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
276 /*--------------------------------------------------------------------------*/
279 * The base implementation of `compareAscending` which compares values and
280 * sorts them in ascending order without guaranteeing a stable sort.
283 * @param {*} value The value to compare.
284 * @param {*} other The other value to compare.
285 * @returns {number} Returns the sort order indicator for `value`.
287 function baseCompareAscending(value, other) {
288 if (value !== other) {
289 var valIsNull = value === null,
290 valIsUndef = value === undefined,
291 valIsReflexive = value === value;
293 var othIsNull = other === null,
294 othIsUndef = other === undefined,
295 othIsReflexive = other === other;
297 if ((value > other && !othIsNull) || !valIsReflexive ||
298 (valIsNull && !othIsUndef && othIsReflexive) ||
299 (valIsUndef && othIsReflexive)) {
302 if ((value < other && !valIsNull) || !othIsReflexive ||
303 (othIsNull && !valIsUndef && valIsReflexive) ||
304 (othIsUndef && valIsReflexive)) {
312 * The base implementation of `_.findIndex` and `_.findLastIndex` without
313 * support for callback shorthands and `this` binding.
316 * @param {Array} array The array to search.
317 * @param {Function} predicate The function invoked per iteration.
318 * @param {boolean} [fromRight] Specify iterating from right to left.
319 * @returns {number} Returns the index of the matched value, else `-1`.
321 function baseFindIndex(array, predicate, fromRight) {
322 var length = array.length,
323 index = fromRight ? length : -1;
325 while ((fromRight ? index-- : ++index < length)) {
326 if (predicate(array[index], index, array)) {
334 * The base implementation of `_.indexOf` without support for binary searches.
337 * @param {Array} array The array to search.
338 * @param {*} value The value to search for.
339 * @param {number} fromIndex The index to search from.
340 * @returns {number} Returns the index of the matched value, else `-1`.
342 function baseIndexOf(array, value, fromIndex) {
343 if (value !== value) {
344 return indexOfNaN(array, fromIndex);
346 var index = fromIndex - 1,
347 length = array.length;
349 while (++index < length) {
350 if (array[index] === value) {
358 * The base implementation of `_.isFunction` without support for environments
359 * with incorrect `typeof` results.
362 * @param {*} value The value to check.
363 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
365 function baseIsFunction(value) {
366 // Avoid a Chakra JIT bug in compatibility modes of IE 11.
367 // See https://github.com/jashkenas/underscore/issues/1621 for more details.
368 return typeof value == 'function' || false;
372 * Converts `value` to a string if it's not one. An empty string is returned
373 * for `null` or `undefined` values.
376 * @param {*} value The value to process.
377 * @returns {string} Returns the string.
379 function baseToString(value) {
380 return value == null ? '' : (value + '');
384 * Used by `_.trim` and `_.trimLeft` to get the index of the first character
385 * of `string` that is not found in `chars`.
388 * @param {string} string The string to inspect.
389 * @param {string} chars The characters to find.
390 * @returns {number} Returns the index of the first character not found in `chars`.
392 function charsLeftIndex(string, chars) {
394 length = string.length;
396 while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
401 * Used by `_.trim` and `_.trimRight` to get the index of the last character
402 * of `string` that is not found in `chars`.
405 * @param {string} string The string to inspect.
406 * @param {string} chars The characters to find.
407 * @returns {number} Returns the index of the last character not found in `chars`.
409 function charsRightIndex(string, chars) {
410 var index = string.length;
412 while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
417 * Used by `_.sortBy` to compare transformed elements of a collection and stable
418 * sort them in ascending order.
421 * @param {Object} object The object to compare.
422 * @param {Object} other The other object to compare.
423 * @returns {number} Returns the sort order indicator for `object`.
425 function compareAscending(object, other) {
426 return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
430 * Used by `_.sortByOrder` to compare multiple properties of a value to another
431 * and stable sort them.
433 * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
434 * a value is sorted in ascending order if its corresponding order is "asc", and
435 * descending if "desc".
438 * @param {Object} object The object to compare.
439 * @param {Object} other The other object to compare.
440 * @param {boolean[]} orders The order to sort by for each property.
441 * @returns {number} Returns the sort order indicator for `object`.
443 function compareMultiple(object, other, orders) {
445 objCriteria = object.criteria,
446 othCriteria = other.criteria,
447 length = objCriteria.length,
448 ordersLength = orders.length;
450 while (++index < length) {
451 var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
453 if (index >= ordersLength) {
456 var order = orders[index];
457 return result * ((order === 'asc' || order === true) ? 1 : -1);
460 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
461 // that causes it, under certain circumstances, to provide the same value for
462 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
465 // This also ensures a stable sort in V8 and other engines.
466 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
467 return object.index - other.index;
471 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
474 * @param {string} letter The matched letter to deburr.
475 * @returns {string} Returns the deburred letter.
477 function deburrLetter(letter) {
478 return deburredLetters[letter];
482 * Used by `_.escape` to convert characters to HTML entities.
485 * @param {string} chr The matched character to escape.
486 * @returns {string} Returns the escaped character.
488 function escapeHtmlChar(chr) {
489 return htmlEscapes[chr];
493 * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
496 * @param {string} chr The matched character to escape.
497 * @param {string} leadingChar The capture group for a leading character.
498 * @param {string} whitespaceChar The capture group for a whitespace character.
499 * @returns {string} Returns the escaped character.
501 function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
503 chr = regexpEscapes[chr];
504 } else if (whitespaceChar) {
505 chr = stringEscapes[chr];
511 * Used by `_.template` to escape characters for inclusion in compiled string literals.
514 * @param {string} chr The matched character to escape.
515 * @returns {string} Returns the escaped character.
517 function escapeStringChar(chr) {
518 return '\\' + stringEscapes[chr];
522 * Gets the index at which the first occurrence of `NaN` is found in `array`.
525 * @param {Array} array The array to search.
526 * @param {number} fromIndex The index to search from.
527 * @param {boolean} [fromRight] Specify iterating from right to left.
528 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
530 function indexOfNaN(array, fromIndex, fromRight) {
531 var length = array.length,
532 index = fromIndex + (fromRight ? 0 : -1);
534 while ((fromRight ? index-- : ++index < length)) {
535 var other = array[index];
536 if (other !== other) {
544 * Checks if `value` is object-like.
547 * @param {*} value The value to check.
548 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
550 function isObjectLike(value) {
551 return !!value && typeof value == 'object';
555 * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
556 * character code is whitespace.
559 * @param {number} charCode The character code to inspect.
560 * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
562 function isSpace(charCode) {
563 return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
564 (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
568 * Replaces all `placeholder` elements in `array` with an internal placeholder
569 * and returns an array of their indexes.
572 * @param {Array} array The array to modify.
573 * @param {*} placeholder The placeholder to replace.
574 * @returns {Array} Returns the new array of placeholder indexes.
576 function replaceHolders(array, placeholder) {
578 length = array.length,
582 while (++index < length) {
583 if (array[index] === placeholder) {
584 array[index] = PLACEHOLDER;
585 result[++resIndex] = index;
592 * An implementation of `_.uniq` optimized for sorted arrays without support
593 * for callback shorthands and `this` binding.
596 * @param {Array} array The array to inspect.
597 * @param {Function} [iteratee] The function invoked per iteration.
598 * @returns {Array} Returns the new duplicate-value-free array.
600 function sortedUniq(array, iteratee) {
603 length = array.length,
607 while (++index < length) {
608 var value = array[index],
609 computed = iteratee ? iteratee(value, index, array) : value;
611 if (!index || seen !== computed) {
613 result[++resIndex] = value;
620 * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
621 * character of `string`.
624 * @param {string} string The string to inspect.
625 * @returns {number} Returns the index of the first non-whitespace character.
627 function trimmedLeftIndex(string) {
629 length = string.length;
631 while (++index < length && isSpace(string.charCodeAt(index))) {}
636 * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
637 * character of `string`.
640 * @param {string} string The string to inspect.
641 * @returns {number} Returns the index of the last non-whitespace character.
643 function trimmedRightIndex(string) {
644 var index = string.length;
646 while (index-- && isSpace(string.charCodeAt(index))) {}
651 * Used by `_.unescape` to convert HTML entities to characters.
654 * @param {string} chr The matched character to unescape.
655 * @returns {string} Returns the unescaped character.
657 function unescapeHtmlChar(chr) {
658 return htmlUnescapes[chr];
661 /*--------------------------------------------------------------------------*/
664 * Create a new pristine `lodash` function using the given `context` object.
669 * @param {Object} [context=root] The context object.
670 * @returns {Function} Returns a new `lodash` function.
673 * _.mixin({ 'foo': _.constant('foo') });
675 * var lodash = _.runInContext();
676 * lodash.mixin({ 'bar': lodash.constant('bar') });
678 * _.isFunction(_.foo);
680 * _.isFunction(_.bar);
683 * lodash.isFunction(lodash.foo);
685 * lodash.isFunction(lodash.bar);
688 * // using `context` to mock `Date#getTime` use in `_.now`
689 * var mock = _.runInContext({
690 * 'Date': function() {
691 * return { 'getTime': getTimeMock };
695 * // or creating a suped-up `defer` in Node.js
696 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
698 function runInContext(context) {
699 // Avoid issues with some ES3 environments that attempt to use values, named
700 // after built-in constructors like `Object`, for the creation of literals.
701 // ES5 clears this up by stating that literals must use built-in constructors.
702 // See https://es5.github.io/#x11.1.5 for more details.
703 context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
705 /** Native constructor references. */
706 var Array = context.Array,
708 Error = context.Error,
709 Function = context.Function,
711 Number = context.Number,
712 Object = context.Object,
713 RegExp = context.RegExp,
714 String = context.String,
715 TypeError = context.TypeError;
717 /** Used for native method references. */
718 var arrayProto = Array.prototype,
719 objectProto = Object.prototype,
720 stringProto = String.prototype;
722 /** Used to resolve the decompiled source of functions. */
723 var fnToString = Function.prototype.toString;
725 /** Used to check objects for own properties. */
726 var hasOwnProperty = objectProto.hasOwnProperty;
728 /** Used to generate unique IDs. */
732 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
735 var objToString = objectProto.toString;
737 /** Used to restore the original `_` reference in `_.noConflict`. */
738 var oldDash = root._;
740 /** Used to detect if a method is native. */
741 var reIsNative = RegExp('^' +
742 fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
743 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
746 /** Native method references. */
747 var ArrayBuffer = context.ArrayBuffer,
748 clearTimeout = context.clearTimeout,
749 parseFloat = context.parseFloat,
751 propertyIsEnumerable = objectProto.propertyIsEnumerable,
752 Set = getNative(context, 'Set'),
753 setTimeout = context.setTimeout,
754 splice = arrayProto.splice,
755 Uint8Array = context.Uint8Array,
756 WeakMap = getNative(context, 'WeakMap');
758 /* Native method references for those with the same name as other `lodash` methods. */
759 var nativeCeil = Math.ceil,
760 nativeCreate = getNative(Object, 'create'),
761 nativeFloor = Math.floor,
762 nativeIsArray = getNative(Array, 'isArray'),
763 nativeIsFinite = context.isFinite,
764 nativeKeys = getNative(Object, 'keys'),
765 nativeMax = Math.max,
766 nativeMin = Math.min,
767 nativeNow = getNative(Date, 'now'),
768 nativeParseInt = context.parseInt,
769 nativeRandom = Math.random;
771 /** Used as references for `-Infinity` and `Infinity`. */
772 var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
773 POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
775 /** Used as references for the maximum length and index of an array. */
776 var MAX_ARRAY_LENGTH = 4294967295,
777 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
778 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
781 * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
782 * of an array-like value.
784 var MAX_SAFE_INTEGER = 9007199254740991;
786 /** Used to store function metadata. */
787 var metaMap = WeakMap && new WeakMap;
789 /** Used to lookup unminified function names. */
792 /*------------------------------------------------------------------------*/
795 * Creates a `lodash` object which wraps `value` to enable implicit chaining.
796 * Methods that operate on and return arrays, collections, and functions can
797 * be chained together. Methods that retrieve a single value or may return a
798 * primitive value will automatically end the chain returning the unwrapped
799 * value. Explicit chaining may be enabled using `_.chain`. The execution of
800 * chained methods is lazy, that is, execution is deferred until `_#value`
801 * is implicitly or explicitly called.
803 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
804 * fusion is an optimization strategy which merge iteratee calls; this can help
805 * to avoid the creation of intermediate data structures and greatly reduce the
806 * number of iteratee executions.
808 * Chaining is supported in custom builds as long as the `_#value` method is
809 * directly or indirectly included in the build.
811 * In addition to lodash methods, wrappers have `Array` and `String` methods.
813 * The wrapper `Array` methods are:
814 * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
815 * `splice`, and `unshift`
817 * The wrapper `String` methods are:
818 * `replace` and `split`
820 * The wrapper methods that support shortcut fusion are:
821 * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
822 * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
823 * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
826 * The chainable wrapper methods are:
827 * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
828 * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
829 * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
830 * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
831 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
832 * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
833 * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
834 * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
835 * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
836 * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
837 * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
838 * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
839 * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
840 * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
841 * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
842 * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
843 * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
845 * The wrapper methods that are **not** chainable by default are:
846 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
847 * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
848 * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
849 * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
850 * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
851 * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
852 * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
853 * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
854 * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
855 * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
856 * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
857 * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
858 * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
859 * `unescape`, `uniqueId`, `value`, and `words`
861 * The wrapper method `sample` will return a wrapped value when `n` is provided,
862 * otherwise an unwrapped value is returned.
867 * @param {*} value The value to wrap in a `lodash` instance.
868 * @returns {Object} Returns the new `lodash` wrapper instance.
871 * var wrapped = _([1, 2, 3]);
873 * // returns an unwrapped value
874 * wrapped.reduce(function(total, n) {
879 * // returns a wrapped value
880 * var squares = wrapped.map(function(n) {
884 * _.isArray(squares);
887 * _.isArray(squares.value());
890 function lodash(value) {
891 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
892 if (value instanceof LodashWrapper) {
895 if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
896 return wrapperClone(value);
899 return new LodashWrapper(value);
903 * The function whose prototype all chaining wrappers inherit from.
907 function baseLodash() {
908 // No operation performed.
912 * The base constructor for creating `lodash` wrapper objects.
915 * @param {*} value The value to wrap.
916 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
917 * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
919 function LodashWrapper(value, chainAll, actions) {
920 this.__wrapped__ = value;
921 this.__actions__ = actions || [];
922 this.__chain__ = !!chainAll;
926 * An object environment feature flags.
932 var support = lodash.support = {};
935 * By default, the template delimiters used by lodash are like those in
936 * embedded Ruby (ERB). Change the following template settings to use
937 * alternative delimiters.
943 lodash.templateSettings = {
946 * Used to detect `data` property values to be HTML-escaped.
948 * @memberOf _.templateSettings
954 * Used to detect code to be evaluated.
956 * @memberOf _.templateSettings
959 'evaluate': reEvaluate,
962 * Used to detect `data` property values to inject.
964 * @memberOf _.templateSettings
967 'interpolate': reInterpolate,
970 * Used to reference the data object in the template text.
972 * @memberOf _.templateSettings
978 * Used to import variables into the compiled template.
980 * @memberOf _.templateSettings
986 * A reference to the `lodash` function.
988 * @memberOf _.templateSettings.imports
995 /*------------------------------------------------------------------------*/
998 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1001 * @param {*} value The value to wrap.
1003 function LazyWrapper(value) {
1004 this.__wrapped__ = value;
1005 this.__actions__ = [];
1007 this.__filtered__ = false;
1008 this.__iteratees__ = [];
1009 this.__takeCount__ = POSITIVE_INFINITY;
1010 this.__views__ = [];
1014 * Creates a clone of the lazy wrapper object.
1018 * @memberOf LazyWrapper
1019 * @returns {Object} Returns the cloned `LazyWrapper` object.
1021 function lazyClone() {
1022 var result = new LazyWrapper(this.__wrapped__);
1023 result.__actions__ = arrayCopy(this.__actions__);
1024 result.__dir__ = this.__dir__;
1025 result.__filtered__ = this.__filtered__;
1026 result.__iteratees__ = arrayCopy(this.__iteratees__);
1027 result.__takeCount__ = this.__takeCount__;
1028 result.__views__ = arrayCopy(this.__views__);
1033 * Reverses the direction of lazy iteration.
1037 * @memberOf LazyWrapper
1038 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1040 function lazyReverse() {
1041 if (this.__filtered__) {
1042 var result = new LazyWrapper(this);
1043 result.__dir__ = -1;
1044 result.__filtered__ = true;
1046 result = this.clone();
1047 result.__dir__ *= -1;
1053 * Extracts the unwrapped value from its lazy wrapper.
1057 * @memberOf LazyWrapper
1058 * @returns {*} Returns the unwrapped value.
1060 function lazyValue() {
1061 var array = this.__wrapped__.value(),
1063 isArr = isArray(array),
1065 arrLength = isArr ? array.length : 0,
1066 view = getView(0, arrLength, this.__views__),
1069 length = end - start,
1070 index = isRight ? end : (start - 1),
1071 iteratees = this.__iteratees__,
1072 iterLength = iteratees.length,
1074 takeCount = nativeMin(length, this.__takeCount__);
1076 if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
1077 return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
1082 while (length-- && resIndex < takeCount) {
1086 value = array[index];
1088 while (++iterIndex < iterLength) {
1089 var data = iteratees[iterIndex],
1090 iteratee = data.iteratee,
1092 computed = iteratee(value);
1094 if (type == LAZY_MAP_FLAG) {
1096 } else if (!computed) {
1097 if (type == LAZY_FILTER_FLAG) {
1104 result[resIndex++] = value;
1109 /*------------------------------------------------------------------------*/
1112 * Creates a cache object to store key/value pairs.
1117 * @memberOf _.memoize
1119 function MapCache() {
1124 * Removes `key` and its value from the cache.
1128 * @memberOf _.memoize.Cache
1129 * @param {string} key The key of the value to remove.
1130 * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
1132 function mapDelete(key) {
1133 return this.has(key) && delete this.__data__[key];
1137 * Gets the cached value for `key`.
1141 * @memberOf _.memoize.Cache
1142 * @param {string} key The key of the value to get.
1143 * @returns {*} Returns the cached value.
1145 function mapGet(key) {
1146 return key == '__proto__' ? undefined : this.__data__[key];
1150 * Checks if a cached value for `key` exists.
1154 * @memberOf _.memoize.Cache
1155 * @param {string} key The key of the entry to check.
1156 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1158 function mapHas(key) {
1159 return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
1163 * Sets `value` to `key` of the cache.
1167 * @memberOf _.memoize.Cache
1168 * @param {string} key The key of the value to cache.
1169 * @param {*} value The value to cache.
1170 * @returns {Object} Returns the cache object.
1172 function mapSet(key, value) {
1173 if (key != '__proto__') {
1174 this.__data__[key] = value;
1179 /*------------------------------------------------------------------------*/
1183 * Creates a cache object to store unique values.
1186 * @param {Array} [values] The values to cache.
1188 function SetCache(values) {
1189 var length = values ? values.length : 0;
1191 this.data = { 'hash': nativeCreate(null), 'set': new Set };
1193 this.push(values[length]);
1198 * Checks if `value` is in `cache` mimicking the return signature of
1199 * `_.indexOf` by returning `0` if the value is found, else `-1`.
1202 * @param {Object} cache The cache to search.
1203 * @param {*} value The value to search for.
1204 * @returns {number} Returns `0` if `value` is found, else `-1`.
1206 function cacheIndexOf(cache, value) {
1207 var data = cache.data,
1208 result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
1210 return result ? 0 : -1;
1214 * Adds `value` to the cache.
1218 * @memberOf SetCache
1219 * @param {*} value The value to cache.
1221 function cachePush(value) {
1222 var data = this.data;
1223 if (typeof value == 'string' || isObject(value)) {
1224 data.set.add(value);
1226 data.hash[value] = true;
1230 /*------------------------------------------------------------------------*/
1233 * Creates a new array joining `array` with `other`.
1236 * @param {Array} array The array to join.
1237 * @param {Array} other The other array to join.
1238 * @returns {Array} Returns the new concatenated array.
1240 function arrayConcat(array, other) {
1242 length = array.length,
1244 othLength = other.length,
1245 result = Array(length + othLength);
1247 while (++index < length) {
1248 result[index] = array[index];
1250 while (++othIndex < othLength) {
1251 result[index++] = other[othIndex];
1257 * Copies the values of `source` to `array`.
1260 * @param {Array} source The array to copy values from.
1261 * @param {Array} [array=[]] The array to copy values to.
1262 * @returns {Array} Returns `array`.
1264 function arrayCopy(source, array) {
1266 length = source.length;
1268 array || (array = Array(length));
1269 while (++index < length) {
1270 array[index] = source[index];
1276 * A specialized version of `_.forEach` for arrays without support for callback
1277 * shorthands and `this` binding.
1280 * @param {Array} array The array to iterate over.
1281 * @param {Function} iteratee The function invoked per iteration.
1282 * @returns {Array} Returns `array`.
1284 function arrayEach(array, iteratee) {
1286 length = array.length;
1288 while (++index < length) {
1289 if (iteratee(array[index], index, array) === false) {
1297 * A specialized version of `_.forEachRight` for arrays without support for
1298 * callback shorthands and `this` binding.
1301 * @param {Array} array The array to iterate over.
1302 * @param {Function} iteratee The function invoked per iteration.
1303 * @returns {Array} Returns `array`.
1305 function arrayEachRight(array, iteratee) {
1306 var length = array.length;
1309 if (iteratee(array[length], length, array) === false) {
1317 * A specialized version of `_.every` for arrays without support for callback
1318 * shorthands and `this` binding.
1321 * @param {Array} array The array to iterate over.
1322 * @param {Function} predicate The function invoked per iteration.
1323 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1326 function arrayEvery(array, predicate) {
1328 length = array.length;
1330 while (++index < length) {
1331 if (!predicate(array[index], index, array)) {
1339 * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
1340 * with one argument: (value).
1343 * @param {Array} array The array to iterate over.
1344 * @param {Function} iteratee The function invoked per iteration.
1345 * @param {Function} comparator The function used to compare values.
1346 * @param {*} exValue The initial extremum value.
1347 * @returns {*} Returns the extremum value.
1349 function arrayExtremum(array, iteratee, comparator, exValue) {
1351 length = array.length,
1355 while (++index < length) {
1356 var value = array[index],
1357 current = +iteratee(value);
1359 if (comparator(current, computed)) {
1368 * A specialized version of `_.filter` for arrays without support for callback
1369 * shorthands and `this` binding.
1372 * @param {Array} array The array to iterate over.
1373 * @param {Function} predicate The function invoked per iteration.
1374 * @returns {Array} Returns the new filtered array.
1376 function arrayFilter(array, predicate) {
1378 length = array.length,
1382 while (++index < length) {
1383 var value = array[index];
1384 if (predicate(value, index, array)) {
1385 result[++resIndex] = value;
1392 * A specialized version of `_.map` for arrays without support for callback
1393 * shorthands and `this` binding.
1396 * @param {Array} array The array to iterate over.
1397 * @param {Function} iteratee The function invoked per iteration.
1398 * @returns {Array} Returns the new mapped array.
1400 function arrayMap(array, iteratee) {
1402 length = array.length,
1403 result = Array(length);
1405 while (++index < length) {
1406 result[index] = iteratee(array[index], index, array);
1412 * Appends the elements of `values` to `array`.
1415 * @param {Array} array The array to modify.
1416 * @param {Array} values The values to append.
1417 * @returns {Array} Returns `array`.
1419 function arrayPush(array, values) {
1421 length = values.length,
1422 offset = array.length;
1424 while (++index < length) {
1425 array[offset + index] = values[index];
1431 * A specialized version of `_.reduce` for arrays without support for callback
1432 * shorthands and `this` binding.
1435 * @param {Array} array The array to iterate over.
1436 * @param {Function} iteratee The function invoked per iteration.
1437 * @param {*} [accumulator] The initial value.
1438 * @param {boolean} [initFromArray] Specify using the first element of `array`
1439 * as the initial value.
1440 * @returns {*} Returns the accumulated value.
1442 function arrayReduce(array, iteratee, accumulator, initFromArray) {
1444 length = array.length;
1446 if (initFromArray && length) {
1447 accumulator = array[++index];
1449 while (++index < length) {
1450 accumulator = iteratee(accumulator, array[index], index, array);
1456 * A specialized version of `_.reduceRight` for arrays without support for
1457 * callback shorthands and `this` binding.
1460 * @param {Array} array The array to iterate over.
1461 * @param {Function} iteratee The function invoked per iteration.
1462 * @param {*} [accumulator] The initial value.
1463 * @param {boolean} [initFromArray] Specify using the last element of `array`
1464 * as the initial value.
1465 * @returns {*} Returns the accumulated value.
1467 function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
1468 var length = array.length;
1469 if (initFromArray && length) {
1470 accumulator = array[--length];
1473 accumulator = iteratee(accumulator, array[length], length, array);
1479 * A specialized version of `_.some` for arrays without support for callback
1480 * shorthands and `this` binding.
1483 * @param {Array} array The array to iterate over.
1484 * @param {Function} predicate The function invoked per iteration.
1485 * @returns {boolean} Returns `true` if any element passes the predicate check,
1488 function arraySome(array, predicate) {
1490 length = array.length;
1492 while (++index < length) {
1493 if (predicate(array[index], index, array)) {
1501 * A specialized version of `_.sum` for arrays without support for callback
1502 * shorthands and `this` binding..
1505 * @param {Array} array The array to iterate over.
1506 * @param {Function} iteratee The function invoked per iteration.
1507 * @returns {number} Returns the sum.
1509 function arraySum(array, iteratee) {
1510 var length = array.length,
1514 result += +iteratee(array[length]) || 0;
1520 * Used by `_.defaults` to customize its `_.assign` use.
1523 * @param {*} objectValue The destination object property value.
1524 * @param {*} sourceValue The source object property value.
1525 * @returns {*} Returns the value to assign to the destination object.
1527 function assignDefaults(objectValue, sourceValue) {
1528 return objectValue === undefined ? sourceValue : objectValue;
1532 * Used by `_.template` to customize its `_.assign` use.
1534 * **Note:** This function is like `assignDefaults` except that it ignores
1535 * inherited property values when checking if a property is `undefined`.
1538 * @param {*} objectValue The destination object property value.
1539 * @param {*} sourceValue The source object property value.
1540 * @param {string} key The key associated with the object and source values.
1541 * @param {Object} object The destination object.
1542 * @returns {*} Returns the value to assign to the destination object.
1544 function assignOwnDefaults(objectValue, sourceValue, key, object) {
1545 return (objectValue === undefined || !hasOwnProperty.call(object, key))
1551 * A specialized version of `_.assign` for customizing assigned values without
1552 * support for argument juggling, multiple sources, and `this` binding `customizer`
1556 * @param {Object} object The destination object.
1557 * @param {Object} source The source object.
1558 * @param {Function} customizer The function to customize assigned values.
1559 * @returns {Object} Returns `object`.
1561 function assignWith(object, source, customizer) {
1563 props = keys(source),
1564 length = props.length;
1566 while (++index < length) {
1567 var key = props[index],
1568 value = object[key],
1569 result = customizer(value, source[key], key, object, source);
1571 if ((result === result ? (result !== value) : (value === value)) ||
1572 (value === undefined && !(key in object))) {
1573 object[key] = result;
1580 * The base implementation of `_.assign` without support for argument juggling,
1581 * multiple sources, and `customizer` functions.
1584 * @param {Object} object The destination object.
1585 * @param {Object} source The source object.
1586 * @returns {Object} Returns `object`.
1588 function baseAssign(object, source) {
1589 return source == null
1591 : baseCopy(source, keys(source), object);
1595 * The base implementation of `_.at` without support for string collections
1596 * and individual key arguments.
1599 * @param {Array|Object} collection The collection to iterate over.
1600 * @param {number[]|string[]} props The property names or indexes of elements to pick.
1601 * @returns {Array} Returns the new array of picked elements.
1603 function baseAt(collection, props) {
1605 isNil = collection == null,
1606 isArr = !isNil && isArrayLike(collection),
1607 length = isArr ? collection.length : 0,
1608 propsLength = props.length,
1609 result = Array(propsLength);
1611 while(++index < propsLength) {
1612 var key = props[index];
1614 result[index] = isIndex(key, length) ? collection[key] : undefined;
1616 result[index] = isNil ? undefined : collection[key];
1623 * Copies properties of `source` to `object`.
1626 * @param {Object} source The object to copy properties from.
1627 * @param {Array} props The property names to copy.
1628 * @param {Object} [object={}] The object to copy properties to.
1629 * @returns {Object} Returns `object`.
1631 function baseCopy(source, props, object) {
1632 object || (object = {});
1635 length = props.length;
1637 while (++index < length) {
1638 var key = props[index];
1639 object[key] = source[key];
1645 * The base implementation of `_.callback` which supports specifying the
1646 * number of arguments to provide to `func`.
1649 * @param {*} [func=_.identity] The value to convert to a callback.
1650 * @param {*} [thisArg] The `this` binding of `func`.
1651 * @param {number} [argCount] The number of arguments to provide to `func`.
1652 * @returns {Function} Returns the callback.
1654 function baseCallback(func, thisArg, argCount) {
1655 var type = typeof func;
1656 if (type == 'function') {
1657 return thisArg === undefined
1659 : bindCallback(func, thisArg, argCount);
1664 if (type == 'object') {
1665 return baseMatches(func);
1667 return thisArg === undefined
1669 : baseMatchesProperty(func, thisArg);
1673 * The base implementation of `_.clone` without support for argument juggling
1674 * and `this` binding `customizer` functions.
1677 * @param {*} value The value to clone.
1678 * @param {boolean} [isDeep] Specify a deep clone.
1679 * @param {Function} [customizer] The function to customize cloning values.
1680 * @param {string} [key] The key of `value`.
1681 * @param {Object} [object] The object `value` belongs to.
1682 * @param {Array} [stackA=[]] Tracks traversed source objects.
1683 * @param {Array} [stackB=[]] Associates clones with source counterparts.
1684 * @returns {*} Returns the cloned value.
1686 function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
1689 result = object ? customizer(value, key, object) : customizer(value);
1691 if (result !== undefined) {
1694 if (!isObject(value)) {
1697 var isArr = isArray(value);
1699 result = initCloneArray(value);
1701 return arrayCopy(value, result);
1704 var tag = objToString.call(value),
1705 isFunc = tag == funcTag;
1707 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
1708 result = initCloneObject(isFunc ? {} : value);
1710 return baseAssign(result, value);
1713 return cloneableTags[tag]
1714 ? initCloneByTag(value, tag, isDeep)
1715 : (object ? value : {});
1718 // Check for circular references and return its corresponding clone.
1719 stackA || (stackA = []);
1720 stackB || (stackB = []);
1722 var length = stackA.length;
1724 if (stackA[length] == value) {
1725 return stackB[length];
1728 // Add the source value to the stack of traversed objects and associate it with its clone.
1730 stackB.push(result);
1732 // Recursively populate clone (susceptible to call stack limits).
1733 (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
1734 result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
1740 * The base implementation of `_.create` without support for assigning
1741 * properties to the created object.
1744 * @param {Object} prototype The object to inherit from.
1745 * @returns {Object} Returns the new object.
1747 var baseCreate = (function() {
1748 function object() {}
1749 return function(prototype) {
1750 if (isObject(prototype)) {
1751 object.prototype = prototype;
1752 var result = new object;
1753 object.prototype = undefined;
1755 return result || {};
1760 * The base implementation of `_.delay` and `_.defer` which accepts an index
1761 * of where to slice the arguments to provide to `func`.
1764 * @param {Function} func The function to delay.
1765 * @param {number} wait The number of milliseconds to delay invocation.
1766 * @param {Object} args The arguments provide to `func`.
1767 * @returns {number} Returns the timer id.
1769 function baseDelay(func, wait, args) {
1770 if (typeof func != 'function') {
1771 throw new TypeError(FUNC_ERROR_TEXT);
1773 return setTimeout(function() { func.apply(undefined, args); }, wait);
1777 * The base implementation of `_.difference` which accepts a single array
1778 * of values to exclude.
1781 * @param {Array} array The array to inspect.
1782 * @param {Array} values The values to exclude.
1783 * @returns {Array} Returns the new array of filtered values.
1785 function baseDifference(array, values) {
1786 var length = array ? array.length : 0,
1793 indexOf = getIndexOf(),
1794 isCommon = indexOf == baseIndexOf,
1795 cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
1796 valuesLength = values.length;
1799 indexOf = cacheIndexOf;
1804 while (++index < length) {
1805 var value = array[index];
1807 if (isCommon && value === value) {
1808 var valuesIndex = valuesLength;
1809 while (valuesIndex--) {
1810 if (values[valuesIndex] === value) {
1816 else if (indexOf(values, value, 0) < 0) {
1824 * The base implementation of `_.forEach` without support for callback
1825 * shorthands and `this` binding.
1828 * @param {Array|Object|string} collection The collection to iterate over.
1829 * @param {Function} iteratee The function invoked per iteration.
1830 * @returns {Array|Object|string} Returns `collection`.
1832 var baseEach = createBaseEach(baseForOwn);
1835 * The base implementation of `_.forEachRight` without support for callback
1836 * shorthands and `this` binding.
1839 * @param {Array|Object|string} collection The collection to iterate over.
1840 * @param {Function} iteratee The function invoked per iteration.
1841 * @returns {Array|Object|string} Returns `collection`.
1843 var baseEachRight = createBaseEach(baseForOwnRight, true);
1846 * The base implementation of `_.every` without support for callback
1847 * shorthands and `this` binding.
1850 * @param {Array|Object|string} collection The collection to iterate over.
1851 * @param {Function} predicate The function invoked per iteration.
1852 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1855 function baseEvery(collection, predicate) {
1857 baseEach(collection, function(value, index, collection) {
1858 result = !!predicate(value, index, collection);
1865 * Gets the extremum value of `collection` invoking `iteratee` for each value
1866 * in `collection` to generate the criterion by which the value is ranked.
1867 * The `iteratee` is invoked with three arguments: (value, index|key, collection).
1870 * @param {Array|Object|string} collection The collection to iterate over.
1871 * @param {Function} iteratee The function invoked per iteration.
1872 * @param {Function} comparator The function used to compare values.
1873 * @param {*} exValue The initial extremum value.
1874 * @returns {*} Returns the extremum value.
1876 function baseExtremum(collection, iteratee, comparator, exValue) {
1877 var computed = exValue,
1880 baseEach(collection, function(value, index, collection) {
1881 var current = +iteratee(value, index, collection);
1882 if (comparator(current, computed) || (current === exValue && current === result)) {
1891 * The base implementation of `_.fill` without an iteratee call guard.
1894 * @param {Array} array The array to fill.
1895 * @param {*} value The value to fill `array` with.
1896 * @param {number} [start=0] The start position.
1897 * @param {number} [end=array.length] The end position.
1898 * @returns {Array} Returns `array`.
1900 function baseFill(array, value, start, end) {
1901 var length = array.length;
1903 start = start == null ? 0 : (+start || 0);
1905 start = -start > length ? 0 : (length + start);
1907 end = (end === undefined || end > length) ? length : (+end || 0);
1911 length = start > end ? 0 : (end >>> 0);
1914 while (start < length) {
1915 array[start++] = value;
1921 * The base implementation of `_.filter` without support for callback
1922 * shorthands and `this` binding.
1925 * @param {Array|Object|string} collection The collection to iterate over.
1926 * @param {Function} predicate The function invoked per iteration.
1927 * @returns {Array} Returns the new filtered array.
1929 function baseFilter(collection, predicate) {
1931 baseEach(collection, function(value, index, collection) {
1932 if (predicate(value, index, collection)) {
1940 * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
1941 * without support for callback shorthands and `this` binding, which iterates
1942 * over `collection` using the provided `eachFunc`.
1945 * @param {Array|Object|string} collection The collection to search.
1946 * @param {Function} predicate The function invoked per iteration.
1947 * @param {Function} eachFunc The function to iterate over `collection`.
1948 * @param {boolean} [retKey] Specify returning the key of the found element
1949 * instead of the element itself.
1950 * @returns {*} Returns the found element or its key, else `undefined`.
1952 function baseFind(collection, predicate, eachFunc, retKey) {
1954 eachFunc(collection, function(value, key, collection) {
1955 if (predicate(value, key, collection)) {
1956 result = retKey ? key : value;
1964 * The base implementation of `_.flatten` with added support for restricting
1965 * flattening and specifying the start index.
1968 * @param {Array} array The array to flatten.
1969 * @param {boolean} [isDeep] Specify a deep flatten.
1970 * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
1971 * @param {Array} [result=[]] The initial result value.
1972 * @returns {Array} Returns the new flattened array.
1974 function baseFlatten(array, isDeep, isStrict, result) {
1975 result || (result = []);
1978 length = array.length;
1980 while (++index < length) {
1981 var value = array[index];
1982 if (isObjectLike(value) && isArrayLike(value) &&
1983 (isStrict || isArray(value) || isArguments(value))) {
1985 // Recursively flatten arrays (susceptible to call stack limits).
1986 baseFlatten(value, isDeep, isStrict, result);
1988 arrayPush(result, value);
1990 } else if (!isStrict) {
1991 result[result.length] = value;
1998 * The base implementation of `baseForIn` and `baseForOwn` which iterates
1999 * over `object` properties returned by `keysFunc` invoking `iteratee` for
2000 * each property. Iteratee functions may exit iteration early by explicitly
2001 * returning `false`.
2004 * @param {Object} object The object to iterate over.
2005 * @param {Function} iteratee The function invoked per iteration.
2006 * @param {Function} keysFunc The function to get the keys of `object`.
2007 * @returns {Object} Returns `object`.
2009 var baseFor = createBaseFor();
2012 * This function is like `baseFor` except that it iterates over properties
2013 * in the opposite order.
2016 * @param {Object} object The object to iterate over.
2017 * @param {Function} iteratee The function invoked per iteration.
2018 * @param {Function} keysFunc The function to get the keys of `object`.
2019 * @returns {Object} Returns `object`.
2021 var baseForRight = createBaseFor(true);
2024 * The base implementation of `_.forIn` without support for callback
2025 * shorthands and `this` binding.
2028 * @param {Object} object The object to iterate over.
2029 * @param {Function} iteratee The function invoked per iteration.
2030 * @returns {Object} Returns `object`.
2032 function baseForIn(object, iteratee) {
2033 return baseFor(object, iteratee, keysIn);
2037 * The base implementation of `_.forOwn` without support for callback
2038 * shorthands and `this` binding.
2041 * @param {Object} object The object to iterate over.
2042 * @param {Function} iteratee The function invoked per iteration.
2043 * @returns {Object} Returns `object`.
2045 function baseForOwn(object, iteratee) {
2046 return baseFor(object, iteratee, keys);
2050 * The base implementation of `_.forOwnRight` without support for callback
2051 * shorthands and `this` binding.
2054 * @param {Object} object The object to iterate over.
2055 * @param {Function} iteratee The function invoked per iteration.
2056 * @returns {Object} Returns `object`.
2058 function baseForOwnRight(object, iteratee) {
2059 return baseForRight(object, iteratee, keys);
2063 * The base implementation of `_.functions` which creates an array of
2064 * `object` function property names filtered from those provided.
2067 * @param {Object} object The object to inspect.
2068 * @param {Array} props The property names to filter.
2069 * @returns {Array} Returns the new array of filtered property names.
2071 function baseFunctions(object, props) {
2073 length = props.length,
2077 while (++index < length) {
2078 var key = props[index];
2079 if (isFunction(object[key])) {
2080 result[++resIndex] = key;
2087 * The base implementation of `get` without support for string paths
2088 * and default values.
2091 * @param {Object} object The object to query.
2092 * @param {Array} path The path of the property to get.
2093 * @param {string} [pathKey] The key representation of path.
2094 * @returns {*} Returns the resolved value.
2096 function baseGet(object, path, pathKey) {
2097 if (object == null) {
2100 if (pathKey !== undefined && pathKey in toObject(object)) {
2104 length = path.length;
2106 while (object != null && index < length) {
2107 object = object[path[index++]];
2109 return (index && index == length) ? object : undefined;
2113 * The base implementation of `_.isEqual` without support for `this` binding
2114 * `customizer` functions.
2117 * @param {*} value The value to compare.
2118 * @param {*} other The other value to compare.
2119 * @param {Function} [customizer] The function to customize comparing values.
2120 * @param {boolean} [isLoose] Specify performing partial comparisons.
2121 * @param {Array} [stackA] Tracks traversed `value` objects.
2122 * @param {Array} [stackB] Tracks traversed `other` objects.
2123 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2125 function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
2126 if (value === other) {
2129 if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
2130 return value !== value && other !== other;
2132 return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
2136 * A specialized version of `baseIsEqual` for arrays and objects which performs
2137 * deep comparisons and tracks traversed objects enabling objects with circular
2138 * references to be compared.
2141 * @param {Object} object The object to compare.
2142 * @param {Object} other The other object to compare.
2143 * @param {Function} equalFunc The function to determine equivalents of values.
2144 * @param {Function} [customizer] The function to customize comparing objects.
2145 * @param {boolean} [isLoose] Specify performing partial comparisons.
2146 * @param {Array} [stackA=[]] Tracks traversed `value` objects.
2147 * @param {Array} [stackB=[]] Tracks traversed `other` objects.
2148 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2150 function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
2151 var objIsArr = isArray(object),
2152 othIsArr = isArray(other),
2157 objTag = objToString.call(object);
2158 if (objTag == argsTag) {
2160 } else if (objTag != objectTag) {
2161 objIsArr = isTypedArray(object);
2165 othTag = objToString.call(other);
2166 if (othTag == argsTag) {
2168 } else if (othTag != objectTag) {
2169 othIsArr = isTypedArray(other);
2172 var objIsObj = objTag == objectTag,
2173 othIsObj = othTag == objectTag,
2174 isSameTag = objTag == othTag;
2176 if (isSameTag && !(objIsArr || objIsObj)) {
2177 return equalByTag(object, other, objTag);
2180 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2181 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2183 if (objIsWrapped || othIsWrapped) {
2184 return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
2190 // Assume cyclic values are equal.
2191 // For more information on detecting circular references see https://es5.github.io/#JO.
2192 stackA || (stackA = []);
2193 stackB || (stackB = []);
2195 var length = stackA.length;
2197 if (stackA[length] == object) {
2198 return stackB[length] == other;
2201 // Add `object` and `other` to the stack of traversed objects.
2202 stackA.push(object);
2205 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
2214 * The base implementation of `_.isMatch` without support for callback
2215 * shorthands and `this` binding.
2218 * @param {Object} object The object to inspect.
2219 * @param {Array} matchData The propery names, values, and compare flags to match.
2220 * @param {Function} [customizer] The function to customize comparing objects.
2221 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2223 function baseIsMatch(object, matchData, customizer) {
2224 var index = matchData.length,
2226 noCustomizer = !customizer;
2228 if (object == null) {
2231 object = toObject(object);
2233 var data = matchData[index];
2234 if ((noCustomizer && data[2])
2235 ? data[1] !== object[data[0]]
2236 : !(data[0] in object)
2241 while (++index < length) {
2242 data = matchData[index];
2244 objValue = object[key],
2247 if (noCustomizer && data[2]) {
2248 if (objValue === undefined && !(key in object)) {
2252 var result = customizer ? customizer(objValue, srcValue, key) : undefined;
2253 if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
2262 * The base implementation of `_.map` without support for callback shorthands
2263 * and `this` binding.
2266 * @param {Array|Object|string} collection The collection to iterate over.
2267 * @param {Function} iteratee The function invoked per iteration.
2268 * @returns {Array} Returns the new mapped array.
2270 function baseMap(collection, iteratee) {
2272 result = isArrayLike(collection) ? Array(collection.length) : [];
2274 baseEach(collection, function(value, key, collection) {
2275 result[++index] = iteratee(value, key, collection);
2281 * The base implementation of `_.matches` which does not clone `source`.
2284 * @param {Object} source The object of property values to match.
2285 * @returns {Function} Returns the new function.
2287 function baseMatches(source) {
2288 var matchData = getMatchData(source);
2289 if (matchData.length == 1 && matchData[0][2]) {
2290 var key = matchData[0][0],
2291 value = matchData[0][1];
2293 return function(object) {
2294 if (object == null) {
2297 return object[key] === value && (value !== undefined || (key in toObject(object)));
2300 return function(object) {
2301 return baseIsMatch(object, matchData);
2306 * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
2309 * @param {string} path The path of the property to get.
2310 * @param {*} srcValue The value to compare.
2311 * @returns {Function} Returns the new function.
2313 function baseMatchesProperty(path, srcValue) {
2314 var isArr = isArray(path),
2315 isCommon = isKey(path) && isStrictComparable(srcValue),
2316 pathKey = (path + '');
2318 path = toPath(path);
2319 return function(object) {
2320 if (object == null) {
2324 object = toObject(object);
2325 if ((isArr || !isCommon) && !(key in object)) {
2326 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
2327 if (object == null) {
2331 object = toObject(object);
2333 return object[key] === srcValue
2334 ? (srcValue !== undefined || (key in object))
2335 : baseIsEqual(srcValue, object[key], undefined, true);
2340 * The base implementation of `_.merge` without support for argument juggling,
2341 * multiple sources, and `this` binding `customizer` functions.
2344 * @param {Object} object The destination object.
2345 * @param {Object} source The source object.
2346 * @param {Function} [customizer] The function to customize merged values.
2347 * @param {Array} [stackA=[]] Tracks traversed source objects.
2348 * @param {Array} [stackB=[]] Associates values with source counterparts.
2349 * @returns {Object} Returns `object`.
2351 function baseMerge(object, source, customizer, stackA, stackB) {
2352 if (!isObject(object)) {
2355 var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
2356 props = isSrcArr ? undefined : keys(source);
2358 arrayEach(props || source, function(srcValue, key) {
2361 srcValue = source[key];
2363 if (isObjectLike(srcValue)) {
2364 stackA || (stackA = []);
2365 stackB || (stackB = []);
2366 baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
2369 var value = object[key],
2370 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2371 isCommon = result === undefined;
2376 if ((result !== undefined || (isSrcArr && !(key in object))) &&
2377 (isCommon || (result === result ? (result !== value) : (value === value)))) {
2378 object[key] = result;
2386 * A specialized version of `baseMerge` for arrays and objects which performs
2387 * deep merges and tracks traversed objects enabling objects with circular
2388 * references to be merged.
2391 * @param {Object} object The destination object.
2392 * @param {Object} source The source object.
2393 * @param {string} key The key of the value to merge.
2394 * @param {Function} mergeFunc The function to merge values.
2395 * @param {Function} [customizer] The function to customize merged values.
2396 * @param {Array} [stackA=[]] Tracks traversed source objects.
2397 * @param {Array} [stackB=[]] Associates values with source counterparts.
2398 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2400 function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
2401 var length = stackA.length,
2402 srcValue = source[key];
2405 if (stackA[length] == srcValue) {
2406 object[key] = stackB[length];
2410 var value = object[key],
2411 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2412 isCommon = result === undefined;
2416 if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
2417 result = isArray(value)
2419 : (isArrayLike(value) ? arrayCopy(value) : []);
2421 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
2422 result = isArguments(value)
2423 ? toPlainObject(value)
2424 : (isPlainObject(value) ? value : {});
2430 // Add the source value to the stack of traversed objects and associate
2431 // it with its merged value.
2432 stackA.push(srcValue);
2433 stackB.push(result);
2436 // Recursively merge objects and arrays (susceptible to call stack limits).
2437 object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
2438 } else if (result === result ? (result !== value) : (value === value)) {
2439 object[key] = result;
2444 * The base implementation of `_.property` without support for deep paths.
2447 * @param {string} key The key of the property to get.
2448 * @returns {Function} Returns the new function.
2450 function baseProperty(key) {
2451 return function(object) {
2452 return object == null ? undefined : object[key];
2457 * A specialized version of `baseProperty` which supports deep paths.
2460 * @param {Array|string} path The path of the property to get.
2461 * @returns {Function} Returns the new function.
2463 function basePropertyDeep(path) {
2464 var pathKey = (path + '');
2465 path = toPath(path);
2466 return function(object) {
2467 return baseGet(object, path, pathKey);
2472 * The base implementation of `_.pullAt` without support for individual
2473 * index arguments and capturing the removed elements.
2476 * @param {Array} array The array to modify.
2477 * @param {number[]} indexes The indexes of elements to remove.
2478 * @returns {Array} Returns `array`.
2480 function basePullAt(array, indexes) {
2481 var length = array ? indexes.length : 0;
2483 var index = indexes[length];
2484 if (index != previous && isIndex(index)) {
2485 var previous = index;
2486 splice.call(array, index, 1);
2493 * The base implementation of `_.random` without support for argument juggling
2494 * and returning floating-point numbers.
2497 * @param {number} min The minimum possible value.
2498 * @param {number} max The maximum possible value.
2499 * @returns {number} Returns the random number.
2501 function baseRandom(min, max) {
2502 return min + nativeFloor(nativeRandom() * (max - min + 1));
2506 * The base implementation of `_.reduce` and `_.reduceRight` without support
2507 * for callback shorthands and `this` binding, which iterates over `collection`
2508 * using the provided `eachFunc`.
2511 * @param {Array|Object|string} collection The collection to iterate over.
2512 * @param {Function} iteratee The function invoked per iteration.
2513 * @param {*} accumulator The initial value.
2514 * @param {boolean} initFromCollection Specify using the first or last element
2515 * of `collection` as the initial value.
2516 * @param {Function} eachFunc The function to iterate over `collection`.
2517 * @returns {*} Returns the accumulated value.
2519 function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
2520 eachFunc(collection, function(value, index, collection) {
2521 accumulator = initFromCollection
2522 ? (initFromCollection = false, value)
2523 : iteratee(accumulator, value, index, collection);
2529 * The base implementation of `setData` without support for hot loop detection.
2532 * @param {Function} func The function to associate metadata with.
2533 * @param {*} data The metadata.
2534 * @returns {Function} Returns `func`.
2536 var baseSetData = !metaMap ? identity : function(func, data) {
2537 metaMap.set(func, data);
2542 * The base implementation of `_.slice` without an iteratee call guard.
2545 * @param {Array} array The array to slice.
2546 * @param {number} [start=0] The start position.
2547 * @param {number} [end=array.length] The end position.
2548 * @returns {Array} Returns the slice of `array`.
2550 function baseSlice(array, start, end) {
2552 length = array.length;
2554 start = start == null ? 0 : (+start || 0);
2556 start = -start > length ? 0 : (length + start);
2558 end = (end === undefined || end > length) ? length : (+end || 0);
2562 length = start > end ? 0 : ((end - start) >>> 0);
2565 var result = Array(length);
2566 while (++index < length) {
2567 result[index] = array[index + start];
2573 * The base implementation of `_.some` without support for callback shorthands
2574 * and `this` binding.
2577 * @param {Array|Object|string} collection The collection to iterate over.
2578 * @param {Function} predicate The function invoked per iteration.
2579 * @returns {boolean} Returns `true` if any element passes the predicate check,
2582 function baseSome(collection, predicate) {
2585 baseEach(collection, function(value, index, collection) {
2586 result = predicate(value, index, collection);
2593 * The base implementation of `_.sortBy` which uses `comparer` to define
2594 * the sort order of `array` and replaces criteria objects with their
2595 * corresponding values.
2598 * @param {Array} array The array to sort.
2599 * @param {Function} comparer The function to define sort order.
2600 * @returns {Array} Returns `array`.
2602 function baseSortBy(array, comparer) {
2603 var length = array.length;
2605 array.sort(comparer);
2607 array[length] = array[length].value;
2613 * The base implementation of `_.sortByOrder` without param guards.
2616 * @param {Array|Object|string} collection The collection to iterate over.
2617 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
2618 * @param {boolean[]} orders The sort orders of `iteratees`.
2619 * @returns {Array} Returns the new sorted array.
2621 function baseSortByOrder(collection, iteratees, orders) {
2622 var callback = getCallback(),
2625 iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
2627 var result = baseMap(collection, function(value) {
2628 var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
2629 return { 'criteria': criteria, 'index': ++index, 'value': value };
2632 return baseSortBy(result, function(object, other) {
2633 return compareMultiple(object, other, orders);
2638 * The base implementation of `_.sum` without support for callback shorthands
2639 * and `this` binding.
2642 * @param {Array|Object|string} collection The collection to iterate over.
2643 * @param {Function} iteratee The function invoked per iteration.
2644 * @returns {number} Returns the sum.
2646 function baseSum(collection, iteratee) {
2648 baseEach(collection, function(value, index, collection) {
2649 result += +iteratee(value, index, collection) || 0;
2655 * The base implementation of `_.uniq` without support for callback shorthands
2656 * and `this` binding.
2659 * @param {Array} array The array to inspect.
2660 * @param {Function} [iteratee] The function invoked per iteration.
2661 * @returns {Array} Returns the new duplicate-value-free array.
2663 function baseUniq(array, iteratee) {
2665 indexOf = getIndexOf(),
2666 length = array.length,
2667 isCommon = indexOf == baseIndexOf,
2668 isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
2669 seen = isLarge ? createCache() : null,
2673 indexOf = cacheIndexOf;
2677 seen = iteratee ? [] : result;
2680 while (++index < length) {
2681 var value = array[index],
2682 computed = iteratee ? iteratee(value, index, array) : value;
2684 if (isCommon && value === value) {
2685 var seenIndex = seen.length;
2686 while (seenIndex--) {
2687 if (seen[seenIndex] === computed) {
2692 seen.push(computed);
2696 else if (indexOf(seen, computed, 0) < 0) {
2697 if (iteratee || isLarge) {
2698 seen.push(computed);
2707 * The base implementation of `_.values` and `_.valuesIn` which creates an
2708 * array of `object` property values corresponding to the property names
2712 * @param {Object} object The object to query.
2713 * @param {Array} props The property names to get values for.
2714 * @returns {Object} Returns the array of property values.
2716 function baseValues(object, props) {
2718 length = props.length,
2719 result = Array(length);
2721 while (++index < length) {
2722 result[index] = object[props[index]];
2728 * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
2729 * and `_.takeWhile` without support for callback shorthands and `this` binding.
2732 * @param {Array} array The array to query.
2733 * @param {Function} predicate The function invoked per iteration.
2734 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
2735 * @param {boolean} [fromRight] Specify iterating from right to left.
2736 * @returns {Array} Returns the slice of `array`.
2738 function baseWhile(array, predicate, isDrop, fromRight) {
2739 var length = array.length,
2740 index = fromRight ? length : -1;
2742 while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
2744 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
2745 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
2749 * The base implementation of `wrapperValue` which returns the result of
2750 * performing a sequence of actions on the unwrapped `value`, where each
2751 * successive action is supplied the return value of the previous.
2754 * @param {*} value The unwrapped value.
2755 * @param {Array} actions Actions to peform to resolve the unwrapped value.
2756 * @returns {*} Returns the resolved value.
2758 function baseWrapperValue(value, actions) {
2760 if (result instanceof LazyWrapper) {
2761 result = result.value();
2764 length = actions.length;
2766 while (++index < length) {
2767 var action = actions[index];
2768 result = action.func.apply(action.thisArg, arrayPush([result], action.args));
2774 * Performs a binary search of `array` to determine the index at which `value`
2775 * should be inserted into `array` in order to maintain its sort order.
2778 * @param {Array} array The sorted array to inspect.
2779 * @param {*} value The value to evaluate.
2780 * @param {boolean} [retHighest] Specify returning the highest qualified index.
2781 * @returns {number} Returns the index at which `value` should be inserted
2784 function binaryIndex(array, value, retHighest) {
2786 high = array ? array.length : low;
2788 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
2789 while (low < high) {
2790 var mid = (low + high) >>> 1,
2791 computed = array[mid];
2793 if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
2801 return binaryIndexBy(array, value, identity, retHighest);
2805 * This function is like `binaryIndex` except that it invokes `iteratee` for
2806 * `value` and each element of `array` to compute their sort ranking. The
2807 * iteratee is invoked with one argument; (value).
2810 * @param {Array} array The sorted array to inspect.
2811 * @param {*} value The value to evaluate.
2812 * @param {Function} iteratee The function invoked per iteration.
2813 * @param {boolean} [retHighest] Specify returning the highest qualified index.
2814 * @returns {number} Returns the index at which `value` should be inserted
2817 function binaryIndexBy(array, value, iteratee, retHighest) {
2818 value = iteratee(value);
2821 high = array ? array.length : 0,
2822 valIsNaN = value !== value,
2823 valIsNull = value === null,
2824 valIsUndef = value === undefined;
2826 while (low < high) {
2827 var mid = nativeFloor((low + high) / 2),
2828 computed = iteratee(array[mid]),
2829 isDef = computed !== undefined,
2830 isReflexive = computed === computed;
2833 var setLow = isReflexive || retHighest;
2834 } else if (valIsNull) {
2835 setLow = isReflexive && isDef && (retHighest || computed != null);
2836 } else if (valIsUndef) {
2837 setLow = isReflexive && (retHighest || isDef);
2838 } else if (computed == null) {
2841 setLow = retHighest ? (computed <= value) : (computed < value);
2849 return nativeMin(high, MAX_ARRAY_INDEX);
2853 * A specialized version of `baseCallback` which only supports `this` binding
2854 * and specifying the number of arguments to provide to `func`.
2857 * @param {Function} func The function to bind.
2858 * @param {*} thisArg The `this` binding of `func`.
2859 * @param {number} [argCount] The number of arguments to provide to `func`.
2860 * @returns {Function} Returns the callback.
2862 function bindCallback(func, thisArg, argCount) {
2863 if (typeof func != 'function') {
2866 if (thisArg === undefined) {
2870 case 1: return function(value) {
2871 return func.call(thisArg, value);
2873 case 3: return function(value, index, collection) {
2874 return func.call(thisArg, value, index, collection);
2876 case 4: return function(accumulator, value, index, collection) {
2877 return func.call(thisArg, accumulator, value, index, collection);
2879 case 5: return function(value, other, key, object, source) {
2880 return func.call(thisArg, value, other, key, object, source);
2884 return func.apply(thisArg, arguments);
2889 * Creates a clone of the given array buffer.
2892 * @param {ArrayBuffer} buffer The array buffer to clone.
2893 * @returns {ArrayBuffer} Returns the cloned array buffer.
2895 function bufferClone(buffer) {
2896 var result = new ArrayBuffer(buffer.byteLength),
2897 view = new Uint8Array(result);
2899 view.set(new Uint8Array(buffer));
2904 * Creates an array that is the composition of partially applied arguments,
2905 * placeholders, and provided arguments into a single array of arguments.
2908 * @param {Array|Object} args The provided arguments.
2909 * @param {Array} partials The arguments to prepend to those provided.
2910 * @param {Array} holders The `partials` placeholder indexes.
2911 * @returns {Array} Returns the new array of composed arguments.
2913 function composeArgs(args, partials, holders) {
2914 var holdersLength = holders.length,
2916 argsLength = nativeMax(args.length - holdersLength, 0),
2918 leftLength = partials.length,
2919 result = Array(leftLength + argsLength);
2921 while (++leftIndex < leftLength) {
2922 result[leftIndex] = partials[leftIndex];
2924 while (++argsIndex < holdersLength) {
2925 result[holders[argsIndex]] = args[argsIndex];
2927 while (argsLength--) {
2928 result[leftIndex++] = args[argsIndex++];
2934 * This function is like `composeArgs` except that the arguments composition
2935 * is tailored for `_.partialRight`.
2938 * @param {Array|Object} args The provided arguments.
2939 * @param {Array} partials The arguments to append to those provided.
2940 * @param {Array} holders The `partials` placeholder indexes.
2941 * @returns {Array} Returns the new array of composed arguments.
2943 function composeArgsRight(args, partials, holders) {
2944 var holdersIndex = -1,
2945 holdersLength = holders.length,
2947 argsLength = nativeMax(args.length - holdersLength, 0),
2949 rightLength = partials.length,
2950 result = Array(argsLength + rightLength);
2952 while (++argsIndex < argsLength) {
2953 result[argsIndex] = args[argsIndex];
2955 var offset = argsIndex;
2956 while (++rightIndex < rightLength) {
2957 result[offset + rightIndex] = partials[rightIndex];
2959 while (++holdersIndex < holdersLength) {
2960 result[offset + holders[holdersIndex]] = args[argsIndex++];
2966 * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
2969 * @param {Function} setter The function to set keys and values of the accumulator object.
2970 * @param {Function} [initializer] The function to initialize the accumulator object.
2971 * @returns {Function} Returns the new aggregator function.
2973 function createAggregator(setter, initializer) {
2974 return function(collection, iteratee, thisArg) {
2975 var result = initializer ? initializer() : {};
2976 iteratee = getCallback(iteratee, thisArg, 3);
2978 if (isArray(collection)) {
2980 length = collection.length;
2982 while (++index < length) {
2983 var value = collection[index];
2984 setter(result, value, iteratee(value, index, collection), collection);
2987 baseEach(collection, function(value, key, collection) {
2988 setter(result, value, iteratee(value, key, collection), collection);
2996 * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
2999 * @param {Function} assigner The function to assign values.
3000 * @returns {Function} Returns the new assigner function.
3002 function createAssigner(assigner) {
3003 return restParam(function(object, sources) {
3005 length = object == null ? 0 : sources.length,
3006 customizer = length > 2 ? sources[length - 2] : undefined,
3007 guard = length > 2 ? sources[2] : undefined,
3008 thisArg = length > 1 ? sources[length - 1] : undefined;
3010 if (typeof customizer == 'function') {
3011 customizer = bindCallback(customizer, thisArg, 5);
3014 customizer = typeof thisArg == 'function' ? thisArg : undefined;
3015 length -= (customizer ? 1 : 0);
3017 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
3018 customizer = length < 3 ? undefined : customizer;
3021 while (++index < length) {
3022 var source = sources[index];
3024 assigner(object, source, customizer);
3032 * Creates a `baseEach` or `baseEachRight` function.
3035 * @param {Function} eachFunc The function to iterate over a collection.
3036 * @param {boolean} [fromRight] Specify iterating from right to left.
3037 * @returns {Function} Returns the new base function.
3039 function createBaseEach(eachFunc, fromRight) {
3040 return function(collection, iteratee) {
3041 var length = collection ? getLength(collection) : 0;
3042 if (!isLength(length)) {
3043 return eachFunc(collection, iteratee);
3045 var index = fromRight ? length : -1,
3046 iterable = toObject(collection);
3048 while ((fromRight ? index-- : ++index < length)) {
3049 if (iteratee(iterable[index], index, iterable) === false) {
3058 * Creates a base function for `_.forIn` or `_.forInRight`.
3061 * @param {boolean} [fromRight] Specify iterating from right to left.
3062 * @returns {Function} Returns the new base function.
3064 function createBaseFor(fromRight) {
3065 return function(object, iteratee, keysFunc) {
3066 var iterable = toObject(object),
3067 props = keysFunc(object),
3068 length = props.length,
3069 index = fromRight ? length : -1;
3071 while ((fromRight ? index-- : ++index < length)) {
3072 var key = props[index];
3073 if (iteratee(iterable[key], key, iterable) === false) {
3082 * Creates a function that wraps `func` and invokes it with the `this`
3083 * binding of `thisArg`.
3086 * @param {Function} func The function to bind.
3087 * @param {*} [thisArg] The `this` binding of `func`.
3088 * @returns {Function} Returns the new bound function.
3090 function createBindWrapper(func, thisArg) {
3091 var Ctor = createCtorWrapper(func);
3093 function wrapper() {
3094 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
3095 return fn.apply(thisArg, arguments);
3101 * Creates a `Set` cache object to optimize linear searches of large arrays.
3104 * @param {Array} [values] The values to cache.
3105 * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
3107 function createCache(values) {
3108 return (nativeCreate && Set) ? new SetCache(values) : null;
3112 * Creates a function that produces compound words out of the words in a
3116 * @param {Function} callback The function to combine each word.
3117 * @returns {Function} Returns the new compounder function.
3119 function createCompounder(callback) {
3120 return function(string) {
3122 array = words(deburr(string)),
3123 length = array.length,
3126 while (++index < length) {
3127 result = callback(result, array[index], index);
3134 * Creates a function that produces an instance of `Ctor` regardless of
3135 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
3138 * @param {Function} Ctor The constructor to wrap.
3139 * @returns {Function} Returns the new wrapped function.
3141 function createCtorWrapper(Ctor) {
3143 // Use a `switch` statement to work with class constructors.
3144 // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
3145 // for more details.
3146 var args = arguments;
3147 switch (args.length) {
3148 case 0: return new Ctor;
3149 case 1: return new Ctor(args[0]);
3150 case 2: return new Ctor(args[0], args[1]);
3151 case 3: return new Ctor(args[0], args[1], args[2]);
3152 case 4: return new Ctor(args[0], args[1], args[2], args[3]);
3153 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
3154 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
3155 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
3157 var thisBinding = baseCreate(Ctor.prototype),
3158 result = Ctor.apply(thisBinding, args);
3160 // Mimic the constructor's `return` behavior.
3161 // See https://es5.github.io/#x13.2.2 for more details.
3162 return isObject(result) ? result : thisBinding;
3167 * Creates a `_.curry` or `_.curryRight` function.
3170 * @param {boolean} flag The curry bit flag.
3171 * @returns {Function} Returns the new curry function.
3173 function createCurry(flag) {
3174 function curryFunc(func, arity, guard) {
3175 if (guard && isIterateeCall(func, arity, guard)) {
3178 var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
3179 result.placeholder = curryFunc.placeholder;
3186 * Creates a `_.defaults` or `_.defaultsDeep` function.
3189 * @param {Function} assigner The function to assign values.
3190 * @param {Function} customizer The function to customize assigned values.
3191 * @returns {Function} Returns the new defaults function.
3193 function createDefaults(assigner, customizer) {
3194 return restParam(function(args) {
3195 var object = args[0];
3196 if (object == null) {
3199 args.push(customizer);
3200 return assigner.apply(undefined, args);
3205 * Creates a `_.max` or `_.min` function.
3208 * @param {Function} comparator The function used to compare values.
3209 * @param {*} exValue The initial extremum value.
3210 * @returns {Function} Returns the new extremum function.
3212 function createExtremum(comparator, exValue) {
3213 return function(collection, iteratee, thisArg) {
3214 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
3215 iteratee = undefined;
3217 iteratee = getCallback(iteratee, thisArg, 3);
3218 if (iteratee.length == 1) {
3219 collection = isArray(collection) ? collection : toIterable(collection);
3220 var result = arrayExtremum(collection, iteratee, comparator, exValue);
3221 if (!(collection.length && result === exValue)) {
3225 return baseExtremum(collection, iteratee, comparator, exValue);
3230 * Creates a `_.find` or `_.findLast` function.
3233 * @param {Function} eachFunc The function to iterate over a collection.
3234 * @param {boolean} [fromRight] Specify iterating from right to left.
3235 * @returns {Function} Returns the new find function.
3237 function createFind(eachFunc, fromRight) {
3238 return function(collection, predicate, thisArg) {
3239 predicate = getCallback(predicate, thisArg, 3);
3240 if (isArray(collection)) {
3241 var index = baseFindIndex(collection, predicate, fromRight);
3242 return index > -1 ? collection[index] : undefined;
3244 return baseFind(collection, predicate, eachFunc);
3249 * Creates a `_.findIndex` or `_.findLastIndex` function.
3252 * @param {boolean} [fromRight] Specify iterating from right to left.
3253 * @returns {Function} Returns the new find function.
3255 function createFindIndex(fromRight) {
3256 return function(array, predicate, thisArg) {
3257 if (!(array && array.length)) {
3260 predicate = getCallback(predicate, thisArg, 3);
3261 return baseFindIndex(array, predicate, fromRight);
3266 * Creates a `_.findKey` or `_.findLastKey` function.
3269 * @param {Function} objectFunc The function to iterate over an object.
3270 * @returns {Function} Returns the new find function.
3272 function createFindKey(objectFunc) {
3273 return function(object, predicate, thisArg) {
3274 predicate = getCallback(predicate, thisArg, 3);
3275 return baseFind(object, predicate, objectFunc, true);
3280 * Creates a `_.flow` or `_.flowRight` function.
3283 * @param {boolean} [fromRight] Specify iterating from right to left.
3284 * @returns {Function} Returns the new flow function.
3286 function createFlow(fromRight) {
3289 length = arguments.length,
3290 index = fromRight ? length : -1,
3292 funcs = Array(length);
3294 while ((fromRight ? index-- : ++index < length)) {
3295 var func = funcs[leftIndex++] = arguments[index];
3296 if (typeof func != 'function') {
3297 throw new TypeError(FUNC_ERROR_TEXT);
3299 if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
3300 wrapper = new LodashWrapper([], true);
3303 index = wrapper ? -1 : length;
3304 while (++index < length) {
3305 func = funcs[index];
3307 var funcName = getFuncName(func),
3308 data = funcName == 'wrapper' ? getData(func) : undefined;
3310 if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
3311 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
3313 wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
3317 var args = arguments,
3320 if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
3321 return wrapper.plant(value).value();
3324 result = length ? funcs[index].apply(this, args) : value;
3326 while (++index < length) {
3327 result = funcs[index].call(this, result);
3335 * Creates a function for `_.forEach` or `_.forEachRight`.
3338 * @param {Function} arrayFunc The function to iterate over an array.
3339 * @param {Function} eachFunc The function to iterate over a collection.
3340 * @returns {Function} Returns the new each function.
3342 function createForEach(arrayFunc, eachFunc) {
3343 return function(collection, iteratee, thisArg) {
3344 return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
3345 ? arrayFunc(collection, iteratee)
3346 : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
3351 * Creates a function for `_.forIn` or `_.forInRight`.
3354 * @param {Function} objectFunc The function to iterate over an object.
3355 * @returns {Function} Returns the new each function.
3357 function createForIn(objectFunc) {
3358 return function(object, iteratee, thisArg) {
3359 if (typeof iteratee != 'function' || thisArg !== undefined) {
3360 iteratee = bindCallback(iteratee, thisArg, 3);
3362 return objectFunc(object, iteratee, keysIn);
3367 * Creates a function for `_.forOwn` or `_.forOwnRight`.
3370 * @param {Function} objectFunc The function to iterate over an object.
3371 * @returns {Function} Returns the new each function.
3373 function createForOwn(objectFunc) {
3374 return function(object, iteratee, thisArg) {
3375 if (typeof iteratee != 'function' || thisArg !== undefined) {
3376 iteratee = bindCallback(iteratee, thisArg, 3);
3378 return objectFunc(object, iteratee);
3383 * Creates a function for `_.mapKeys` or `_.mapValues`.
3386 * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
3387 * @returns {Function} Returns the new map function.
3389 function createObjectMapper(isMapKeys) {
3390 return function(object, iteratee, thisArg) {
3392 iteratee = getCallback(iteratee, thisArg, 3);
3394 baseForOwn(object, function(value, key, object) {
3395 var mapped = iteratee(value, key, object);
3396 key = isMapKeys ? mapped : key;
3397 value = isMapKeys ? value : mapped;
3398 result[key] = value;
3405 * Creates a function for `_.padLeft` or `_.padRight`.
3408 * @param {boolean} [fromRight] Specify padding from the right.
3409 * @returns {Function} Returns the new pad function.
3411 function createPadDir(fromRight) {
3412 return function(string, length, chars) {
3413 string = baseToString(string);
3414 return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
3419 * Creates a `_.partial` or `_.partialRight` function.
3422 * @param {boolean} flag The partial bit flag.
3423 * @returns {Function} Returns the new partial function.
3425 function createPartial(flag) {
3426 var partialFunc = restParam(function(func, partials) {
3427 var holders = replaceHolders(partials, partialFunc.placeholder);
3428 return createWrapper(func, flag, undefined, partials, holders);
3434 * Creates a function for `_.reduce` or `_.reduceRight`.
3437 * @param {Function} arrayFunc The function to iterate over an array.
3438 * @param {Function} eachFunc The function to iterate over a collection.
3439 * @returns {Function} Returns the new each function.
3441 function createReduce(arrayFunc, eachFunc) {
3442 return function(collection, iteratee, accumulator, thisArg) {
3443 var initFromArray = arguments.length < 3;
3444 return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
3445 ? arrayFunc(collection, iteratee, accumulator, initFromArray)
3446 : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
3451 * Creates a function that wraps `func` and invokes it with optional `this`
3452 * binding of, partial application, and currying.
3455 * @param {Function|string} func The function or method name to reference.
3456 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3457 * @param {*} [thisArg] The `this` binding of `func`.
3458 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
3459 * @param {Array} [holders] The `partials` placeholder indexes.
3460 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
3461 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
3462 * @param {Array} [argPos] The argument positions of the new function.
3463 * @param {number} [ary] The arity cap of `func`.
3464 * @param {number} [arity] The arity of `func`.
3465 * @returns {Function} Returns the new wrapped function.
3467 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
3468 var isAry = bitmask & ARY_FLAG,
3469 isBind = bitmask & BIND_FLAG,
3470 isBindKey = bitmask & BIND_KEY_FLAG,
3471 isCurry = bitmask & CURRY_FLAG,
3472 isCurryBound = bitmask & CURRY_BOUND_FLAG,
3473 isCurryRight = bitmask & CURRY_RIGHT_FLAG,
3474 Ctor = isBindKey ? undefined : createCtorWrapper(func);
3476 function wrapper() {
3477 // Avoid `arguments` object use disqualifying optimizations by
3478 // converting it to an array before providing it to other functions.
3479 var length = arguments.length,
3481 args = Array(length);
3484 args[index] = arguments[index];
3487 args = composeArgs(args, partials, holders);
3489 if (partialsRight) {
3490 args = composeArgsRight(args, partialsRight, holdersRight);
3492 if (isCurry || isCurryRight) {
3493 var placeholder = wrapper.placeholder,
3494 argsHolders = replaceHolders(args, placeholder);
3496 length -= argsHolders.length;
3497 if (length < arity) {
3498 var newArgPos = argPos ? arrayCopy(argPos) : undefined,
3499 newArity = nativeMax(arity - length, 0),
3500 newsHolders = isCurry ? argsHolders : undefined,
3501 newHoldersRight = isCurry ? undefined : argsHolders,
3502 newPartials = isCurry ? args : undefined,
3503 newPartialsRight = isCurry ? undefined : args;
3505 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
3506 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
3508 if (!isCurryBound) {
3509 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
3511 var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
3512 result = createHybridWrapper.apply(undefined, newData);
3514 if (isLaziable(func)) {
3515 setData(result, newData);
3517 result.placeholder = placeholder;
3521 var thisBinding = isBind ? thisArg : this,
3522 fn = isBindKey ? thisBinding[func] : func;
3525 args = reorder(args, argPos);
3527 if (isAry && ary < args.length) {
3530 if (this && this !== root && this instanceof wrapper) {
3531 fn = Ctor || createCtorWrapper(func);
3533 return fn.apply(thisBinding, args);
3539 * Creates the padding required for `string` based on the given `length`.
3540 * The `chars` string is truncated if the number of characters exceeds `length`.
3543 * @param {string} string The string to create padding for.
3544 * @param {number} [length=0] The padding length.
3545 * @param {string} [chars=' '] The string used as padding.
3546 * @returns {string} Returns the pad for `string`.
3548 function createPadding(string, length, chars) {
3549 var strLength = string.length;
3552 if (strLength >= length || !nativeIsFinite(length)) {
3555 var padLength = length - strLength;
3556 chars = chars == null ? ' ' : (chars + '');
3557 return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
3561 * Creates a function that wraps `func` and invokes it with the optional `this`
3562 * binding of `thisArg` and the `partials` prepended to those provided to
3566 * @param {Function} func The function to partially apply arguments to.
3567 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3568 * @param {*} thisArg The `this` binding of `func`.
3569 * @param {Array} partials The arguments to prepend to those provided to the new function.
3570 * @returns {Function} Returns the new bound function.
3572 function createPartialWrapper(func, bitmask, thisArg, partials) {
3573 var isBind = bitmask & BIND_FLAG,
3574 Ctor = createCtorWrapper(func);
3576 function wrapper() {
3577 // Avoid `arguments` object use disqualifying optimizations by
3578 // converting it to an array before providing it `func`.
3580 argsLength = arguments.length,
3582 leftLength = partials.length,
3583 args = Array(leftLength + argsLength);
3585 while (++leftIndex < leftLength) {
3586 args[leftIndex] = partials[leftIndex];
3588 while (argsLength--) {
3589 args[leftIndex++] = arguments[++argsIndex];
3591 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
3592 return fn.apply(isBind ? thisArg : this, args);
3598 * Creates a `_.ceil`, `_.floor`, or `_.round` function.
3601 * @param {string} methodName The name of the `Math` method to use when rounding.
3602 * @returns {Function} Returns the new round function.
3604 function createRound(methodName) {
3605 var func = Math[methodName];
3606 return function(number, precision) {
3607 precision = precision === undefined ? 0 : (+precision || 0);
3609 precision = pow(10, precision);
3610 return func(number * precision) / precision;
3612 return func(number);
3617 * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
3620 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3621 * @returns {Function} Returns the new index function.
3623 function createSortedIndex(retHighest) {
3624 return function(array, value, iteratee, thisArg) {
3625 var callback = getCallback(iteratee);
3626 return (iteratee == null && callback === baseCallback)
3627 ? binaryIndex(array, value, retHighest)
3628 : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
3633 * Creates a function that either curries or invokes `func` with optional
3634 * `this` binding and partially applied arguments.
3637 * @param {Function|string} func The function or method name to reference.
3638 * @param {number} bitmask The bitmask of flags.
3639 * The bitmask may be composed of the following flags:
3642 * 4 - `_.curry` or `_.curryRight` of a bound function
3644 * 16 - `_.curryRight`
3646 * 64 - `_.partialRight`
3649 * @param {*} [thisArg] The `this` binding of `func`.
3650 * @param {Array} [partials] The arguments to be partially applied.
3651 * @param {Array} [holders] The `partials` placeholder indexes.
3652 * @param {Array} [argPos] The argument positions of the new function.
3653 * @param {number} [ary] The arity cap of `func`.
3654 * @param {number} [arity] The arity of `func`.
3655 * @returns {Function} Returns the new wrapped function.
3657 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
3658 var isBindKey = bitmask & BIND_KEY_FLAG;
3659 if (!isBindKey && typeof func != 'function') {
3660 throw new TypeError(FUNC_ERROR_TEXT);
3662 var length = partials ? partials.length : 0;
3664 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
3665 partials = holders = undefined;
3667 length -= (holders ? holders.length : 0);
3668 if (bitmask & PARTIAL_RIGHT_FLAG) {
3669 var partialsRight = partials,
3670 holdersRight = holders;
3672 partials = holders = undefined;
3674 var data = isBindKey ? undefined : getData(func),
3675 newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
3678 mergeData(newData, data);
3679 bitmask = newData[1];
3682 newData[9] = arity == null
3683 ? (isBindKey ? 0 : func.length)
3684 : (nativeMax(arity - length, 0) || 0);
3686 if (bitmask == BIND_FLAG) {
3687 var result = createBindWrapper(newData[0], newData[2]);
3688 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
3689 result = createPartialWrapper.apply(undefined, newData);
3691 result = createHybridWrapper.apply(undefined, newData);
3693 var setter = data ? baseSetData : setData;
3694 return setter(result, newData);
3698 * A specialized version of `baseIsEqualDeep` for arrays with support for
3699 * partial deep comparisons.
3702 * @param {Array} array The array to compare.
3703 * @param {Array} other The other array to compare.
3704 * @param {Function} equalFunc The function to determine equivalents of values.
3705 * @param {Function} [customizer] The function to customize comparing arrays.
3706 * @param {boolean} [isLoose] Specify performing partial comparisons.
3707 * @param {Array} [stackA] Tracks traversed `value` objects.
3708 * @param {Array} [stackB] Tracks traversed `other` objects.
3709 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
3711 function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
3713 arrLength = array.length,
3714 othLength = other.length;
3716 if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
3719 // Ignore non-index properties.
3720 while (++index < arrLength) {
3721 var arrValue = array[index],
3722 othValue = other[index],
3723 result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
3725 if (result !== undefined) {
3731 // Recursively compare arrays (susceptible to call stack limits).
3733 if (!arraySome(other, function(othValue) {
3734 return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
3738 } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
3746 * A specialized version of `baseIsEqualDeep` for comparing objects of
3747 * the same `toStringTag`.
3749 * **Note:** This function only supports comparing values with tags of
3750 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
3753 * @param {Object} object The object to compare.
3754 * @param {Object} other The other object to compare.
3755 * @param {string} tag The `toStringTag` of the objects to compare.
3756 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3758 function equalByTag(object, other, tag) {
3762 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
3763 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
3764 return +object == +other;
3767 return object.name == other.name && object.message == other.message;
3770 // Treat `NaN` vs. `NaN` as equal.
3771 return (object != +object)
3777 // Coerce regexes to strings and treat strings primitives and string
3778 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
3779 return object == (other + '');
3785 * A specialized version of `baseIsEqualDeep` for objects with support for
3786 * partial deep comparisons.
3789 * @param {Object} object The object to compare.
3790 * @param {Object} other The other object to compare.
3791 * @param {Function} equalFunc The function to determine equivalents of values.
3792 * @param {Function} [customizer] The function to customize comparing values.
3793 * @param {boolean} [isLoose] Specify performing partial comparisons.
3794 * @param {Array} [stackA] Tracks traversed `value` objects.
3795 * @param {Array} [stackB] Tracks traversed `other` objects.
3796 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
3798 function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
3799 var objProps = keys(object),
3800 objLength = objProps.length,
3801 othProps = keys(other),
3802 othLength = othProps.length;
3804 if (objLength != othLength && !isLoose) {
3807 var index = objLength;
3809 var key = objProps[index];
3810 if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
3814 var skipCtor = isLoose;
3815 while (++index < objLength) {
3816 key = objProps[index];
3817 var objValue = object[key],
3818 othValue = other[key],
3819 result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
3821 // Recursively compare objects (susceptible to call stack limits).
3822 if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
3825 skipCtor || (skipCtor = key == 'constructor');
3828 var objCtor = object.constructor,
3829 othCtor = other.constructor;
3831 // Non `Object` object instances with different constructors are not equal.
3832 if (objCtor != othCtor &&
3833 ('constructor' in object && 'constructor' in other) &&
3834 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
3835 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
3843 * Gets the appropriate "callback" function. If the `_.callback` method is
3844 * customized this function returns the custom method, otherwise it returns
3845 * the `baseCallback` function. If arguments are provided the chosen function
3846 * is invoked with them and its result is returned.
3849 * @returns {Function} Returns the chosen function or its result.
3851 function getCallback(func, thisArg, argCount) {
3852 var result = lodash.callback || callback;
3853 result = result === callback ? baseCallback : result;
3854 return argCount ? result(func, thisArg, argCount) : result;
3858 * Gets metadata for `func`.
3861 * @param {Function} func The function to query.
3862 * @returns {*} Returns the metadata for `func`.
3864 var getData = !metaMap ? noop : function(func) {
3865 return metaMap.get(func);
3869 * Gets the name of `func`.
3872 * @param {Function} func The function to query.
3873 * @returns {string} Returns the function name.
3875 function getFuncName(func) {
3876 var result = func.name,
3877 array = realNames[result],
3878 length = array ? array.length : 0;
3881 var data = array[length],
3882 otherFunc = data.func;
3883 if (otherFunc == null || otherFunc == func) {
3891 * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
3892 * customized this function returns the custom method, otherwise it returns
3893 * the `baseIndexOf` function. If arguments are provided the chosen function
3894 * is invoked with them and its result is returned.
3897 * @returns {Function|number} Returns the chosen function or its result.
3899 function getIndexOf(collection, target, fromIndex) {
3900 var result = lodash.indexOf || indexOf;
3901 result = result === indexOf ? baseIndexOf : result;
3902 return collection ? result(collection, target, fromIndex) : result;
3906 * Gets the "length" property value of `object`.
3908 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
3909 * that affects Safari on at least iOS 8.1-8.3 ARM64.
3912 * @param {Object} object The object to query.
3913 * @returns {*} Returns the "length" value.
3915 var getLength = baseProperty('length');
3918 * Gets the propery names, values, and compare flags of `object`.
3921 * @param {Object} object The object to query.
3922 * @returns {Array} Returns the match data of `object`.
3924 function getMatchData(object) {
3925 var result = pairs(object),
3926 length = result.length;
3929 result[length][2] = isStrictComparable(result[length][1]);
3935 * Gets the native function at `key` of `object`.
3938 * @param {Object} object The object to query.
3939 * @param {string} key The key of the method to get.
3940 * @returns {*} Returns the function if it's native, else `undefined`.
3942 function getNative(object, key) {
3943 var value = object == null ? undefined : object[key];
3944 return isNative(value) ? value : undefined;
3948 * Gets the view, applying any `transforms` to the `start` and `end` positions.
3951 * @param {number} start The start of the view.
3952 * @param {number} end The end of the view.
3953 * @param {Array} transforms The transformations to apply to the view.
3954 * @returns {Object} Returns an object containing the `start` and `end`
3955 * positions of the view.
3957 function getView(start, end, transforms) {
3959 length = transforms.length;
3961 while (++index < length) {
3962 var data = transforms[index],
3965 switch (data.type) {
3966 case 'drop': start += size; break;
3967 case 'dropRight': end -= size; break;
3968 case 'take': end = nativeMin(end, start + size); break;
3969 case 'takeRight': start = nativeMax(start, end - size); break;
3972 return { 'start': start, 'end': end };
3976 * Initializes an array clone.
3979 * @param {Array} array The array to clone.
3980 * @returns {Array} Returns the initialized clone.
3982 function initCloneArray(array) {
3983 var length = array.length,
3984 result = new array.constructor(length);
3986 // Add array properties assigned by `RegExp#exec`.
3987 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
3988 result.index = array.index;
3989 result.input = array.input;
3995 * Initializes an object clone.
3998 * @param {Object} object The object to clone.
3999 * @returns {Object} Returns the initialized clone.
4001 function initCloneObject(object) {
4002 var Ctor = object.constructor;
4003 if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
4010 * Initializes an object clone based on its `toStringTag`.
4012 * **Note:** This function only supports cloning values with tags of
4013 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4016 * @param {Object} object The object to clone.
4017 * @param {string} tag The `toStringTag` of the object to clone.
4018 * @param {boolean} [isDeep] Specify a deep clone.
4019 * @returns {Object} Returns the initialized clone.
4021 function initCloneByTag(object, tag, isDeep) {
4022 var Ctor = object.constructor;
4024 case arrayBufferTag:
4025 return bufferClone(object);
4029 return new Ctor(+object);
4031 case float32Tag: case float64Tag:
4032 case int8Tag: case int16Tag: case int32Tag:
4033 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
4034 var buffer = object.buffer;
4035 return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
4039 return new Ctor(object);
4042 var result = new Ctor(object.source, reFlags.exec(object));
4043 result.lastIndex = object.lastIndex;
4049 * Invokes the method at `path` on `object`.
4052 * @param {Object} object The object to query.
4053 * @param {Array|string} path The path of the method to invoke.
4054 * @param {Array} args The arguments to invoke the method with.
4055 * @returns {*} Returns the result of the invoked method.
4057 function invokePath(object, path, args) {
4058 if (object != null && !isKey(path, object)) {
4059 path = toPath(path);
4060 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
4063 var func = object == null ? object : object[path];
4064 return func == null ? undefined : func.apply(object, args);
4068 * Checks if `value` is array-like.
4071 * @param {*} value The value to check.
4072 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
4074 function isArrayLike(value) {
4075 return value != null && isLength(getLength(value));
4079 * Checks if `value` is a valid array-like index.
4082 * @param {*} value The value to check.
4083 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
4084 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
4086 function isIndex(value, length) {
4087 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
4088 length = length == null ? MAX_SAFE_INTEGER : length;
4089 return value > -1 && value % 1 == 0 && value < length;
4093 * Checks if the provided arguments are from an iteratee call.
4096 * @param {*} value The potential iteratee value argument.
4097 * @param {*} index The potential iteratee index or key argument.
4098 * @param {*} object The potential iteratee object argument.
4099 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
4101 function isIterateeCall(value, index, object) {
4102 if (!isObject(object)) {
4105 var type = typeof index;
4106 if (type == 'number'
4107 ? (isArrayLike(object) && isIndex(index, object.length))
4108 : (type == 'string' && index in object)) {
4109 var other = object[index];
4110 return value === value ? (value === other) : (other !== other);
4116 * Checks if `value` is a property name and not a property path.
4119 * @param {*} value The value to check.
4120 * @param {Object} [object] The object to query keys on.
4121 * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
4123 function isKey(value, object) {
4124 var type = typeof value;
4125 if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
4128 if (isArray(value)) {
4131 var result = !reIsDeepProp.test(value);
4132 return result || (object != null && value in toObject(object));
4136 * Checks if `func` has a lazy counterpart.
4139 * @param {Function} func The function to check.
4140 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
4142 function isLaziable(func) {
4143 var funcName = getFuncName(func);
4144 if (!(funcName in LazyWrapper.prototype)) {
4147 var other = lodash[funcName];
4148 if (func === other) {
4151 var data = getData(other);
4152 return !!data && func === data[0];
4156 * Checks if `value` is a valid array-like length.
4158 * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
4161 * @param {*} value The value to check.
4162 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
4164 function isLength(value) {
4165 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
4169 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
4172 * @param {*} value The value to check.
4173 * @returns {boolean} Returns `true` if `value` if suitable for strict
4174 * equality comparisons, else `false`.
4176 function isStrictComparable(value) {
4177 return value === value && !isObject(value);
4181 * Merges the function metadata of `source` into `data`.
4183 * Merging metadata reduces the number of wrappers required to invoke a function.
4184 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
4185 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
4186 * augment function arguments, making the order in which they are executed important,
4187 * preventing the merging of metadata. However, we make an exception for a safe
4188 * common case where curried functions have `_.ary` and or `_.rearg` applied.
4191 * @param {Array} data The destination metadata.
4192 * @param {Array} source The source metadata.
4193 * @returns {Array} Returns `data`.
4195 function mergeData(data, source) {
4196 var bitmask = data[1],
4197 srcBitmask = source[1],
4198 newBitmask = bitmask | srcBitmask,
4199 isCommon = newBitmask < ARY_FLAG;
4202 (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
4203 (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
4204 (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
4206 // Exit early if metadata can't be merged.
4207 if (!(isCommon || isCombo)) {
4210 // Use source `thisArg` if available.
4211 if (srcBitmask & BIND_FLAG) {
4212 data[2] = source[2];
4213 // Set when currying a bound function.
4214 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
4216 // Compose partial arguments.
4217 var value = source[3];
4219 var partials = data[3];
4220 data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
4221 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
4223 // Compose partial right arguments.
4227 data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
4228 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
4230 // Use source `argPos` if available.
4233 data[7] = arrayCopy(value);
4235 // Use source `ary` if it's smaller.
4236 if (srcBitmask & ARY_FLAG) {
4237 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
4239 // Use source `arity` if one is not provided.
4240 if (data[9] == null) {
4241 data[9] = source[9];
4243 // Use source `func` and merge bitmasks.
4244 data[0] = source[0];
4245 data[1] = newBitmask;
4251 * Used by `_.defaultsDeep` to customize its `_.merge` use.
4254 * @param {*} objectValue The destination object property value.
4255 * @param {*} sourceValue The source object property value.
4256 * @returns {*} Returns the value to assign to the destination object.
4258 function mergeDefaults(objectValue, sourceValue) {
4259 return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
4263 * A specialized version of `_.pick` which picks `object` properties specified
4267 * @param {Object} object The source object.
4268 * @param {string[]} props The property names to pick.
4269 * @returns {Object} Returns the new object.
4271 function pickByArray(object, props) {
4272 object = toObject(object);
4275 length = props.length,
4278 while (++index < length) {
4279 var key = props[index];
4280 if (key in object) {
4281 result[key] = object[key];
4288 * A specialized version of `_.pick` which picks `object` properties `predicate`
4289 * returns truthy for.
4292 * @param {Object} object The source object.
4293 * @param {Function} predicate The function invoked per iteration.
4294 * @returns {Object} Returns the new object.
4296 function pickByCallback(object, predicate) {
4298 baseForIn(object, function(value, key, object) {
4299 if (predicate(value, key, object)) {
4300 result[key] = value;
4307 * Reorder `array` according to the specified indexes where the element at
4308 * the first index is assigned as the first element, the element at
4309 * the second index is assigned as the second element, and so on.
4312 * @param {Array} array The array to reorder.
4313 * @param {Array} indexes The arranged array indexes.
4314 * @returns {Array} Returns `array`.
4316 function reorder(array, indexes) {
4317 var arrLength = array.length,
4318 length = nativeMin(indexes.length, arrLength),
4319 oldArray = arrayCopy(array);
4322 var index = indexes[length];
4323 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
4329 * Sets metadata for `func`.
4331 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
4332 * period of time, it will trip its breaker and transition to an identity function
4333 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
4337 * @param {Function} func The function to associate metadata with.
4338 * @param {*} data The metadata.
4339 * @returns {Function} Returns `func`.
4341 var setData = (function() {
4345 return function(key, value) {
4347 remaining = HOT_SPAN - (stamp - lastCalled);
4350 if (remaining > 0) {
4351 if (++count >= HOT_COUNT) {
4357 return baseSetData(key, value);
4362 * A fallback implementation of `Object.keys` which creates an array of the
4363 * own enumerable property names of `object`.
4366 * @param {Object} object The object to query.
4367 * @returns {Array} Returns the array of property names.
4369 function shimKeys(object) {
4370 var props = keysIn(object),
4371 propsLength = props.length,
4372 length = propsLength && object.length;
4374 var allowIndexes = !!length && isLength(length) &&
4375 (isArray(object) || isArguments(object));
4380 while (++index < propsLength) {
4381 var key = props[index];
4382 if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
4390 * Converts `value` to an array-like object if it's not one.
4393 * @param {*} value The value to process.
4394 * @returns {Array|Object} Returns the array-like object.
4396 function toIterable(value) {
4397 if (value == null) {
4400 if (!isArrayLike(value)) {
4401 return values(value);
4403 return isObject(value) ? value : Object(value);
4407 * Converts `value` to an object if it's not one.
4410 * @param {*} value The value to process.
4411 * @returns {Object} Returns the object.
4413 function toObject(value) {
4414 return isObject(value) ? value : Object(value);
4418 * Converts `value` to property path array if it's not one.
4421 * @param {*} value The value to process.
4422 * @returns {Array} Returns the property path array.
4424 function toPath(value) {
4425 if (isArray(value)) {
4429 baseToString(value).replace(rePropName, function(match, number, quote, string) {
4430 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
4436 * Creates a clone of `wrapper`.
4439 * @param {Object} wrapper The wrapper to clone.
4440 * @returns {Object} Returns the cloned wrapper.
4442 function wrapperClone(wrapper) {
4443 return wrapper instanceof LazyWrapper
4445 : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
4448 /*------------------------------------------------------------------------*/
4451 * Creates an array of elements split into groups the length of `size`.
4452 * If `collection` can't be split evenly, the final chunk will be the remaining
4458 * @param {Array} array The array to process.
4459 * @param {number} [size=1] The length of each chunk.
4460 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4461 * @returns {Array} Returns the new array containing chunks.
4464 * _.chunk(['a', 'b', 'c', 'd'], 2);
4465 * // => [['a', 'b'], ['c', 'd']]
4467 * _.chunk(['a', 'b', 'c', 'd'], 3);
4468 * // => [['a', 'b', 'c'], ['d']]
4470 function chunk(array, size, guard) {
4471 if (guard ? isIterateeCall(array, size, guard) : size == null) {
4474 size = nativeMax(nativeFloor(size) || 1, 1);
4477 length = array ? array.length : 0,
4479 result = Array(nativeCeil(length / size));
4481 while (index < length) {
4482 result[++resIndex] = baseSlice(array, index, (index += size));
4488 * Creates an array with all falsey values removed. The values `false`, `null`,
4489 * `0`, `""`, `undefined`, and `NaN` are falsey.
4494 * @param {Array} array The array to compact.
4495 * @returns {Array} Returns the new array of filtered values.
4498 * _.compact([0, 1, false, 2, '', 3]);
4501 function compact(array) {
4503 length = array ? array.length : 0,
4507 while (++index < length) {
4508 var value = array[index];
4510 result[++resIndex] = value;
4517 * Creates an array of unique `array` values not included in the other
4518 * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4519 * for equality comparisons.
4524 * @param {Array} array The array to inspect.
4525 * @param {...Array} [values] The arrays of values to exclude.
4526 * @returns {Array} Returns the new array of filtered values.
4529 * _.difference([1, 2, 3], [4, 2]);
4532 var difference = restParam(function(array, values) {
4533 return (isObjectLike(array) && isArrayLike(array))
4534 ? baseDifference(array, baseFlatten(values, false, true))
4539 * Creates a slice of `array` with `n` elements dropped from the beginning.
4544 * @param {Array} array The array to query.
4545 * @param {number} [n=1] The number of elements to drop.
4546 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4547 * @returns {Array} Returns the slice of `array`.
4550 * _.drop([1, 2, 3]);
4553 * _.drop([1, 2, 3], 2);
4556 * _.drop([1, 2, 3], 5);
4559 * _.drop([1, 2, 3], 0);
4562 function drop(array, n, guard) {
4563 var length = array ? array.length : 0;
4567 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4570 return baseSlice(array, n < 0 ? 0 : n);
4574 * Creates a slice of `array` with `n` elements dropped from the end.
4579 * @param {Array} array The array to query.
4580 * @param {number} [n=1] The number of elements to drop.
4581 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4582 * @returns {Array} Returns the slice of `array`.
4585 * _.dropRight([1, 2, 3]);
4588 * _.dropRight([1, 2, 3], 2);
4591 * _.dropRight([1, 2, 3], 5);
4594 * _.dropRight([1, 2, 3], 0);
4597 function dropRight(array, n, guard) {
4598 var length = array ? array.length : 0;
4602 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4605 n = length - (+n || 0);
4606 return baseSlice(array, 0, n < 0 ? 0 : n);
4610 * Creates a slice of `array` excluding elements dropped from the end.
4611 * Elements are dropped until `predicate` returns falsey. The predicate is
4612 * bound to `thisArg` and invoked with three arguments: (value, index, array).
4614 * If a property name is provided for `predicate` the created `_.property`
4615 * style callback returns the property value of the given element.
4617 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4618 * style callback returns `true` for elements that have a matching property
4619 * value, else `false`.
4621 * If an object is provided for `predicate` the created `_.matches` style
4622 * callback returns `true` for elements that match the properties of the given
4623 * object, else `false`.
4628 * @param {Array} array The array to query.
4629 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4631 * @param {*} [thisArg] The `this` binding of `predicate`.
4632 * @returns {Array} Returns the slice of `array`.
4635 * _.dropRightWhile([1, 2, 3], function(n) {
4641 * { 'user': 'barney', 'active': true },
4642 * { 'user': 'fred', 'active': false },
4643 * { 'user': 'pebbles', 'active': false }
4646 * // using the `_.matches` callback shorthand
4647 * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
4648 * // => ['barney', 'fred']
4650 * // using the `_.matchesProperty` callback shorthand
4651 * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
4654 * // using the `_.property` callback shorthand
4655 * _.pluck(_.dropRightWhile(users, 'active'), 'user');
4656 * // => ['barney', 'fred', 'pebbles']
4658 function dropRightWhile(array, predicate, thisArg) {
4659 return (array && array.length)
4660 ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
4665 * Creates a slice of `array` excluding elements dropped from the beginning.
4666 * Elements are dropped until `predicate` returns falsey. The predicate is
4667 * bound to `thisArg` and invoked with three arguments: (value, index, array).
4669 * If a property name is provided for `predicate` the created `_.property`
4670 * style callback returns the property value of the given element.
4672 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4673 * style callback returns `true` for elements that have a matching property
4674 * value, else `false`.
4676 * If an object is provided for `predicate` the created `_.matches` style
4677 * callback returns `true` for elements that have the properties of the given
4678 * object, else `false`.
4683 * @param {Array} array The array to query.
4684 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4686 * @param {*} [thisArg] The `this` binding of `predicate`.
4687 * @returns {Array} Returns the slice of `array`.
4690 * _.dropWhile([1, 2, 3], function(n) {
4696 * { 'user': 'barney', 'active': false },
4697 * { 'user': 'fred', 'active': false },
4698 * { 'user': 'pebbles', 'active': true }
4701 * // using the `_.matches` callback shorthand
4702 * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
4703 * // => ['fred', 'pebbles']
4705 * // using the `_.matchesProperty` callback shorthand
4706 * _.pluck(_.dropWhile(users, 'active', false), 'user');
4709 * // using the `_.property` callback shorthand
4710 * _.pluck(_.dropWhile(users, 'active'), 'user');
4711 * // => ['barney', 'fred', 'pebbles']
4713 function dropWhile(array, predicate, thisArg) {
4714 return (array && array.length)
4715 ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
4720 * Fills elements of `array` with `value` from `start` up to, but not
4723 * **Note:** This method mutates `array`.
4728 * @param {Array} array The array to fill.
4729 * @param {*} value The value to fill `array` with.
4730 * @param {number} [start=0] The start position.
4731 * @param {number} [end=array.length] The end position.
4732 * @returns {Array} Returns `array`.
4735 * var array = [1, 2, 3];
4737 * _.fill(array, 'a');
4738 * console.log(array);
4739 * // => ['a', 'a', 'a']
4741 * _.fill(Array(3), 2);
4744 * _.fill([4, 6, 8], '*', 1, 2);
4747 function fill(array, value, start, end) {
4748 var length = array ? array.length : 0;
4752 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
4756 return baseFill(array, value, start, end);
4760 * This method is like `_.find` except that it returns the index of the first
4761 * element `predicate` returns truthy for instead of the element itself.
4763 * If a property name is provided for `predicate` the created `_.property`
4764 * style callback returns the property value of the given element.
4766 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4767 * style callback returns `true` for elements that have a matching property
4768 * value, else `false`.
4770 * If an object is provided for `predicate` the created `_.matches` style
4771 * callback returns `true` for elements that have the properties of the given
4772 * object, else `false`.
4777 * @param {Array} array The array to search.
4778 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4780 * @param {*} [thisArg] The `this` binding of `predicate`.
4781 * @returns {number} Returns the index of the found element, else `-1`.
4785 * { 'user': 'barney', 'active': false },
4786 * { 'user': 'fred', 'active': false },
4787 * { 'user': 'pebbles', 'active': true }
4790 * _.findIndex(users, function(chr) {
4791 * return chr.user == 'barney';
4795 * // using the `_.matches` callback shorthand
4796 * _.findIndex(users, { 'user': 'fred', 'active': false });
4799 * // using the `_.matchesProperty` callback shorthand
4800 * _.findIndex(users, 'active', false);
4803 * // using the `_.property` callback shorthand
4804 * _.findIndex(users, 'active');
4807 var findIndex = createFindIndex();
4810 * This method is like `_.findIndex` except that it iterates over elements
4811 * of `collection` from right to left.
4813 * If a property name is provided for `predicate` the created `_.property`
4814 * style callback returns the property value of the given element.
4816 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4817 * style callback returns `true` for elements that have a matching property
4818 * value, else `false`.
4820 * If an object is provided for `predicate` the created `_.matches` style
4821 * callback returns `true` for elements that have the properties of the given
4822 * object, else `false`.
4827 * @param {Array} array The array to search.
4828 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4830 * @param {*} [thisArg] The `this` binding of `predicate`.
4831 * @returns {number} Returns the index of the found element, else `-1`.
4835 * { 'user': 'barney', 'active': true },
4836 * { 'user': 'fred', 'active': false },
4837 * { 'user': 'pebbles', 'active': false }
4840 * _.findLastIndex(users, function(chr) {
4841 * return chr.user == 'pebbles';
4845 * // using the `_.matches` callback shorthand
4846 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
4849 * // using the `_.matchesProperty` callback shorthand
4850 * _.findLastIndex(users, 'active', false);
4853 * // using the `_.property` callback shorthand
4854 * _.findLastIndex(users, 'active');
4857 var findLastIndex = createFindIndex(true);
4860 * Gets the first element of `array`.
4866 * @param {Array} array The array to query.
4867 * @returns {*} Returns the first element of `array`.
4870 * _.first([1, 2, 3]);
4876 function first(array) {
4877 return array ? array[0] : undefined;
4881 * Flattens a nested array. If `isDeep` is `true` the array is recursively
4882 * flattened, otherwise it is only flattened a single level.
4887 * @param {Array} array The array to flatten.
4888 * @param {boolean} [isDeep] Specify a deep flatten.
4889 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4890 * @returns {Array} Returns the new flattened array.
4893 * _.flatten([1, [2, 3, [4]]]);
4894 * // => [1, 2, 3, [4]]
4897 * _.flatten([1, [2, 3, [4]]], true);
4898 * // => [1, 2, 3, 4]
4900 function flatten(array, isDeep, guard) {
4901 var length = array ? array.length : 0;
4902 if (guard && isIterateeCall(array, isDeep, guard)) {
4905 return length ? baseFlatten(array, isDeep) : [];
4909 * Recursively flattens a nested array.
4914 * @param {Array} array The array to recursively flatten.
4915 * @returns {Array} Returns the new flattened array.
4918 * _.flattenDeep([1, [2, 3, [4]]]);
4919 * // => [1, 2, 3, 4]
4921 function flattenDeep(array) {
4922 var length = array ? array.length : 0;
4923 return length ? baseFlatten(array, true) : [];
4927 * Gets the index at which the first occurrence of `value` is found in `array`
4928 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4929 * for equality comparisons. If `fromIndex` is negative, it is used as the offset
4930 * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
4931 * performs a faster binary search.
4936 * @param {Array} array The array to search.
4937 * @param {*} value The value to search for.
4938 * @param {boolean|number} [fromIndex=0] The index to search from or `true`
4939 * to perform a binary search on a sorted array.
4940 * @returns {number} Returns the index of the matched value, else `-1`.
4943 * _.indexOf([1, 2, 1, 2], 2);
4946 * // using `fromIndex`
4947 * _.indexOf([1, 2, 1, 2], 2, 2);
4950 * // performing a binary search
4951 * _.indexOf([1, 1, 2, 2], 2, true);
4954 function indexOf(array, value, fromIndex) {
4955 var length = array ? array.length : 0;
4959 if (typeof fromIndex == 'number') {
4960 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
4961 } else if (fromIndex) {
4962 var index = binaryIndex(array, value);
4963 if (index < length &&
4964 (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
4969 return baseIndexOf(array, value, fromIndex || 0);
4973 * Gets all but the last element of `array`.
4978 * @param {Array} array The array to query.
4979 * @returns {Array} Returns the slice of `array`.
4982 * _.initial([1, 2, 3]);
4985 function initial(array) {
4986 return dropRight(array, 1);
4990 * Creates an array of unique values that are included in all of the provided
4991 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4992 * for equality comparisons.
4997 * @param {...Array} [arrays] The arrays to inspect.
4998 * @returns {Array} Returns the new array of shared values.
5000 * _.intersection([1, 2], [4, 2], [2, 1]);
5003 var intersection = restParam(function(arrays) {
5004 var othLength = arrays.length,
5005 othIndex = othLength,
5006 caches = Array(length),
5007 indexOf = getIndexOf(),
5008 isCommon = indexOf == baseIndexOf,
5011 while (othIndex--) {
5012 var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
5013 caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
5015 var array = arrays[0],
5017 length = array ? array.length : 0,
5021 while (++index < length) {
5022 value = array[index];
5023 if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
5024 var othIndex = othLength;
5025 while (--othIndex) {
5026 var cache = caches[othIndex];
5027 if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
5041 * Gets the last element of `array`.
5046 * @param {Array} array The array to query.
5047 * @returns {*} Returns the last element of `array`.
5050 * _.last([1, 2, 3]);
5053 function last(array) {
5054 var length = array ? array.length : 0;
5055 return length ? array[length - 1] : undefined;
5059 * This method is like `_.indexOf` except that it iterates over elements of
5060 * `array` from right to left.
5065 * @param {Array} array The array to search.
5066 * @param {*} value The value to search for.
5067 * @param {boolean|number} [fromIndex=array.length-1] The index to search from
5068 * or `true` to perform a binary search on a sorted array.
5069 * @returns {number} Returns the index of the matched value, else `-1`.
5072 * _.lastIndexOf([1, 2, 1, 2], 2);
5075 * // using `fromIndex`
5076 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
5079 * // performing a binary search
5080 * _.lastIndexOf([1, 1, 2, 2], 2, true);
5083 function lastIndexOf(array, value, fromIndex) {
5084 var length = array ? array.length : 0;
5089 if (typeof fromIndex == 'number') {
5090 index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
5091 } else if (fromIndex) {
5092 index = binaryIndex(array, value, true) - 1;
5093 var other = array[index];
5094 if (value === value ? (value === other) : (other !== other)) {
5099 if (value !== value) {
5100 return indexOfNaN(array, index, true);
5103 if (array[index] === value) {
5111 * Removes all provided values from `array` using
5112 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5113 * for equality comparisons.
5115 * **Note:** Unlike `_.without`, this method mutates `array`.
5120 * @param {Array} array The array to modify.
5121 * @param {...*} [values] The values to remove.
5122 * @returns {Array} Returns `array`.
5125 * var array = [1, 2, 3, 1, 2, 3];
5127 * _.pull(array, 2, 3);
5128 * console.log(array);
5132 var args = arguments,
5135 if (!(array && array.length)) {
5139 indexOf = getIndexOf(),
5140 length = args.length;
5142 while (++index < length) {
5144 value = args[index];
5146 while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
5147 splice.call(array, fromIndex, 1);
5154 * Removes elements from `array` corresponding to the given indexes and returns
5155 * an array of the removed elements. Indexes may be specified as an array of
5156 * indexes or as individual arguments.
5158 * **Note:** Unlike `_.at`, this method mutates `array`.
5163 * @param {Array} array The array to modify.
5164 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
5165 * specified as individual indexes or arrays of indexes.
5166 * @returns {Array} Returns the new array of removed elements.
5169 * var array = [5, 10, 15, 20];
5170 * var evens = _.pullAt(array, 1, 3);
5172 * console.log(array);
5175 * console.log(evens);
5178 var pullAt = restParam(function(array, indexes) {
5179 indexes = baseFlatten(indexes);
5181 var result = baseAt(array, indexes);
5182 basePullAt(array, indexes.sort(baseCompareAscending));
5187 * Removes all elements from `array` that `predicate` returns truthy for
5188 * and returns an array of the removed elements. The predicate is bound to
5189 * `thisArg` and invoked with three arguments: (value, index, array).
5191 * If a property name is provided for `predicate` the created `_.property`
5192 * style callback returns the property value of the given element.
5194 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5195 * style callback returns `true` for elements that have a matching property
5196 * value, else `false`.
5198 * If an object is provided for `predicate` the created `_.matches` style
5199 * callback returns `true` for elements that have the properties of the given
5200 * object, else `false`.
5202 * **Note:** Unlike `_.filter`, this method mutates `array`.
5207 * @param {Array} array The array to modify.
5208 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5210 * @param {*} [thisArg] The `this` binding of `predicate`.
5211 * @returns {Array} Returns the new array of removed elements.
5214 * var array = [1, 2, 3, 4];
5215 * var evens = _.remove(array, function(n) {
5216 * return n % 2 == 0;
5219 * console.log(array);
5222 * console.log(evens);
5225 function remove(array, predicate, thisArg) {
5227 if (!(array && array.length)) {
5232 length = array.length;
5234 predicate = getCallback(predicate, thisArg, 3);
5235 while (++index < length) {
5236 var value = array[index];
5237 if (predicate(value, index, array)) {
5239 indexes.push(index);
5242 basePullAt(array, indexes);
5247 * Gets all but the first element of `array`.
5253 * @param {Array} array The array to query.
5254 * @returns {Array} Returns the slice of `array`.
5257 * _.rest([1, 2, 3]);
5260 function rest(array) {
5261 return drop(array, 1);
5265 * Creates a slice of `array` from `start` up to, but not including, `end`.
5267 * **Note:** This method is used instead of `Array#slice` to support node
5268 * lists in IE < 9 and to ensure dense arrays are returned.
5273 * @param {Array} array The array to slice.
5274 * @param {number} [start=0] The start position.
5275 * @param {number} [end=array.length] The end position.
5276 * @returns {Array} Returns the slice of `array`.
5278 function slice(array, start, end) {
5279 var length = array ? array.length : 0;
5283 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
5287 return baseSlice(array, start, end);
5291 * Uses a binary search to determine the lowest index at which `value` should
5292 * be inserted into `array` in order to maintain its sort order. If an iteratee
5293 * function is provided it is invoked for `value` and each element of `array`
5294 * to compute their sort ranking. The iteratee is bound to `thisArg` and
5295 * invoked with one argument; (value).
5297 * If a property name is provided for `iteratee` the created `_.property`
5298 * style callback returns the property value of the given element.
5300 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5301 * style callback returns `true` for elements that have a matching property
5302 * value, else `false`.
5304 * If an object is provided for `iteratee` the created `_.matches` style
5305 * callback returns `true` for elements that have the properties of the given
5306 * object, else `false`.
5311 * @param {Array} array The sorted array to inspect.
5312 * @param {*} value The value to evaluate.
5313 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5315 * @param {*} [thisArg] The `this` binding of `iteratee`.
5316 * @returns {number} Returns the index at which `value` should be inserted
5320 * _.sortedIndex([30, 50], 40);
5323 * _.sortedIndex([4, 4, 5, 5], 5);
5326 * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
5328 * // using an iteratee function
5329 * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
5330 * return this.data[word];
5334 * // using the `_.property` callback shorthand
5335 * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
5338 var sortedIndex = createSortedIndex();
5341 * This method is like `_.sortedIndex` except that it returns the highest
5342 * index at which `value` should be inserted into `array` in order to
5343 * maintain its sort order.
5348 * @param {Array} array The sorted array to inspect.
5349 * @param {*} value The value to evaluate.
5350 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5352 * @param {*} [thisArg] The `this` binding of `iteratee`.
5353 * @returns {number} Returns the index at which `value` should be inserted
5357 * _.sortedLastIndex([4, 4, 5, 5], 5);
5360 var sortedLastIndex = createSortedIndex(true);
5363 * Creates a slice of `array` with `n` elements taken from the beginning.
5368 * @param {Array} array The array to query.
5369 * @param {number} [n=1] The number of elements to take.
5370 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5371 * @returns {Array} Returns the slice of `array`.
5374 * _.take([1, 2, 3]);
5377 * _.take([1, 2, 3], 2);
5380 * _.take([1, 2, 3], 5);
5383 * _.take([1, 2, 3], 0);
5386 function take(array, n, guard) {
5387 var length = array ? array.length : 0;
5391 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5394 return baseSlice(array, 0, n < 0 ? 0 : n);
5398 * Creates a slice of `array` with `n` elements taken from the end.
5403 * @param {Array} array The array to query.
5404 * @param {number} [n=1] The number of elements to take.
5405 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5406 * @returns {Array} Returns the slice of `array`.
5409 * _.takeRight([1, 2, 3]);
5412 * _.takeRight([1, 2, 3], 2);
5415 * _.takeRight([1, 2, 3], 5);
5418 * _.takeRight([1, 2, 3], 0);
5421 function takeRight(array, n, guard) {
5422 var length = array ? array.length : 0;
5426 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5429 n = length - (+n || 0);
5430 return baseSlice(array, n < 0 ? 0 : n);
5434 * Creates a slice of `array` with elements taken from the end. Elements are
5435 * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
5436 * and invoked with three arguments: (value, index, array).
5438 * If a property name is provided for `predicate` the created `_.property`
5439 * style callback returns the property value of the given element.
5441 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5442 * style callback returns `true` for elements that have a matching property
5443 * value, else `false`.
5445 * If an object is provided for `predicate` the created `_.matches` style
5446 * callback returns `true` for elements that have the properties of the given
5447 * object, else `false`.
5452 * @param {Array} array The array to query.
5453 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5455 * @param {*} [thisArg] The `this` binding of `predicate`.
5456 * @returns {Array} Returns the slice of `array`.
5459 * _.takeRightWhile([1, 2, 3], function(n) {
5465 * { 'user': 'barney', 'active': true },
5466 * { 'user': 'fred', 'active': false },
5467 * { 'user': 'pebbles', 'active': false }
5470 * // using the `_.matches` callback shorthand
5471 * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
5474 * // using the `_.matchesProperty` callback shorthand
5475 * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
5476 * // => ['fred', 'pebbles']
5478 * // using the `_.property` callback shorthand
5479 * _.pluck(_.takeRightWhile(users, 'active'), 'user');
5482 function takeRightWhile(array, predicate, thisArg) {
5483 return (array && array.length)
5484 ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
5489 * Creates a slice of `array` with elements taken from the beginning. Elements
5490 * are taken until `predicate` returns falsey. The predicate is bound to
5491 * `thisArg` and invoked with three arguments: (value, index, array).
5493 * If a property name is provided for `predicate` the created `_.property`
5494 * style callback returns the property value of the given element.
5496 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5497 * style callback returns `true` for elements that have a matching property
5498 * value, else `false`.
5500 * If an object is provided for `predicate` the created `_.matches` style
5501 * callback returns `true` for elements that have the properties of the given
5502 * object, else `false`.
5507 * @param {Array} array The array to query.
5508 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5510 * @param {*} [thisArg] The `this` binding of `predicate`.
5511 * @returns {Array} Returns the slice of `array`.
5514 * _.takeWhile([1, 2, 3], function(n) {
5520 * { 'user': 'barney', 'active': false },
5521 * { 'user': 'fred', 'active': false},
5522 * { 'user': 'pebbles', 'active': true }
5525 * // using the `_.matches` callback shorthand
5526 * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
5529 * // using the `_.matchesProperty` callback shorthand
5530 * _.pluck(_.takeWhile(users, 'active', false), 'user');
5531 * // => ['barney', 'fred']
5533 * // using the `_.property` callback shorthand
5534 * _.pluck(_.takeWhile(users, 'active'), 'user');
5537 function takeWhile(array, predicate, thisArg) {
5538 return (array && array.length)
5539 ? baseWhile(array, getCallback(predicate, thisArg, 3))
5544 * Creates an array of unique values, in order, from all of the provided arrays
5545 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5546 * for equality comparisons.
5551 * @param {...Array} [arrays] The arrays to inspect.
5552 * @returns {Array} Returns the new array of combined values.
5555 * _.union([1, 2], [4, 2], [2, 1]);
5558 var union = restParam(function(arrays) {
5559 return baseUniq(baseFlatten(arrays, false, true));
5563 * Creates a duplicate-free version of an array, using
5564 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5565 * for equality comparisons, in which only the first occurence of each element
5566 * is kept. Providing `true` for `isSorted` performs a faster search algorithm
5567 * for sorted arrays. If an iteratee function is provided it is invoked for
5568 * each element in the array to generate the criterion by which uniqueness
5569 * is computed. The `iteratee` is bound to `thisArg` and invoked with three
5570 * arguments: (value, index, array).
5572 * If a property name is provided for `iteratee` the created `_.property`
5573 * style callback returns the property value of the given element.
5575 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5576 * style callback returns `true` for elements that have a matching property
5577 * value, else `false`.
5579 * If an object is provided for `iteratee` the created `_.matches` style
5580 * callback returns `true` for elements that have the properties of the given
5581 * object, else `false`.
5587 * @param {Array} array The array to inspect.
5588 * @param {boolean} [isSorted] Specify the array is sorted.
5589 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
5590 * @param {*} [thisArg] The `this` binding of `iteratee`.
5591 * @returns {Array} Returns the new duplicate-value-free array.
5594 * _.uniq([2, 1, 2]);
5597 * // using `isSorted`
5598 * _.uniq([1, 1, 2], true);
5601 * // using an iteratee function
5602 * _.uniq([1, 2.5, 1.5, 2], function(n) {
5603 * return this.floor(n);
5607 * // using the `_.property` callback shorthand
5608 * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
5609 * // => [{ 'x': 1 }, { 'x': 2 }]
5611 function uniq(array, isSorted, iteratee, thisArg) {
5612 var length = array ? array.length : 0;
5616 if (isSorted != null && typeof isSorted != 'boolean') {
5618 iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
5621 var callback = getCallback();
5622 if (!(iteratee == null && callback === baseCallback)) {
5623 iteratee = callback(iteratee, thisArg, 3);
5625 return (isSorted && getIndexOf() == baseIndexOf)
5626 ? sortedUniq(array, iteratee)
5627 : baseUniq(array, iteratee);
5631 * This method is like `_.zip` except that it accepts an array of grouped
5632 * elements and creates an array regrouping the elements to their pre-zip
5638 * @param {Array} array The array of grouped elements to process.
5639 * @returns {Array} Returns the new array of regrouped elements.
5642 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
5643 * // => [['fred', 30, true], ['barney', 40, false]]
5646 * // => [['fred', 'barney'], [30, 40], [true, false]]
5648 function unzip(array) {
5649 if (!(array && array.length)) {
5655 array = arrayFilter(array, function(group) {
5656 if (isArrayLike(group)) {
5657 length = nativeMax(group.length, length);
5661 var result = Array(length);
5662 while (++index < length) {
5663 result[index] = arrayMap(array, baseProperty(index));
5669 * This method is like `_.unzip` except that it accepts an iteratee to specify
5670 * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
5671 * and invoked with four arguments: (accumulator, value, index, group).
5676 * @param {Array} array The array of grouped elements to process.
5677 * @param {Function} [iteratee] The function to combine regrouped values.
5678 * @param {*} [thisArg] The `this` binding of `iteratee`.
5679 * @returns {Array} Returns the new array of regrouped elements.
5682 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
5683 * // => [[1, 10, 100], [2, 20, 200]]
5685 * _.unzipWith(zipped, _.add);
5686 * // => [3, 30, 300]
5688 function unzipWith(array, iteratee, thisArg) {
5689 var length = array ? array.length : 0;
5693 var result = unzip(array);
5694 if (iteratee == null) {
5697 iteratee = bindCallback(iteratee, thisArg, 4);
5698 return arrayMap(result, function(group) {
5699 return arrayReduce(group, iteratee, undefined, true);
5704 * Creates an array excluding all provided values using
5705 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5706 * for equality comparisons.
5711 * @param {Array} array The array to filter.
5712 * @param {...*} [values] The values to exclude.
5713 * @returns {Array} Returns the new array of filtered values.
5716 * _.without([1, 2, 1, 3], 1, 2);
5719 var without = restParam(function(array, values) {
5720 return isArrayLike(array)
5721 ? baseDifference(array, values)
5726 * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
5727 * of the provided arrays.
5732 * @param {...Array} [arrays] The arrays to inspect.
5733 * @returns {Array} Returns the new array of values.
5736 * _.xor([1, 2], [4, 2]);
5741 length = arguments.length;
5743 while (++index < length) {
5744 var array = arguments[index];
5745 if (isArrayLike(array)) {
5747 ? arrayPush(baseDifference(result, array), baseDifference(array, result))
5751 return result ? baseUniq(result) : [];
5755 * Creates an array of grouped elements, the first of which contains the first
5756 * elements of the given arrays, the second of which contains the second elements
5757 * of the given arrays, and so on.
5762 * @param {...Array} [arrays] The arrays to process.
5763 * @returns {Array} Returns the new array of grouped elements.
5766 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
5767 * // => [['fred', 30, true], ['barney', 40, false]]
5769 var zip = restParam(unzip);
5772 * The inverse of `_.pairs`; this method returns an object composed from arrays
5773 * of property names and values. Provide either a single two dimensional array,
5774 * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
5775 * and one of corresponding values.
5781 * @param {Array} props The property names.
5782 * @param {Array} [values=[]] The property values.
5783 * @returns {Object} Returns the new object.
5786 * _.zipObject([['fred', 30], ['barney', 40]]);
5787 * // => { 'fred': 30, 'barney': 40 }
5789 * _.zipObject(['fred', 'barney'], [30, 40]);
5790 * // => { 'fred': 30, 'barney': 40 }
5792 function zipObject(props, values) {
5794 length = props ? props.length : 0,
5797 if (length && !values && !isArray(props[0])) {
5800 while (++index < length) {
5801 var key = props[index];
5803 result[key] = values[index];
5805 result[key[0]] = key[1];
5812 * This method is like `_.zip` except that it accepts an iteratee to specify
5813 * how grouped values should be combined. The `iteratee` is bound to `thisArg`
5814 * and invoked with four arguments: (accumulator, value, index, group).
5819 * @param {...Array} [arrays] The arrays to process.
5820 * @param {Function} [iteratee] The function to combine grouped values.
5821 * @param {*} [thisArg] The `this` binding of `iteratee`.
5822 * @returns {Array} Returns the new array of grouped elements.
5825 * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
5828 var zipWith = restParam(function(arrays) {
5829 var length = arrays.length,
5830 iteratee = length > 2 ? arrays[length - 2] : undefined,
5831 thisArg = length > 1 ? arrays[length - 1] : undefined;
5833 if (length > 2 && typeof iteratee == 'function') {
5836 iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
5837 thisArg = undefined;
5839 arrays.length = length;
5840 return unzipWith(arrays, iteratee, thisArg);
5843 /*------------------------------------------------------------------------*/
5846 * Creates a `lodash` object that wraps `value` with explicit method
5852 * @param {*} value The value to wrap.
5853 * @returns {Object} Returns the new `lodash` wrapper instance.
5857 * { 'user': 'barney', 'age': 36 },
5858 * { 'user': 'fred', 'age': 40 },
5859 * { 'user': 'pebbles', 'age': 1 }
5862 * var youngest = _.chain(users)
5864 * .map(function(chr) {
5865 * return chr.user + ' is ' + chr.age;
5869 * // => 'pebbles is 1'
5871 function chain(value) {
5872 var result = lodash(value);
5873 result.__chain__ = true;
5878 * This method invokes `interceptor` and returns `value`. The interceptor is
5879 * bound to `thisArg` and invoked with one argument; (value). The purpose of
5880 * this method is to "tap into" a method chain in order to perform operations
5881 * on intermediate results within the chain.
5886 * @param {*} value The value to provide to `interceptor`.
5887 * @param {Function} interceptor The function to invoke.
5888 * @param {*} [thisArg] The `this` binding of `interceptor`.
5889 * @returns {*} Returns `value`.
5893 * .tap(function(array) {
5900 function tap(value, interceptor, thisArg) {
5901 interceptor.call(thisArg, value);
5906 * This method is like `_.tap` except that it returns the result of `interceptor`.
5911 * @param {*} value The value to provide to `interceptor`.
5912 * @param {Function} interceptor The function to invoke.
5913 * @param {*} [thisArg] The `this` binding of `interceptor`.
5914 * @returns {*} Returns the result of `interceptor`.
5920 * .thru(function(value) {
5926 function thru(value, interceptor, thisArg) {
5927 return interceptor.call(thisArg, value);
5931 * Enables explicit method chaining on the wrapper object.
5936 * @returns {Object} Returns the new `lodash` wrapper instance.
5940 * { 'user': 'barney', 'age': 36 },
5941 * { 'user': 'fred', 'age': 40 }
5944 * // without explicit chaining
5946 * // => { 'user': 'barney', 'age': 36 }
5948 * // with explicit chaining
5953 * // => { 'user': 'barney' }
5955 function wrapperChain() {
5960 * Executes the chained sequence and returns the wrapped result.
5965 * @returns {Object} Returns the new `lodash` wrapper instance.
5968 * var array = [1, 2];
5969 * var wrapped = _(array).push(3);
5971 * console.log(array);
5974 * wrapped = wrapped.commit();
5975 * console.log(array);
5981 * console.log(array);
5984 function wrapperCommit() {
5985 return new LodashWrapper(this.value(), this.__chain__);
5989 * Creates a new array joining a wrapped array with any additional arrays
5995 * @param {...*} [values] The values to concatenate.
5996 * @returns {Array} Returns the new concatenated array.
6000 * var wrapped = _(array).concat(2, [3], [[4]]);
6002 * console.log(wrapped.value());
6003 * // => [1, 2, 3, [4]]
6005 * console.log(array);
6008 var wrapperConcat = restParam(function(values) {
6009 values = baseFlatten(values);
6010 return this.thru(function(array) {
6011 return arrayConcat(isArray(array) ? array : [toObject(array)], values);
6016 * Creates a clone of the chained sequence planting `value` as the wrapped value.
6021 * @returns {Object} Returns the new `lodash` wrapper instance.
6024 * var array = [1, 2];
6025 * var wrapped = _(array).map(function(value) {
6026 * return Math.pow(value, 2);
6029 * var other = [3, 4];
6030 * var otherWrapped = wrapped.plant(other);
6032 * otherWrapped.value();
6038 function wrapperPlant(value) {
6042 while (parent instanceof baseLodash) {
6043 var clone = wrapperClone(parent);
6045 previous.__wrapped__ = clone;
6049 var previous = clone;
6050 parent = parent.__wrapped__;
6052 previous.__wrapped__ = value;
6057 * Reverses the wrapped array so the first element becomes the last, the
6058 * second element becomes the second to last, and so on.
6060 * **Note:** This method mutates the wrapped array.
6065 * @returns {Object} Returns the new reversed `lodash` wrapper instance.
6068 * var array = [1, 2, 3];
6070 * _(array).reverse().value()
6073 * console.log(array);
6076 function wrapperReverse() {
6077 var value = this.__wrapped__;
6079 var interceptor = function(value) {
6080 return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
6082 if (value instanceof LazyWrapper) {
6083 var wrapped = value;
6084 if (this.__actions__.length) {
6085 wrapped = new LazyWrapper(this);
6087 wrapped = wrapped.reverse();
6088 wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
6089 return new LodashWrapper(wrapped, this.__chain__);
6091 return this.thru(interceptor);
6095 * Produces the result of coercing the unwrapped value to a string.
6100 * @returns {string} Returns the coerced string value.
6103 * _([1, 2, 3]).toString();
6106 function wrapperToString() {
6107 return (this.value() + '');
6111 * Executes the chained sequence to extract the unwrapped value.
6115 * @alias run, toJSON, valueOf
6117 * @returns {*} Returns the resolved unwrapped value.
6120 * _([1, 2, 3]).value();
6123 function wrapperValue() {
6124 return baseWrapperValue(this.__wrapped__, this.__actions__);
6127 /*------------------------------------------------------------------------*/
6130 * Creates an array of elements corresponding to the given keys, or indexes,
6131 * of `collection`. Keys may be specified as individual arguments or as arrays
6136 * @category Collection
6137 * @param {Array|Object|string} collection The collection to iterate over.
6138 * @param {...(number|number[]|string|string[])} [props] The property names
6139 * or indexes of elements to pick, specified individually or in arrays.
6140 * @returns {Array} Returns the new array of picked elements.
6143 * _.at(['a', 'b', 'c'], [0, 2]);
6146 * _.at(['barney', 'fred', 'pebbles'], 0, 2);
6147 * // => ['barney', 'pebbles']
6149 var at = restParam(function(collection, props) {
6150 return baseAt(collection, baseFlatten(props));
6154 * Creates an object composed of keys generated from the results of running
6155 * each element of `collection` through `iteratee`. The corresponding value
6156 * of each key is the number of times the key was returned by `iteratee`.
6157 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6158 * (value, index|key, collection).
6160 * If a property name is provided for `iteratee` the created `_.property`
6161 * style callback returns the property value of the given element.
6163 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6164 * style callback returns `true` for elements that have a matching property
6165 * value, else `false`.
6167 * If an object is provided for `iteratee` the created `_.matches` style
6168 * callback returns `true` for elements that have the properties of the given
6169 * object, else `false`.
6173 * @category Collection
6174 * @param {Array|Object|string} collection The collection to iterate over.
6175 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6177 * @param {*} [thisArg] The `this` binding of `iteratee`.
6178 * @returns {Object} Returns the composed aggregate object.
6181 * _.countBy([4.3, 6.1, 6.4], function(n) {
6182 * return Math.floor(n);
6184 * // => { '4': 1, '6': 2 }
6186 * _.countBy([4.3, 6.1, 6.4], function(n) {
6187 * return this.floor(n);
6189 * // => { '4': 1, '6': 2 }
6191 * _.countBy(['one', 'two', 'three'], 'length');
6192 * // => { '3': 2, '5': 1 }
6194 var countBy = createAggregator(function(result, value, key) {
6195 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
6199 * Checks if `predicate` returns truthy for **all** elements of `collection`.
6200 * The predicate is bound to `thisArg` and invoked with three arguments:
6201 * (value, index|key, collection).
6203 * If a property name is provided for `predicate` the created `_.property`
6204 * style callback returns the property value of the given element.
6206 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6207 * style callback returns `true` for elements that have a matching property
6208 * value, else `false`.
6210 * If an object is provided for `predicate` the created `_.matches` style
6211 * callback returns `true` for elements that have the properties of the given
6212 * object, else `false`.
6217 * @category Collection
6218 * @param {Array|Object|string} collection The collection to iterate over.
6219 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6221 * @param {*} [thisArg] The `this` binding of `predicate`.
6222 * @returns {boolean} Returns `true` if all elements pass the predicate check,
6226 * _.every([true, 1, null, 'yes'], Boolean);
6230 * { 'user': 'barney', 'active': false },
6231 * { 'user': 'fred', 'active': false }
6234 * // using the `_.matches` callback shorthand
6235 * _.every(users, { 'user': 'barney', 'active': false });
6238 * // using the `_.matchesProperty` callback shorthand
6239 * _.every(users, 'active', false);
6242 * // using the `_.property` callback shorthand
6243 * _.every(users, 'active');
6246 function every(collection, predicate, thisArg) {
6247 var func = isArray(collection) ? arrayEvery : baseEvery;
6248 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
6249 predicate = undefined;
6251 if (typeof predicate != 'function' || thisArg !== undefined) {
6252 predicate = getCallback(predicate, thisArg, 3);
6254 return func(collection, predicate);
6258 * Iterates over elements of `collection`, returning an array of all elements
6259 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6260 * invoked with three arguments: (value, index|key, collection).
6262 * If a property name is provided for `predicate` the created `_.property`
6263 * style callback returns the property value of the given element.
6265 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6266 * style callback returns `true` for elements that have a matching property
6267 * value, else `false`.
6269 * If an object is provided for `predicate` the created `_.matches` style
6270 * callback returns `true` for elements that have the properties of the given
6271 * object, else `false`.
6276 * @category Collection
6277 * @param {Array|Object|string} collection The collection to iterate over.
6278 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6280 * @param {*} [thisArg] The `this` binding of `predicate`.
6281 * @returns {Array} Returns the new filtered array.
6284 * _.filter([4, 5, 6], function(n) {
6285 * return n % 2 == 0;
6290 * { 'user': 'barney', 'age': 36, 'active': true },
6291 * { 'user': 'fred', 'age': 40, 'active': false }
6294 * // using the `_.matches` callback shorthand
6295 * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
6298 * // using the `_.matchesProperty` callback shorthand
6299 * _.pluck(_.filter(users, 'active', false), 'user');
6302 * // using the `_.property` callback shorthand
6303 * _.pluck(_.filter(users, 'active'), 'user');
6306 function filter(collection, predicate, thisArg) {
6307 var func = isArray(collection) ? arrayFilter : baseFilter;
6308 predicate = getCallback(predicate, thisArg, 3);
6309 return func(collection, predicate);
6313 * Iterates over elements of `collection`, returning the first element
6314 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6315 * invoked with three arguments: (value, index|key, collection).
6317 * If a property name is provided for `predicate` the created `_.property`
6318 * style callback returns the property value of the given element.
6320 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6321 * style callback returns `true` for elements that have a matching property
6322 * value, else `false`.
6324 * If an object is provided for `predicate` the created `_.matches` style
6325 * callback returns `true` for elements that have the properties of the given
6326 * object, else `false`.
6331 * @category Collection
6332 * @param {Array|Object|string} collection The collection to search.
6333 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6335 * @param {*} [thisArg] The `this` binding of `predicate`.
6336 * @returns {*} Returns the matched element, else `undefined`.
6340 * { 'user': 'barney', 'age': 36, 'active': true },
6341 * { 'user': 'fred', 'age': 40, 'active': false },
6342 * { 'user': 'pebbles', 'age': 1, 'active': true }
6345 * _.result(_.find(users, function(chr) {
6346 * return chr.age < 40;
6350 * // using the `_.matches` callback shorthand
6351 * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
6354 * // using the `_.matchesProperty` callback shorthand
6355 * _.result(_.find(users, 'active', false), 'user');
6358 * // using the `_.property` callback shorthand
6359 * _.result(_.find(users, 'active'), 'user');
6362 var find = createFind(baseEach);
6365 * This method is like `_.find` except that it iterates over elements of
6366 * `collection` from right to left.
6370 * @category Collection
6371 * @param {Array|Object|string} collection The collection to search.
6372 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6374 * @param {*} [thisArg] The `this` binding of `predicate`.
6375 * @returns {*} Returns the matched element, else `undefined`.
6378 * _.findLast([1, 2, 3, 4], function(n) {
6379 * return n % 2 == 1;
6383 var findLast = createFind(baseEachRight, true);
6386 * Performs a deep comparison between each element in `collection` and the
6387 * source object, returning the first element that has equivalent property
6390 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
6391 * numbers, `Object` objects, regexes, and strings. Objects are compared by
6392 * their own, not inherited, enumerable properties. For comparing a single
6393 * own or inherited property value see `_.matchesProperty`.
6397 * @category Collection
6398 * @param {Array|Object|string} collection The collection to search.
6399 * @param {Object} source The object of property values to match.
6400 * @returns {*} Returns the matched element, else `undefined`.
6404 * { 'user': 'barney', 'age': 36, 'active': true },
6405 * { 'user': 'fred', 'age': 40, 'active': false }
6408 * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
6411 * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
6414 function findWhere(collection, source) {
6415 return find(collection, baseMatches(source));
6419 * Iterates over elements of `collection` invoking `iteratee` for each element.
6420 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6421 * (value, index|key, collection). Iteratee functions may exit iteration early
6422 * by explicitly returning `false`.
6424 * **Note:** As with other "Collections" methods, objects with a "length" property
6425 * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
6426 * may be used for object iteration.
6431 * @category Collection
6432 * @param {Array|Object|string} collection The collection to iterate over.
6433 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6434 * @param {*} [thisArg] The `this` binding of `iteratee`.
6435 * @returns {Array|Object|string} Returns `collection`.
6438 * _([1, 2]).forEach(function(n) {
6441 * // => logs each value from left to right and returns the array
6443 * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
6444 * console.log(n, key);
6446 * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
6448 var forEach = createForEach(arrayEach, baseEach);
6451 * This method is like `_.forEach` except that it iterates over elements of
6452 * `collection` from right to left.
6457 * @category Collection
6458 * @param {Array|Object|string} collection The collection to iterate over.
6459 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6460 * @param {*} [thisArg] The `this` binding of `iteratee`.
6461 * @returns {Array|Object|string} Returns `collection`.
6464 * _([1, 2]).forEachRight(function(n) {
6467 * // => logs each value from right to left and returns the array
6469 var forEachRight = createForEach(arrayEachRight, baseEachRight);
6472 * Creates an object composed of keys generated from the results of running
6473 * each element of `collection` through `iteratee`. The corresponding value
6474 * of each key is an array of the elements responsible for generating the key.
6475 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6476 * (value, index|key, collection).
6478 * If a property name is provided for `iteratee` the created `_.property`
6479 * style callback returns the property value of the given element.
6481 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6482 * style callback returns `true` for elements that have a matching property
6483 * value, else `false`.
6485 * If an object is provided for `iteratee` the created `_.matches` style
6486 * callback returns `true` for elements that have the properties of the given
6487 * object, else `false`.
6491 * @category Collection
6492 * @param {Array|Object|string} collection The collection to iterate over.
6493 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6495 * @param {*} [thisArg] The `this` binding of `iteratee`.
6496 * @returns {Object} Returns the composed aggregate object.
6499 * _.groupBy([4.2, 6.1, 6.4], function(n) {
6500 * return Math.floor(n);
6502 * // => { '4': [4.2], '6': [6.1, 6.4] }
6504 * _.groupBy([4.2, 6.1, 6.4], function(n) {
6505 * return this.floor(n);
6507 * // => { '4': [4.2], '6': [6.1, 6.4] }
6509 * // using the `_.property` callback shorthand
6510 * _.groupBy(['one', 'two', 'three'], 'length');
6511 * // => { '3': ['one', 'two'], '5': ['three'] }
6513 var groupBy = createAggregator(function(result, value, key) {
6514 if (hasOwnProperty.call(result, key)) {
6515 result[key].push(value);
6517 result[key] = [value];
6522 * Checks if `value` is in `collection` using
6523 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6524 * for equality comparisons. If `fromIndex` is negative, it is used as the offset
6525 * from the end of `collection`.
6529 * @alias contains, include
6530 * @category Collection
6531 * @param {Array|Object|string} collection The collection to search.
6532 * @param {*} target The value to search for.
6533 * @param {number} [fromIndex=0] The index to search from.
6534 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
6535 * @returns {boolean} Returns `true` if a matching element is found, else `false`.
6538 * _.includes([1, 2, 3], 1);
6541 * _.includes([1, 2, 3], 1, 2);
6544 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
6547 * _.includes('pebbles', 'eb');
6550 function includes(collection, target, fromIndex, guard) {
6551 var length = collection ? getLength(collection) : 0;
6552 if (!isLength(length)) {
6553 collection = values(collection);
6554 length = collection.length;
6556 if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
6559 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
6561 return (typeof collection == 'string' || !isArray(collection) && isString(collection))
6562 ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
6563 : (!!length && getIndexOf(collection, target, fromIndex) > -1);
6567 * Creates an object composed of keys generated from the results of running
6568 * each element of `collection` through `iteratee`. The corresponding value
6569 * of each key is the last element responsible for generating the key. The
6570 * iteratee function is bound to `thisArg` and invoked with three arguments:
6571 * (value, index|key, collection).
6573 * If a property name is provided for `iteratee` the created `_.property`
6574 * style callback returns the property value of the given element.
6576 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6577 * style callback returns `true` for elements that have a matching property
6578 * value, else `false`.
6580 * If an object is provided for `iteratee` the created `_.matches` style
6581 * callback returns `true` for elements that have the properties of the given
6582 * object, else `false`.
6586 * @category Collection
6587 * @param {Array|Object|string} collection The collection to iterate over.
6588 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6590 * @param {*} [thisArg] The `this` binding of `iteratee`.
6591 * @returns {Object} Returns the composed aggregate object.
6595 * { 'dir': 'left', 'code': 97 },
6596 * { 'dir': 'right', 'code': 100 }
6599 * _.indexBy(keyData, 'dir');
6600 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
6602 * _.indexBy(keyData, function(object) {
6603 * return String.fromCharCode(object.code);
6605 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6607 * _.indexBy(keyData, function(object) {
6608 * return this.fromCharCode(object.code);
6610 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6612 var indexBy = createAggregator(function(result, value, key) {
6613 result[key] = value;
6617 * Invokes the method at `path` of each element in `collection`, returning
6618 * an array of the results of each invoked method. Any additional arguments
6619 * are provided to each invoked method. If `methodName` is a function it is
6620 * invoked for, and `this` bound to, each element in `collection`.
6624 * @category Collection
6625 * @param {Array|Object|string} collection The collection to iterate over.
6626 * @param {Array|Function|string} path The path of the method to invoke or
6627 * the function invoked per iteration.
6628 * @param {...*} [args] The arguments to invoke the method with.
6629 * @returns {Array} Returns the array of results.
6632 * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
6633 * // => [[1, 5, 7], [1, 2, 3]]
6635 * _.invoke([123, 456], String.prototype.split, '');
6636 * // => [['1', '2', '3'], ['4', '5', '6']]
6638 var invoke = restParam(function(collection, path, args) {
6640 isFunc = typeof path == 'function',
6641 isProp = isKey(path),
6642 result = isArrayLike(collection) ? Array(collection.length) : [];
6644 baseEach(collection, function(value) {
6645 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
6646 result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
6652 * Creates an array of values by running each element in `collection` through
6653 * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
6654 * arguments: (value, index|key, collection).
6656 * If a property name is provided for `iteratee` the created `_.property`
6657 * style callback returns the property value of the given element.
6659 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6660 * style callback returns `true` for elements that have a matching property
6661 * value, else `false`.
6663 * If an object is provided for `iteratee` the created `_.matches` style
6664 * callback returns `true` for elements that have the properties of the given
6665 * object, else `false`.
6667 * Many lodash methods are guarded to work as iteratees for methods like
6668 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
6670 * The guarded methods are:
6671 * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
6672 * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
6673 * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
6674 * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
6675 * `sum`, `uniq`, and `words`
6680 * @category Collection
6681 * @param {Array|Object|string} collection The collection to iterate over.
6682 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6684 * @param {*} [thisArg] The `this` binding of `iteratee`.
6685 * @returns {Array} Returns the new mapped array.
6688 * function timesThree(n) {
6692 * _.map([1, 2], timesThree);
6695 * _.map({ 'a': 1, 'b': 2 }, timesThree);
6696 * // => [3, 6] (iteration order is not guaranteed)
6699 * { 'user': 'barney' },
6700 * { 'user': 'fred' }
6703 * // using the `_.property` callback shorthand
6704 * _.map(users, 'user');
6705 * // => ['barney', 'fred']
6707 function map(collection, iteratee, thisArg) {
6708 var func = isArray(collection) ? arrayMap : baseMap;
6709 iteratee = getCallback(iteratee, thisArg, 3);
6710 return func(collection, iteratee);
6714 * Creates an array of elements split into two groups, the first of which
6715 * contains elements `predicate` returns truthy for, while the second of which
6716 * contains elements `predicate` returns falsey for. The predicate is bound
6717 * to `thisArg` and invoked with three arguments: (value, index|key, collection).
6719 * If a property name is provided for `predicate` the created `_.property`
6720 * style callback returns the property value of the given element.
6722 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6723 * style callback returns `true` for elements that have a matching property
6724 * value, else `false`.
6726 * If an object is provided for `predicate` the created `_.matches` style
6727 * callback returns `true` for elements that have the properties of the given
6728 * object, else `false`.
6732 * @category Collection
6733 * @param {Array|Object|string} collection The collection to iterate over.
6734 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6736 * @param {*} [thisArg] The `this` binding of `predicate`.
6737 * @returns {Array} Returns the array of grouped elements.
6740 * _.partition([1, 2, 3], function(n) {
6743 * // => [[1, 3], [2]]
6745 * _.partition([1.2, 2.3, 3.4], function(n) {
6746 * return this.floor(n) % 2;
6748 * // => [[1.2, 3.4], [2.3]]
6751 * { 'user': 'barney', 'age': 36, 'active': false },
6752 * { 'user': 'fred', 'age': 40, 'active': true },
6753 * { 'user': 'pebbles', 'age': 1, 'active': false }
6756 * var mapper = function(array) {
6757 * return _.pluck(array, 'user');
6760 * // using the `_.matches` callback shorthand
6761 * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
6762 * // => [['pebbles'], ['barney', 'fred']]
6764 * // using the `_.matchesProperty` callback shorthand
6765 * _.map(_.partition(users, 'active', false), mapper);
6766 * // => [['barney', 'pebbles'], ['fred']]
6768 * // using the `_.property` callback shorthand
6769 * _.map(_.partition(users, 'active'), mapper);
6770 * // => [['fred'], ['barney', 'pebbles']]
6772 var partition = createAggregator(function(result, value, key) {
6773 result[key ? 0 : 1].push(value);
6774 }, function() { return [[], []]; });
6777 * Gets the property value of `path` from all elements in `collection`.
6781 * @category Collection
6782 * @param {Array|Object|string} collection The collection to iterate over.
6783 * @param {Array|string} path The path of the property to pluck.
6784 * @returns {Array} Returns the property values.
6788 * { 'user': 'barney', 'age': 36 },
6789 * { 'user': 'fred', 'age': 40 }
6792 * _.pluck(users, 'user');
6793 * // => ['barney', 'fred']
6795 * var userIndex = _.indexBy(users, 'user');
6796 * _.pluck(userIndex, 'age');
6797 * // => [36, 40] (iteration order is not guaranteed)
6799 function pluck(collection, path) {
6800 return map(collection, property(path));
6804 * Reduces `collection` to a value which is the accumulated result of running
6805 * each element in `collection` through `iteratee`, where each successive
6806 * invocation is supplied the return value of the previous. If `accumulator`
6807 * is not provided the first element of `collection` is used as the initial
6808 * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
6809 * (accumulator, value, index|key, collection).
6811 * Many lodash methods are guarded to work as iteratees for methods like
6812 * `_.reduce`, `_.reduceRight`, and `_.transform`.
6814 * The guarded methods are:
6815 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
6820 * @alias foldl, inject
6821 * @category Collection
6822 * @param {Array|Object|string} collection The collection to iterate over.
6823 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6824 * @param {*} [accumulator] The initial value.
6825 * @param {*} [thisArg] The `this` binding of `iteratee`.
6826 * @returns {*} Returns the accumulated value.
6829 * _.reduce([1, 2], function(total, n) {
6834 * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
6835 * result[key] = n * 3;
6838 * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
6840 var reduce = createReduce(arrayReduce, baseEach);
6843 * This method is like `_.reduce` except that it iterates over elements of
6844 * `collection` from right to left.
6849 * @category Collection
6850 * @param {Array|Object|string} collection The collection to iterate over.
6851 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6852 * @param {*} [accumulator] The initial value.
6853 * @param {*} [thisArg] The `this` binding of `iteratee`.
6854 * @returns {*} Returns the accumulated value.
6857 * var array = [[0, 1], [2, 3], [4, 5]];
6859 * _.reduceRight(array, function(flattened, other) {
6860 * return flattened.concat(other);
6862 * // => [4, 5, 2, 3, 0, 1]
6864 var reduceRight = createReduce(arrayReduceRight, baseEachRight);
6867 * The opposite of `_.filter`; this method returns the elements of `collection`
6868 * that `predicate` does **not** return truthy for.
6872 * @category Collection
6873 * @param {Array|Object|string} collection The collection to iterate over.
6874 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6876 * @param {*} [thisArg] The `this` binding of `predicate`.
6877 * @returns {Array} Returns the new filtered array.
6880 * _.reject([1, 2, 3, 4], function(n) {
6881 * return n % 2 == 0;
6886 * { 'user': 'barney', 'age': 36, 'active': false },
6887 * { 'user': 'fred', 'age': 40, 'active': true }
6890 * // using the `_.matches` callback shorthand
6891 * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
6894 * // using the `_.matchesProperty` callback shorthand
6895 * _.pluck(_.reject(users, 'active', false), 'user');
6898 * // using the `_.property` callback shorthand
6899 * _.pluck(_.reject(users, 'active'), 'user');
6902 function reject(collection, predicate, thisArg) {
6903 var func = isArray(collection) ? arrayFilter : baseFilter;
6904 predicate = getCallback(predicate, thisArg, 3);
6905 return func(collection, function(value, index, collection) {
6906 return !predicate(value, index, collection);
6911 * Gets a random element or `n` random elements from a collection.
6915 * @category Collection
6916 * @param {Array|Object|string} collection The collection to sample.
6917 * @param {number} [n] The number of elements to sample.
6918 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6919 * @returns {*} Returns the random sample(s).
6922 * _.sample([1, 2, 3, 4]);
6925 * _.sample([1, 2, 3, 4], 2);
6928 function sample(collection, n, guard) {
6929 if (guard ? isIterateeCall(collection, n, guard) : n == null) {
6930 collection = toIterable(collection);
6931 var length = collection.length;
6932 return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
6935 result = toArray(collection),
6936 length = result.length,
6937 lastIndex = length - 1;
6939 n = nativeMin(n < 0 ? 0 : (+n || 0), length);
6940 while (++index < n) {
6941 var rand = baseRandom(index, lastIndex),
6942 value = result[rand];
6944 result[rand] = result[index];
6945 result[index] = value;
6952 * Creates an array of shuffled values, using a version of the
6953 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
6957 * @category Collection
6958 * @param {Array|Object|string} collection The collection to shuffle.
6959 * @returns {Array} Returns the new shuffled array.
6962 * _.shuffle([1, 2, 3, 4]);
6963 * // => [4, 1, 3, 2]
6965 function shuffle(collection) {
6966 return sample(collection, POSITIVE_INFINITY);
6970 * Gets the size of `collection` by returning its length for array-like
6971 * values or the number of own enumerable properties for objects.
6975 * @category Collection
6976 * @param {Array|Object|string} collection The collection to inspect.
6977 * @returns {number} Returns the size of `collection`.
6980 * _.size([1, 2, 3]);
6983 * _.size({ 'a': 1, 'b': 2 });
6986 * _.size('pebbles');
6989 function size(collection) {
6990 var length = collection ? getLength(collection) : 0;
6991 return isLength(length) ? length : keys(collection).length;
6995 * Checks if `predicate` returns truthy for **any** element of `collection`.
6996 * The function returns as soon as it finds a passing value and does not iterate
6997 * over the entire collection. The predicate is bound to `thisArg` and invoked
6998 * with three arguments: (value, index|key, collection).
7000 * If a property name is provided for `predicate` the created `_.property`
7001 * style callback returns the property value of the given element.
7003 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7004 * style callback returns `true` for elements that have a matching property
7005 * value, else `false`.
7007 * If an object is provided for `predicate` the created `_.matches` style
7008 * callback returns `true` for elements that have the properties of the given
7009 * object, else `false`.
7014 * @category Collection
7015 * @param {Array|Object|string} collection The collection to iterate over.
7016 * @param {Function|Object|string} [predicate=_.identity] The function invoked
7018 * @param {*} [thisArg] The `this` binding of `predicate`.
7019 * @returns {boolean} Returns `true` if any element passes the predicate check,
7023 * _.some([null, 0, 'yes', false], Boolean);
7027 * { 'user': 'barney', 'active': true },
7028 * { 'user': 'fred', 'active': false }
7031 * // using the `_.matches` callback shorthand
7032 * _.some(users, { 'user': 'barney', 'active': false });
7035 * // using the `_.matchesProperty` callback shorthand
7036 * _.some(users, 'active', false);
7039 * // using the `_.property` callback shorthand
7040 * _.some(users, 'active');
7043 function some(collection, predicate, thisArg) {
7044 var func = isArray(collection) ? arraySome : baseSome;
7045 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
7046 predicate = undefined;
7048 if (typeof predicate != 'function' || thisArg !== undefined) {
7049 predicate = getCallback(predicate, thisArg, 3);
7051 return func(collection, predicate);
7055 * Creates an array of elements, sorted in ascending order by the results of
7056 * running each element in a collection through `iteratee`. This method performs
7057 * a stable sort, that is, it preserves the original sort order of equal elements.
7058 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
7059 * (value, index|key, collection).
7061 * If a property name is provided for `iteratee` the created `_.property`
7062 * style callback returns the property value of the given element.
7064 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7065 * style callback returns `true` for elements that have a matching property
7066 * value, else `false`.
7068 * If an object is provided for `iteratee` the created `_.matches` style
7069 * callback returns `true` for elements that have the properties of the given
7070 * object, else `false`.
7074 * @category Collection
7075 * @param {Array|Object|string} collection The collection to iterate over.
7076 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
7078 * @param {*} [thisArg] The `this` binding of `iteratee`.
7079 * @returns {Array} Returns the new sorted array.
7082 * _.sortBy([1, 2, 3], function(n) {
7083 * return Math.sin(n);
7087 * _.sortBy([1, 2, 3], function(n) {
7088 * return this.sin(n);
7093 * { 'user': 'fred' },
7094 * { 'user': 'pebbles' },
7095 * { 'user': 'barney' }
7098 * // using the `_.property` callback shorthand
7099 * _.pluck(_.sortBy(users, 'user'), 'user');
7100 * // => ['barney', 'fred', 'pebbles']
7102 function sortBy(collection, iteratee, thisArg) {
7103 if (collection == null) {
7106 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
7107 iteratee = undefined;
7110 iteratee = getCallback(iteratee, thisArg, 3);
7112 var result = baseMap(collection, function(value, key, collection) {
7113 return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
7115 return baseSortBy(result, compareAscending);
7119 * This method is like `_.sortBy` except that it can sort by multiple iteratees
7120 * or property names.
7122 * If a property name is provided for an iteratee the created `_.property`
7123 * style callback returns the property value of the given element.
7125 * If an object is provided for an iteratee the created `_.matches` style
7126 * callback returns `true` for elements that have the properties of the given
7127 * object, else `false`.
7131 * @category Collection
7132 * @param {Array|Object|string} collection The collection to iterate over.
7133 * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
7134 * The iteratees to sort by, specified as individual values or arrays of values.
7135 * @returns {Array} Returns the new sorted array.
7139 * { 'user': 'fred', 'age': 48 },
7140 * { 'user': 'barney', 'age': 36 },
7141 * { 'user': 'fred', 'age': 42 },
7142 * { 'user': 'barney', 'age': 34 }
7145 * _.map(_.sortByAll(users, ['user', 'age']), _.values);
7146 * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
7148 * _.map(_.sortByAll(users, 'user', function(chr) {
7149 * return Math.floor(chr.age / 10);
7151 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7153 var sortByAll = restParam(function(collection, iteratees) {
7154 if (collection == null) {
7157 var guard = iteratees[2];
7158 if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
7159 iteratees.length = 1;
7161 return baseSortByOrder(collection, baseFlatten(iteratees), []);
7165 * This method is like `_.sortByAll` except that it allows specifying the
7166 * sort orders of the iteratees to sort by. If `orders` is unspecified, all
7167 * values are sorted in ascending order. Otherwise, a value is sorted in
7168 * ascending order if its corresponding order is "asc", and descending if "desc".
7170 * If a property name is provided for an iteratee the created `_.property`
7171 * style callback returns the property value of the given element.
7173 * If an object is provided for an iteratee the created `_.matches` style
7174 * callback returns `true` for elements that have the properties of the given
7175 * object, else `false`.
7179 * @category Collection
7180 * @param {Array|Object|string} collection The collection to iterate over.
7181 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
7182 * @param {boolean[]} [orders] The sort orders of `iteratees`.
7183 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
7184 * @returns {Array} Returns the new sorted array.
7188 * { 'user': 'fred', 'age': 48 },
7189 * { 'user': 'barney', 'age': 34 },
7190 * { 'user': 'fred', 'age': 42 },
7191 * { 'user': 'barney', 'age': 36 }
7194 * // sort by `user` in ascending order and by `age` in descending order
7195 * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
7196 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7198 function sortByOrder(collection, iteratees, orders, guard) {
7199 if (collection == null) {
7202 if (guard && isIterateeCall(iteratees, orders, guard)) {
7205 if (!isArray(iteratees)) {
7206 iteratees = iteratees == null ? [] : [iteratees];
7208 if (!isArray(orders)) {
7209 orders = orders == null ? [] : [orders];
7211 return baseSortByOrder(collection, iteratees, orders);
7215 * Performs a deep comparison between each element in `collection` and the
7216 * source object, returning an array of all elements that have equivalent
7219 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
7220 * numbers, `Object` objects, regexes, and strings. Objects are compared by
7221 * their own, not inherited, enumerable properties. For comparing a single
7222 * own or inherited property value see `_.matchesProperty`.
7226 * @category Collection
7227 * @param {Array|Object|string} collection The collection to search.
7228 * @param {Object} source The object of property values to match.
7229 * @returns {Array} Returns the new filtered array.
7233 * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
7234 * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
7237 * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
7240 * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
7243 function where(collection, source) {
7244 return filter(collection, baseMatches(source));
7247 /*------------------------------------------------------------------------*/
7250 * Gets the number of milliseconds that have elapsed since the Unix epoch
7251 * (1 January 1970 00:00:00 UTC).
7258 * _.defer(function(stamp) {
7259 * console.log(_.now() - stamp);
7261 * // => logs the number of milliseconds it took for the deferred function to be invoked
7263 var now = nativeNow || function() {
7264 return new Date().getTime();
7267 /*------------------------------------------------------------------------*/
7270 * The opposite of `_.before`; this method creates a function that invokes
7271 * `func` once it is called `n` or more times.
7275 * @category Function
7276 * @param {number} n The number of calls before `func` is invoked.
7277 * @param {Function} func The function to restrict.
7278 * @returns {Function} Returns the new restricted function.
7281 * var saves = ['profile', 'settings'];
7283 * var done = _.after(saves.length, function() {
7284 * console.log('done saving!');
7287 * _.forEach(saves, function(type) {
7288 * asyncSave({ 'type': type, 'complete': done });
7290 * // => logs 'done saving!' after the two async saves have completed
7292 function after(n, func) {
7293 if (typeof func != 'function') {
7294 if (typeof n == 'function') {
7299 throw new TypeError(FUNC_ERROR_TEXT);
7302 n = nativeIsFinite(n = +n) ? n : 0;
7305 return func.apply(this, arguments);
7311 * Creates a function that accepts up to `n` arguments ignoring any
7312 * additional arguments.
7316 * @category Function
7317 * @param {Function} func The function to cap arguments for.
7318 * @param {number} [n=func.length] The arity cap.
7319 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7320 * @returns {Function} Returns the new function.
7323 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
7326 function ary(func, n, guard) {
7327 if (guard && isIterateeCall(func, n, guard)) {
7330 n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
7331 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
7335 * Creates a function that invokes `func`, with the `this` binding and arguments
7336 * of the created function, while it is called less than `n` times. Subsequent
7337 * calls to the created function return the result of the last `func` invocation.
7341 * @category Function
7342 * @param {number} n The number of calls at which `func` is no longer invoked.
7343 * @param {Function} func The function to restrict.
7344 * @returns {Function} Returns the new restricted function.
7347 * jQuery('#add').on('click', _.before(5, addContactToList));
7348 * // => allows adding up to 4 contacts to the list
7350 function before(n, func) {
7352 if (typeof func != 'function') {
7353 if (typeof n == 'function') {
7358 throw new TypeError(FUNC_ERROR_TEXT);
7363 result = func.apply(this, arguments);
7373 * Creates a function that invokes `func` with the `this` binding of `thisArg`
7374 * and prepends any additional `_.bind` arguments to those provided to the
7377 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
7378 * may be used as a placeholder for partially applied arguments.
7380 * **Note:** Unlike native `Function#bind` this method does not set the "length"
7381 * property of bound functions.
7385 * @category Function
7386 * @param {Function} func The function to bind.
7387 * @param {*} thisArg The `this` binding of `func`.
7388 * @param {...*} [partials] The arguments to be partially applied.
7389 * @returns {Function} Returns the new bound function.
7392 * var greet = function(greeting, punctuation) {
7393 * return greeting + ' ' + this.user + punctuation;
7396 * var object = { 'user': 'fred' };
7398 * var bound = _.bind(greet, object, 'hi');
7402 * // using placeholders
7403 * var bound = _.bind(greet, object, _, '!');
7407 var bind = restParam(function(func, thisArg, partials) {
7408 var bitmask = BIND_FLAG;
7409 if (partials.length) {
7410 var holders = replaceHolders(partials, bind.placeholder);
7411 bitmask |= PARTIAL_FLAG;
7413 return createWrapper(func, bitmask, thisArg, partials, holders);
7417 * Binds methods of an object to the object itself, overwriting the existing
7418 * method. Method names may be specified as individual arguments or as arrays
7419 * of method names. If no method names are provided all enumerable function
7420 * properties, own and inherited, of `object` are bound.
7422 * **Note:** This method does not set the "length" property of bound functions.
7426 * @category Function
7427 * @param {Object} object The object to bind and assign the bound methods to.
7428 * @param {...(string|string[])} [methodNames] The object method names to bind,
7429 * specified as individual method names or arrays of method names.
7430 * @returns {Object} Returns `object`.
7435 * 'onClick': function() {
7436 * console.log('clicked ' + this.label);
7441 * jQuery('#docs').on('click', view.onClick);
7442 * // => logs 'clicked docs' when the element is clicked
7444 var bindAll = restParam(function(object, methodNames) {
7445 methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
7448 length = methodNames.length;
7450 while (++index < length) {
7451 var key = methodNames[index];
7452 object[key] = createWrapper(object[key], BIND_FLAG, object);
7458 * Creates a function that invokes the method at `object[key]` and prepends
7459 * any additional `_.bindKey` arguments to those provided to the bound function.
7461 * This method differs from `_.bind` by allowing bound functions to reference
7462 * methods that may be redefined or don't yet exist.
7463 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
7466 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
7467 * builds, may be used as a placeholder for partially applied arguments.
7471 * @category Function
7472 * @param {Object} object The object the method belongs to.
7473 * @param {string} key The key of the method.
7474 * @param {...*} [partials] The arguments to be partially applied.
7475 * @returns {Function} Returns the new bound function.
7480 * 'greet': function(greeting, punctuation) {
7481 * return greeting + ' ' + this.user + punctuation;
7485 * var bound = _.bindKey(object, 'greet', 'hi');
7489 * object.greet = function(greeting, punctuation) {
7490 * return greeting + 'ya ' + this.user + punctuation;
7494 * // => 'hiya fred!'
7496 * // using placeholders
7497 * var bound = _.bindKey(object, 'greet', _, '!');
7499 * // => 'hiya fred!'
7501 var bindKey = restParam(function(object, key, partials) {
7502 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
7503 if (partials.length) {
7504 var holders = replaceHolders(partials, bindKey.placeholder);
7505 bitmask |= PARTIAL_FLAG;
7507 return createWrapper(key, bitmask, object, partials, holders);
7511 * Creates a function that accepts one or more arguments of `func` that when
7512 * called either invokes `func` returning its result, if all `func` arguments
7513 * have been provided, or returns a function that accepts one or more of the
7514 * remaining `func` arguments, and so on. The arity of `func` may be specified
7515 * if `func.length` is not sufficient.
7517 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
7518 * may be used as a placeholder for provided arguments.
7520 * **Note:** This method does not set the "length" property of curried functions.
7524 * @category Function
7525 * @param {Function} func The function to curry.
7526 * @param {number} [arity=func.length] The arity of `func`.
7527 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7528 * @returns {Function} Returns the new curried function.
7531 * var abc = function(a, b, c) {
7535 * var curried = _.curry(abc);
7546 * // using placeholders
7547 * curried(1)(_, 3)(2);
7550 var curry = createCurry(CURRY_FLAG);
7553 * This method is like `_.curry` except that arguments are applied to `func`
7554 * in the manner of `_.partialRight` instead of `_.partial`.
7556 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
7557 * builds, may be used as a placeholder for provided arguments.
7559 * **Note:** This method does not set the "length" property of curried functions.
7563 * @category Function
7564 * @param {Function} func The function to curry.
7565 * @param {number} [arity=func.length] The arity of `func`.
7566 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7567 * @returns {Function} Returns the new curried function.
7570 * var abc = function(a, b, c) {
7574 * var curried = _.curryRight(abc);
7585 * // using placeholders
7586 * curried(3)(1, _)(2);
7589 var curryRight = createCurry(CURRY_RIGHT_FLAG);
7592 * Creates a debounced function that delays invoking `func` until after `wait`
7593 * milliseconds have elapsed since the last time the debounced function was
7594 * invoked. The debounced function comes with a `cancel` method to cancel
7595 * delayed invocations. Provide an options object to indicate that `func`
7596 * should be invoked on the leading and/or trailing edge of the `wait` timeout.
7597 * Subsequent calls to the debounced function return the result of the last
7598 * `func` invocation.
7600 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
7601 * on the trailing edge of the timeout only if the the debounced function is
7602 * invoked more than once during the `wait` timeout.
7604 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
7605 * for details over the differences between `_.debounce` and `_.throttle`.
7609 * @category Function
7610 * @param {Function} func The function to debounce.
7611 * @param {number} [wait=0] The number of milliseconds to delay.
7612 * @param {Object} [options] The options object.
7613 * @param {boolean} [options.leading=false] Specify invoking on the leading
7614 * edge of the timeout.
7615 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
7616 * delayed before it is invoked.
7617 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
7618 * edge of the timeout.
7619 * @returns {Function} Returns the new debounced function.
7622 * // avoid costly calculations while the window size is in flux
7623 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
7625 * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
7626 * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
7631 * // ensure `batchLog` is invoked once after 1 second of debounced calls
7632 * var source = new EventSource('/stream');
7633 * jQuery(source).on('message', _.debounce(batchLog, 250, {
7637 * // cancel a debounced call
7638 * var todoChanges = _.debounce(batchLog, 1000);
7639 * Object.observe(models.todo, todoChanges);
7641 * Object.observe(models, function(changes) {
7642 * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
7643 * todoChanges.cancel();
7647 * // ...at some point `models.todo` is changed
7648 * models.todo.completed = true;
7650 * // ...before 1 second has passed `models.todo` is deleted
7651 * // which cancels the debounced `todoChanges` call
7652 * delete models.todo;
7654 function debounce(func, wait, options) {
7666 if (typeof func != 'function') {
7667 throw new TypeError(FUNC_ERROR_TEXT);
7669 wait = wait < 0 ? 0 : (+wait || 0);
7670 if (options === true) {
7673 } else if (isObject(options)) {
7674 leading = !!options.leading;
7675 maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
7676 trailing = 'trailing' in options ? !!options.trailing : trailing;
7681 clearTimeout(timeoutId);
7684 clearTimeout(maxTimeoutId);
7687 maxTimeoutId = timeoutId = trailingCall = undefined;
7690 function complete(isCalled, id) {
7694 maxTimeoutId = timeoutId = trailingCall = undefined;
7697 result = func.apply(thisArg, args);
7698 if (!timeoutId && !maxTimeoutId) {
7699 args = thisArg = undefined;
7704 function delayed() {
7705 var remaining = wait - (now() - stamp);
7706 if (remaining <= 0 || remaining > wait) {
7707 complete(trailingCall, maxTimeoutId);
7709 timeoutId = setTimeout(delayed, remaining);
7713 function maxDelayed() {
7714 complete(trailing, timeoutId);
7717 function debounced() {
7721 trailingCall = trailing && (timeoutId || !leading);
7723 if (maxWait === false) {
7724 var leadingCall = leading && !timeoutId;
7726 if (!maxTimeoutId && !leading) {
7729 var remaining = maxWait - (stamp - lastCalled),
7730 isCalled = remaining <= 0 || remaining > maxWait;
7734 maxTimeoutId = clearTimeout(maxTimeoutId);
7737 result = func.apply(thisArg, args);
7739 else if (!maxTimeoutId) {
7740 maxTimeoutId = setTimeout(maxDelayed, remaining);
7743 if (isCalled && timeoutId) {
7744 timeoutId = clearTimeout(timeoutId);
7746 else if (!timeoutId && wait !== maxWait) {
7747 timeoutId = setTimeout(delayed, wait);
7751 result = func.apply(thisArg, args);
7753 if (isCalled && !timeoutId && !maxTimeoutId) {
7754 args = thisArg = undefined;
7758 debounced.cancel = cancel;
7763 * Defers invoking the `func` until the current call stack has cleared. Any
7764 * additional arguments are provided to `func` when it is invoked.
7768 * @category Function
7769 * @param {Function} func The function to defer.
7770 * @param {...*} [args] The arguments to invoke the function with.
7771 * @returns {number} Returns the timer id.
7774 * _.defer(function(text) {
7775 * console.log(text);
7777 * // logs 'deferred' after one or more milliseconds
7779 var defer = restParam(function(func, args) {
7780 return baseDelay(func, 1, args);
7784 * Invokes `func` after `wait` milliseconds. Any additional arguments are
7785 * provided to `func` when it is invoked.
7789 * @category Function
7790 * @param {Function} func The function to delay.
7791 * @param {number} wait The number of milliseconds to delay invocation.
7792 * @param {...*} [args] The arguments to invoke the function with.
7793 * @returns {number} Returns the timer id.
7796 * _.delay(function(text) {
7797 * console.log(text);
7798 * }, 1000, 'later');
7799 * // => logs 'later' after one second
7801 var delay = restParam(function(func, wait, args) {
7802 return baseDelay(func, wait, args);
7806 * Creates a function that returns the result of invoking the provided
7807 * functions with the `this` binding of the created function, where each
7808 * successive invocation is supplied the return value of the previous.
7812 * @category Function
7813 * @param {...Function} [funcs] Functions to invoke.
7814 * @returns {Function} Returns the new function.
7817 * function square(n) {
7821 * var addSquare = _.flow(_.add, square);
7825 var flow = createFlow();
7828 * This method is like `_.flow` except that it creates a function that
7829 * invokes the provided functions from right to left.
7833 * @alias backflow, compose
7834 * @category Function
7835 * @param {...Function} [funcs] Functions to invoke.
7836 * @returns {Function} Returns the new function.
7839 * function square(n) {
7843 * var addSquare = _.flowRight(square, _.add);
7847 var flowRight = createFlow(true);
7850 * Creates a function that memoizes the result of `func`. If `resolver` is
7851 * provided it determines the cache key for storing the result based on the
7852 * arguments provided to the memoized function. By default, the first argument
7853 * provided to the memoized function is coerced to a string and used as the
7854 * cache key. The `func` is invoked with the `this` binding of the memoized
7857 * **Note:** The cache is exposed as the `cache` property on the memoized
7858 * function. Its creation may be customized by replacing the `_.memoize.Cache`
7859 * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
7860 * method interface of `get`, `has`, and `set`.
7864 * @category Function
7865 * @param {Function} func The function to have its output memoized.
7866 * @param {Function} [resolver] The function to resolve the cache key.
7867 * @returns {Function} Returns the new memoizing function.
7870 * var upperCase = _.memoize(function(string) {
7871 * return string.toUpperCase();
7874 * upperCase('fred');
7877 * // modifying the result cache
7878 * upperCase.cache.set('fred', 'BARNEY');
7879 * upperCase('fred');
7882 * // replacing `_.memoize.Cache`
7883 * var object = { 'user': 'fred' };
7884 * var other = { 'user': 'barney' };
7885 * var identity = _.memoize(_.identity);
7888 * // => { 'user': 'fred' }
7890 * // => { 'user': 'fred' }
7892 * _.memoize.Cache = WeakMap;
7893 * var identity = _.memoize(_.identity);
7896 * // => { 'user': 'fred' }
7898 * // => { 'user': 'barney' }
7900 function memoize(func, resolver) {
7901 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
7902 throw new TypeError(FUNC_ERROR_TEXT);
7904 var memoized = function() {
7905 var args = arguments,
7906 key = resolver ? resolver.apply(this, args) : args[0],
7907 cache = memoized.cache;
7909 if (cache.has(key)) {
7910 return cache.get(key);
7912 var result = func.apply(this, args);
7913 memoized.cache = cache.set(key, result);
7916 memoized.cache = new memoize.Cache;
7921 * Creates a function that runs each argument through a corresponding
7922 * transform function.
7926 * @category Function
7927 * @param {Function} func The function to wrap.
7928 * @param {...(Function|Function[])} [transforms] The functions to transform
7929 * arguments, specified as individual functions or arrays of functions.
7930 * @returns {Function} Returns the new function.
7933 * function doubled(n) {
7937 * function square(n) {
7941 * var modded = _.modArgs(function(x, y) {
7943 * }, square, doubled);
7951 var modArgs = restParam(function(func, transforms) {
7952 transforms = baseFlatten(transforms);
7953 if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
7954 throw new TypeError(FUNC_ERROR_TEXT);
7956 var length = transforms.length;
7957 return restParam(function(args) {
7958 var index = nativeMin(args.length, length);
7960 args[index] = transforms[index](args[index]);
7962 return func.apply(this, args);
7967 * Creates a function that negates the result of the predicate `func`. The
7968 * `func` predicate is invoked with the `this` binding and arguments of the
7973 * @category Function
7974 * @param {Function} predicate The predicate to negate.
7975 * @returns {Function} Returns the new function.
7978 * function isEven(n) {
7979 * return n % 2 == 0;
7982 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
7985 function negate(predicate) {
7986 if (typeof predicate != 'function') {
7987 throw new TypeError(FUNC_ERROR_TEXT);
7990 return !predicate.apply(this, arguments);
7995 * Creates a function that is restricted to invoking `func` once. Repeat calls
7996 * to the function return the value of the first call. The `func` is invoked
7997 * with the `this` binding and arguments of the created function.
8001 * @category Function
8002 * @param {Function} func The function to restrict.
8003 * @returns {Function} Returns the new restricted function.
8006 * var initialize = _.once(createApplication);
8009 * // `initialize` invokes `createApplication` once
8011 function once(func) {
8012 return before(2, func);
8016 * Creates a function that invokes `func` with `partial` arguments prepended
8017 * to those provided to the new function. This method is like `_.bind` except
8018 * it does **not** alter the `this` binding.
8020 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
8021 * builds, may be used as a placeholder for partially applied arguments.
8023 * **Note:** This method does not set the "length" property of partially
8024 * applied functions.
8028 * @category Function
8029 * @param {Function} func The function to partially apply arguments to.
8030 * @param {...*} [partials] The arguments to be partially applied.
8031 * @returns {Function} Returns the new partially applied function.
8034 * var greet = function(greeting, name) {
8035 * return greeting + ' ' + name;
8038 * var sayHelloTo = _.partial(greet, 'hello');
8039 * sayHelloTo('fred');
8040 * // => 'hello fred'
8042 * // using placeholders
8043 * var greetFred = _.partial(greet, _, 'fred');
8047 var partial = createPartial(PARTIAL_FLAG);
8050 * This method is like `_.partial` except that partially applied arguments
8051 * are appended to those provided to the new function.
8053 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
8054 * builds, may be used as a placeholder for partially applied arguments.
8056 * **Note:** This method does not set the "length" property of partially
8057 * applied functions.
8061 * @category Function
8062 * @param {Function} func The function to partially apply arguments to.
8063 * @param {...*} [partials] The arguments to be partially applied.
8064 * @returns {Function} Returns the new partially applied function.
8067 * var greet = function(greeting, name) {
8068 * return greeting + ' ' + name;
8071 * var greetFred = _.partialRight(greet, 'fred');
8075 * // using placeholders
8076 * var sayHelloTo = _.partialRight(greet, 'hello', _);
8077 * sayHelloTo('fred');
8078 * // => 'hello fred'
8080 var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
8083 * Creates a function that invokes `func` with arguments arranged according
8084 * to the specified indexes where the argument value at the first index is
8085 * provided as the first argument, the argument value at the second index is
8086 * provided as the second argument, and so on.
8090 * @category Function
8091 * @param {Function} func The function to rearrange arguments for.
8092 * @param {...(number|number[])} indexes The arranged argument indexes,
8093 * specified as individual indexes or arrays of indexes.
8094 * @returns {Function} Returns the new function.
8097 * var rearged = _.rearg(function(a, b, c) {
8101 * rearged('b', 'c', 'a')
8102 * // => ['a', 'b', 'c']
8104 * var map = _.rearg(_.map, [1, 0]);
8110 var rearg = restParam(function(func, indexes) {
8111 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
8115 * Creates a function that invokes `func` with the `this` binding of the
8116 * created function and arguments from `start` and beyond provided as an array.
8118 * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
8122 * @category Function
8123 * @param {Function} func The function to apply a rest parameter to.
8124 * @param {number} [start=func.length-1] The start position of the rest parameter.
8125 * @returns {Function} Returns the new function.
8128 * var say = _.restParam(function(what, names) {
8129 * return what + ' ' + _.initial(names).join(', ') +
8130 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
8133 * say('hello', 'fred', 'barney', 'pebbles');
8134 * // => 'hello fred, barney, & pebbles'
8136 function restParam(func, start) {
8137 if (typeof func != 'function') {
8138 throw new TypeError(FUNC_ERROR_TEXT);
8140 start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
8142 var args = arguments,
8144 length = nativeMax(args.length - start, 0),
8145 rest = Array(length);
8147 while (++index < length) {
8148 rest[index] = args[start + index];
8151 case 0: return func.call(this, rest);
8152 case 1: return func.call(this, args[0], rest);
8153 case 2: return func.call(this, args[0], args[1], rest);
8155 var otherArgs = Array(start + 1);
8157 while (++index < start) {
8158 otherArgs[index] = args[index];
8160 otherArgs[start] = rest;
8161 return func.apply(this, otherArgs);
8166 * Creates a function that invokes `func` with the `this` binding of the created
8167 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
8169 * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
8173 * @category Function
8174 * @param {Function} func The function to spread arguments over.
8175 * @returns {Function} Returns the new function.
8178 * var say = _.spread(function(who, what) {
8179 * return who + ' says ' + what;
8182 * say(['fred', 'hello']);
8183 * // => 'fred says hello'
8186 * var numbers = Promise.all([
8187 * Promise.resolve(40),
8188 * Promise.resolve(36)
8191 * numbers.then(_.spread(function(x, y) {
8194 * // => a Promise of 76
8196 function spread(func) {
8197 if (typeof func != 'function') {
8198 throw new TypeError(FUNC_ERROR_TEXT);
8200 return function(array) {
8201 return func.apply(this, array);
8206 * Creates a throttled function that only invokes `func` at most once per
8207 * every `wait` milliseconds. The throttled function comes with a `cancel`
8208 * method to cancel delayed invocations. Provide an options object to indicate
8209 * that `func` should be invoked on the leading and/or trailing edge of the
8210 * `wait` timeout. Subsequent calls to the throttled function return the
8211 * result of the last `func` call.
8213 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8214 * on the trailing edge of the timeout only if the the throttled function is
8215 * invoked more than once during the `wait` timeout.
8217 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8218 * for details over the differences between `_.throttle` and `_.debounce`.
8222 * @category Function
8223 * @param {Function} func The function to throttle.
8224 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
8225 * @param {Object} [options] The options object.
8226 * @param {boolean} [options.leading=true] Specify invoking on the leading
8227 * edge of the timeout.
8228 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8229 * edge of the timeout.
8230 * @returns {Function} Returns the new throttled function.
8233 * // avoid excessively updating the position while scrolling
8234 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
8236 * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
8237 * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
8241 * // cancel a trailing throttled call
8242 * jQuery(window).on('popstate', throttled.cancel);
8244 function throttle(func, wait, options) {
8248 if (typeof func != 'function') {
8249 throw new TypeError(FUNC_ERROR_TEXT);
8251 if (options === false) {
8253 } else if (isObject(options)) {
8254 leading = 'leading' in options ? !!options.leading : leading;
8255 trailing = 'trailing' in options ? !!options.trailing : trailing;
8257 return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
8261 * Creates a function that provides `value` to the wrapper function as its
8262 * first argument. Any additional arguments provided to the function are
8263 * appended to those provided to the wrapper function. The wrapper is invoked
8264 * with the `this` binding of the created function.
8268 * @category Function
8269 * @param {*} value The value to wrap.
8270 * @param {Function} wrapper The wrapper function.
8271 * @returns {Function} Returns the new function.
8274 * var p = _.wrap(_.escape, function(func, text) {
8275 * return '<p>' + func(text) + '</p>';
8278 * p('fred, barney, & pebbles');
8279 * // => '<p>fred, barney, & pebbles</p>'
8281 function wrap(value, wrapper) {
8282 wrapper = wrapper == null ? identity : wrapper;
8283 return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
8286 /*------------------------------------------------------------------------*/
8289 * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
8290 * otherwise they are assigned by reference. If `customizer` is provided it is
8291 * invoked to produce the cloned values. If `customizer` returns `undefined`
8292 * cloning is handled by the method instead. The `customizer` is bound to
8293 * `thisArg` and invoked with two argument; (value [, index|key, object]).
8295 * **Note:** This method is loosely based on the
8296 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8297 * The enumerable properties of `arguments` objects and objects created by
8298 * constructors other than `Object` are cloned to plain `Object` objects. An
8299 * empty object is returned for uncloneable values such as functions, DOM nodes,
8300 * Maps, Sets, and WeakMaps.
8305 * @param {*} value The value to clone.
8306 * @param {boolean} [isDeep] Specify a deep clone.
8307 * @param {Function} [customizer] The function to customize cloning values.
8308 * @param {*} [thisArg] The `this` binding of `customizer`.
8309 * @returns {*} Returns the cloned value.
8313 * { 'user': 'barney' },
8314 * { 'user': 'fred' }
8317 * var shallow = _.clone(users);
8318 * shallow[0] === users[0];
8321 * var deep = _.clone(users, true);
8322 * deep[0] === users[0];
8325 * // using a customizer callback
8326 * var el = _.clone(document.body, function(value) {
8327 * if (_.isElement(value)) {
8328 * return value.cloneNode(false);
8332 * el === document.body
8336 * el.childNodes.length;
8339 function clone(value, isDeep, customizer, thisArg) {
8340 if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
8343 else if (typeof isDeep == 'function') {
8344 thisArg = customizer;
8345 customizer = isDeep;
8348 return typeof customizer == 'function'
8349 ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))
8350 : baseClone(value, isDeep);
8354 * Creates a deep clone of `value`. If `customizer` is provided it is invoked
8355 * to produce the cloned values. If `customizer` returns `undefined` cloning
8356 * is handled by the method instead. The `customizer` is bound to `thisArg`
8357 * and invoked with two argument; (value [, index|key, object]).
8359 * **Note:** This method is loosely based on the
8360 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8361 * The enumerable properties of `arguments` objects and objects created by
8362 * constructors other than `Object` are cloned to plain `Object` objects. An
8363 * empty object is returned for uncloneable values such as functions, DOM nodes,
8364 * Maps, Sets, and WeakMaps.
8369 * @param {*} value The value to deep clone.
8370 * @param {Function} [customizer] The function to customize cloning values.
8371 * @param {*} [thisArg] The `this` binding of `customizer`.
8372 * @returns {*} Returns the deep cloned value.
8376 * { 'user': 'barney' },
8377 * { 'user': 'fred' }
8380 * var deep = _.cloneDeep(users);
8381 * deep[0] === users[0];
8384 * // using a customizer callback
8385 * var el = _.cloneDeep(document.body, function(value) {
8386 * if (_.isElement(value)) {
8387 * return value.cloneNode(true);
8391 * el === document.body
8395 * el.childNodes.length;
8398 function cloneDeep(value, customizer, thisArg) {
8399 return typeof customizer == 'function'
8400 ? baseClone(value, true, bindCallback(customizer, thisArg, 1))
8401 : baseClone(value, true);
8405 * Checks if `value` is greater than `other`.
8410 * @param {*} value The value to compare.
8411 * @param {*} other The other value to compare.
8412 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
8424 function gt(value, other) {
8425 return value > other;
8429 * Checks if `value` is greater than or equal to `other`.
8434 * @param {*} value The value to compare.
8435 * @param {*} other The other value to compare.
8436 * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
8448 function gte(value, other) {
8449 return value >= other;
8453 * Checks if `value` is classified as an `arguments` object.
8458 * @param {*} value The value to check.
8459 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8462 * _.isArguments(function() { return arguments; }());
8465 * _.isArguments([1, 2, 3]);
8468 function isArguments(value) {
8469 return isObjectLike(value) && isArrayLike(value) &&
8470 hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
8474 * Checks if `value` is classified as an `Array` object.
8479 * @param {*} value The value to check.
8480 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8483 * _.isArray([1, 2, 3]);
8486 * _.isArray(function() { return arguments; }());
8489 var isArray = nativeIsArray || function(value) {
8490 return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
8494 * Checks if `value` is classified as a boolean primitive or object.
8499 * @param {*} value The value to check.
8500 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8503 * _.isBoolean(false);
8506 * _.isBoolean(null);
8509 function isBoolean(value) {
8510 return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
8514 * Checks if `value` is classified as a `Date` object.
8519 * @param {*} value The value to check.
8520 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8523 * _.isDate(new Date);
8526 * _.isDate('Mon April 23 2012');
8529 function isDate(value) {
8530 return isObjectLike(value) && objToString.call(value) == dateTag;
8534 * Checks if `value` is a DOM element.
8539 * @param {*} value The value to check.
8540 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
8543 * _.isElement(document.body);
8546 * _.isElement('<body>');
8549 function isElement(value) {
8550 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
8554 * Checks if `value` is empty. A value is considered empty unless it is an
8555 * `arguments` object, array, string, or jQuery-like collection with a length
8556 * greater than `0` or an object with own enumerable properties.
8561 * @param {Array|Object|string} value The value to inspect.
8562 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
8574 * _.isEmpty([1, 2, 3]);
8577 * _.isEmpty({ 'a': 1 });
8580 function isEmpty(value) {
8581 if (value == null) {
8584 if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
8585 (isObjectLike(value) && isFunction(value.splice)))) {
8586 return !value.length;
8588 return !keys(value).length;
8592 * Performs a deep comparison between two values to determine if they are
8593 * equivalent. If `customizer` is provided it is invoked to compare values.
8594 * If `customizer` returns `undefined` comparisons are handled by the method
8595 * instead. The `customizer` is bound to `thisArg` and invoked with three
8596 * arguments: (value, other [, index|key]).
8598 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
8599 * numbers, `Object` objects, regexes, and strings. Objects are compared by
8600 * their own, not inherited, enumerable properties. Functions and DOM nodes
8601 * are **not** supported. Provide a customizer function to extend support
8602 * for comparing other values.
8608 * @param {*} value The value to compare.
8609 * @param {*} other The other value to compare.
8610 * @param {Function} [customizer] The function to customize value comparisons.
8611 * @param {*} [thisArg] The `this` binding of `customizer`.
8612 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
8615 * var object = { 'user': 'fred' };
8616 * var other = { 'user': 'fred' };
8621 * _.isEqual(object, other);
8624 * // using a customizer callback
8625 * var array = ['hello', 'goodbye'];
8626 * var other = ['hi', 'goodbye'];
8628 * _.isEqual(array, other, function(value, other) {
8629 * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
8635 function isEqual(value, other, customizer, thisArg) {
8636 customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
8637 var result = customizer ? customizer(value, other) : undefined;
8638 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
8642 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
8643 * `SyntaxError`, `TypeError`, or `URIError` object.
8648 * @param {*} value The value to check.
8649 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
8652 * _.isError(new Error);
8658 function isError(value) {
8659 return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
8663 * Checks if `value` is a finite primitive number.
8665 * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
8670 * @param {*} value The value to check.
8671 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
8683 * _.isFinite(Object(10));
8686 * _.isFinite(Infinity);
8689 function isFinite(value) {
8690 return typeof value == 'number' && nativeIsFinite(value);
8694 * Checks if `value` is classified as a `Function` object.
8699 * @param {*} value The value to check.
8700 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8706 * _.isFunction(/abc/);
8709 function isFunction(value) {
8710 // The use of `Object#toString` avoids issues with the `typeof` operator
8711 // in older versions of Chrome and Safari which return 'function' for regexes
8712 // and Safari 8 equivalents which return 'object' for typed array constructors.
8713 return isObject(value) && objToString.call(value) == funcTag;
8717 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
8718 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
8723 * @param {*} value The value to check.
8724 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
8730 * _.isObject([1, 2, 3]);
8736 function isObject(value) {
8737 // Avoid a V8 JIT bug in Chrome 19-20.
8738 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
8739 var type = typeof value;
8740 return !!value && (type == 'object' || type == 'function');
8744 * Performs a deep comparison between `object` and `source` to determine if
8745 * `object` contains equivalent property values. If `customizer` is provided
8746 * it is invoked to compare values. If `customizer` returns `undefined`
8747 * comparisons are handled by the method instead. The `customizer` is bound
8748 * to `thisArg` and invoked with three arguments: (value, other, index|key).
8750 * **Note:** This method supports comparing properties of arrays, booleans,
8751 * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
8752 * and DOM nodes are **not** supported. Provide a customizer function to extend
8753 * support for comparing other values.
8758 * @param {Object} object The object to inspect.
8759 * @param {Object} source The object of property values to match.
8760 * @param {Function} [customizer] The function to customize value comparisons.
8761 * @param {*} [thisArg] The `this` binding of `customizer`.
8762 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
8765 * var object = { 'user': 'fred', 'age': 40 };
8767 * _.isMatch(object, { 'age': 40 });
8770 * _.isMatch(object, { 'age': 36 });
8773 * // using a customizer callback
8774 * var object = { 'greeting': 'hello' };
8775 * var source = { 'greeting': 'hi' };
8777 * _.isMatch(object, source, function(value, other) {
8778 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
8782 function isMatch(object, source, customizer, thisArg) {
8783 customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
8784 return baseIsMatch(object, getMatchData(source), customizer);
8788 * Checks if `value` is `NaN`.
8790 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
8791 * which returns `true` for `undefined` and other non-numeric values.
8796 * @param {*} value The value to check.
8797 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
8803 * _.isNaN(new Number(NaN));
8809 * _.isNaN(undefined);
8812 function isNaN(value) {
8813 // An `NaN` primitive is the only value that is not equal to itself.
8814 // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
8815 return isNumber(value) && value != +value;
8819 * Checks if `value` is a native function.
8824 * @param {*} value The value to check.
8825 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
8828 * _.isNative(Array.prototype.push);
8834 function isNative(value) {
8835 if (value == null) {
8838 if (isFunction(value)) {
8839 return reIsNative.test(fnToString.call(value));
8841 return isObjectLike(value) && reIsHostCtor.test(value);
8845 * Checks if `value` is `null`.
8850 * @param {*} value The value to check.
8851 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
8860 function isNull(value) {
8861 return value === null;
8865 * Checks if `value` is classified as a `Number` primitive or object.
8867 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
8868 * as numbers, use the `_.isFinite` method.
8873 * @param {*} value The value to check.
8874 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8883 * _.isNumber('8.4');
8886 function isNumber(value) {
8887 return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
8891 * Checks if `value` is a plain object, that is, an object created by the
8892 * `Object` constructor or one with a `[[Prototype]]` of `null`.
8894 * **Note:** This method assumes objects created by the `Object` constructor
8895 * have no inherited enumerable properties.
8900 * @param {*} value The value to check.
8901 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
8908 * _.isPlainObject(new Foo);
8911 * _.isPlainObject([1, 2, 3]);
8914 * _.isPlainObject({ 'x': 0, 'y': 0 });
8917 * _.isPlainObject(Object.create(null));
8920 function isPlainObject(value) {
8923 // Exit early for non `Object` objects.
8924 if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
8925 (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
8928 // IE < 9 iterates inherited properties before own properties. If the first
8929 // iterated property is an object's own property then there are no inherited
8930 // enumerable properties.
8932 // In most environments an object's own properties are iterated before
8933 // its inherited properties. If the last iterated property is an object's
8934 // own property then there are no inherited enumerable properties.
8935 baseForIn(value, function(subValue, key) {
8938 return result === undefined || hasOwnProperty.call(value, result);
8942 * Checks if `value` is classified as a `RegExp` object.
8947 * @param {*} value The value to check.
8948 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8951 * _.isRegExp(/abc/);
8954 * _.isRegExp('/abc/');
8957 function isRegExp(value) {
8958 return isObject(value) && objToString.call(value) == regexpTag;
8962 * Checks if `value` is classified as a `String` primitive or object.
8967 * @param {*} value The value to check.
8968 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8971 * _.isString('abc');
8977 function isString(value) {
8978 return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
8982 * Checks if `value` is classified as a typed array.
8987 * @param {*} value The value to check.
8988 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8991 * _.isTypedArray(new Uint8Array);
8994 * _.isTypedArray([]);
8997 function isTypedArray(value) {
8998 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
9002 * Checks if `value` is `undefined`.
9007 * @param {*} value The value to check.
9008 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
9011 * _.isUndefined(void 0);
9014 * _.isUndefined(null);
9017 function isUndefined(value) {
9018 return value === undefined;
9022 * Checks if `value` is less than `other`.
9027 * @param {*} value The value to compare.
9028 * @param {*} other The other value to compare.
9029 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
9041 function lt(value, other) {
9042 return value < other;
9046 * Checks if `value` is less than or equal to `other`.
9051 * @param {*} value The value to compare.
9052 * @param {*} other The other value to compare.
9053 * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
9065 function lte(value, other) {
9066 return value <= other;
9070 * Converts `value` to an array.
9075 * @param {*} value The value to convert.
9076 * @returns {Array} Returns the converted array.
9080 * return _.toArray(arguments).slice(1);
9084 function toArray(value) {
9085 var length = value ? getLength(value) : 0;
9086 if (!isLength(length)) {
9087 return values(value);
9092 return arrayCopy(value);
9096 * Converts `value` to a plain object flattening inherited enumerable
9097 * properties of `value` to own properties of the plain object.
9102 * @param {*} value The value to convert.
9103 * @returns {Object} Returns the converted plain object.
9110 * Foo.prototype.c = 3;
9112 * _.assign({ 'a': 1 }, new Foo);
9113 * // => { 'a': 1, 'b': 2 }
9115 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
9116 * // => { 'a': 1, 'b': 2, 'c': 3 }
9118 function toPlainObject(value) {
9119 return baseCopy(value, keysIn(value));
9122 /*------------------------------------------------------------------------*/
9125 * Recursively merges own enumerable properties of the source object(s), that
9126 * don't resolve to `undefined` into the destination object. Subsequent sources
9127 * overwrite property assignments of previous sources. If `customizer` is
9128 * provided it is invoked to produce the merged values of the destination and
9129 * source properties. If `customizer` returns `undefined` merging is handled
9130 * by the method instead. The `customizer` is bound to `thisArg` and invoked
9131 * with five arguments: (objectValue, sourceValue, key, object, source).
9136 * @param {Object} object The destination object.
9137 * @param {...Object} [sources] The source objects.
9138 * @param {Function} [customizer] The function to customize assigned values.
9139 * @param {*} [thisArg] The `this` binding of `customizer`.
9140 * @returns {Object} Returns `object`.
9144 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
9148 * 'data': [{ 'age': 36 }, { 'age': 40 }]
9151 * _.merge(users, ages);
9152 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
9154 * // using a customizer callback
9156 * 'fruits': ['apple'],
9157 * 'vegetables': ['beet']
9161 * 'fruits': ['banana'],
9162 * 'vegetables': ['carrot']
9165 * _.merge(object, other, function(a, b) {
9166 * if (_.isArray(a)) {
9167 * return a.concat(b);
9170 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
9172 var merge = createAssigner(baseMerge);
9175 * Assigns own enumerable properties of source object(s) to the destination
9176 * object. Subsequent sources overwrite property assignments of previous sources.
9177 * If `customizer` is provided it is invoked to produce the assigned values.
9178 * The `customizer` is bound to `thisArg` and invoked with five arguments:
9179 * (objectValue, sourceValue, key, object, source).
9181 * **Note:** This method mutates `object` and is based on
9182 * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
9188 * @param {Object} object The destination object.
9189 * @param {...Object} [sources] The source objects.
9190 * @param {Function} [customizer] The function to customize assigned values.
9191 * @param {*} [thisArg] The `this` binding of `customizer`.
9192 * @returns {Object} Returns `object`.
9195 * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
9196 * // => { 'user': 'fred', 'age': 40 }
9198 * // using a customizer callback
9199 * var defaults = _.partialRight(_.assign, function(value, other) {
9200 * return _.isUndefined(value) ? other : value;
9203 * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9204 * // => { 'user': 'barney', 'age': 36 }
9206 var assign = createAssigner(function(object, source, customizer) {
9208 ? assignWith(object, source, customizer)
9209 : baseAssign(object, source);
9213 * Creates an object that inherits from the given `prototype` object. If a
9214 * `properties` object is provided its own enumerable properties are assigned
9215 * to the created object.
9220 * @param {Object} prototype The object to inherit from.
9221 * @param {Object} [properties] The properties to assign to the object.
9222 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9223 * @returns {Object} Returns the new object.
9226 * function Shape() {
9231 * function Circle() {
9235 * Circle.prototype = _.create(Shape.prototype, {
9236 * 'constructor': Circle
9239 * var circle = new Circle;
9240 * circle instanceof Circle;
9243 * circle instanceof Shape;
9246 function create(prototype, properties, guard) {
9247 var result = baseCreate(prototype);
9248 if (guard && isIterateeCall(prototype, properties, guard)) {
9249 properties = undefined;
9251 return properties ? baseAssign(result, properties) : result;
9255 * Assigns own enumerable properties of source object(s) to the destination
9256 * object for all destination properties that resolve to `undefined`. Once a
9257 * property is set, additional values of the same property are ignored.
9259 * **Note:** This method mutates `object`.
9264 * @param {Object} object The destination object.
9265 * @param {...Object} [sources] The source objects.
9266 * @returns {Object} Returns `object`.
9269 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9270 * // => { 'user': 'barney', 'age': 36 }
9272 var defaults = createDefaults(assign, assignDefaults);
9275 * This method is like `_.defaults` except that it recursively assigns
9276 * default properties.
9278 * **Note:** This method mutates `object`.
9283 * @param {Object} object The destination object.
9284 * @param {...Object} [sources] The source objects.
9285 * @returns {Object} Returns `object`.
9288 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
9289 * // => { 'user': { 'name': 'barney', 'age': 36 } }
9292 var defaultsDeep = createDefaults(merge, mergeDefaults);
9295 * This method is like `_.find` except that it returns the key of the first
9296 * element `predicate` returns truthy for instead of the element itself.
9298 * If a property name is provided for `predicate` the created `_.property`
9299 * style callback returns the property value of the given element.
9301 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9302 * style callback returns `true` for elements that have a matching property
9303 * value, else `false`.
9305 * If an object is provided for `predicate` the created `_.matches` style
9306 * callback returns `true` for elements that have the properties of the given
9307 * object, else `false`.
9312 * @param {Object} object The object to search.
9313 * @param {Function|Object|string} [predicate=_.identity] The function invoked
9315 * @param {*} [thisArg] The `this` binding of `predicate`.
9316 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9320 * 'barney': { 'age': 36, 'active': true },
9321 * 'fred': { 'age': 40, 'active': false },
9322 * 'pebbles': { 'age': 1, 'active': true }
9325 * _.findKey(users, function(chr) {
9326 * return chr.age < 40;
9328 * // => 'barney' (iteration order is not guaranteed)
9330 * // using the `_.matches` callback shorthand
9331 * _.findKey(users, { 'age': 1, 'active': true });
9334 * // using the `_.matchesProperty` callback shorthand
9335 * _.findKey(users, 'active', false);
9338 * // using the `_.property` callback shorthand
9339 * _.findKey(users, 'active');
9342 var findKey = createFindKey(baseForOwn);
9345 * This method is like `_.findKey` except that it iterates over elements of
9346 * a collection in the opposite order.
9348 * If a property name is provided for `predicate` the created `_.property`
9349 * style callback returns the property value of the given element.
9351 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9352 * style callback returns `true` for elements that have a matching property
9353 * value, else `false`.
9355 * If an object is provided for `predicate` the created `_.matches` style
9356 * callback returns `true` for elements that have the properties of the given
9357 * object, else `false`.
9362 * @param {Object} object The object to search.
9363 * @param {Function|Object|string} [predicate=_.identity] The function invoked
9365 * @param {*} [thisArg] The `this` binding of `predicate`.
9366 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9370 * 'barney': { 'age': 36, 'active': true },
9371 * 'fred': { 'age': 40, 'active': false },
9372 * 'pebbles': { 'age': 1, 'active': true }
9375 * _.findLastKey(users, function(chr) {
9376 * return chr.age < 40;
9378 * // => returns `pebbles` assuming `_.findKey` returns `barney`
9380 * // using the `_.matches` callback shorthand
9381 * _.findLastKey(users, { 'age': 36, 'active': true });
9384 * // using the `_.matchesProperty` callback shorthand
9385 * _.findLastKey(users, 'active', false);
9388 * // using the `_.property` callback shorthand
9389 * _.findLastKey(users, 'active');
9392 var findLastKey = createFindKey(baseForOwnRight);
9395 * Iterates over own and inherited enumerable properties of an object invoking
9396 * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
9397 * with three arguments: (value, key, object). Iteratee functions may exit
9398 * iteration early by explicitly returning `false`.
9403 * @param {Object} object The object to iterate over.
9404 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9405 * @param {*} [thisArg] The `this` binding of `iteratee`.
9406 * @returns {Object} Returns `object`.
9414 * Foo.prototype.c = 3;
9416 * _.forIn(new Foo, function(value, key) {
9419 * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
9421 var forIn = createForIn(baseFor);
9424 * This method is like `_.forIn` except that it iterates over properties of
9425 * `object` in the opposite order.
9430 * @param {Object} object The object to iterate over.
9431 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9432 * @param {*} [thisArg] The `this` binding of `iteratee`.
9433 * @returns {Object} Returns `object`.
9441 * Foo.prototype.c = 3;
9443 * _.forInRight(new Foo, function(value, key) {
9446 * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
9448 var forInRight = createForIn(baseForRight);
9451 * Iterates over own enumerable properties of an object invoking `iteratee`
9452 * for each property. The `iteratee` is bound to `thisArg` and invoked with
9453 * three arguments: (value, key, object). Iteratee functions may exit iteration
9454 * early by explicitly returning `false`.
9459 * @param {Object} object The object to iterate over.
9460 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9461 * @param {*} [thisArg] The `this` binding of `iteratee`.
9462 * @returns {Object} Returns `object`.
9470 * Foo.prototype.c = 3;
9472 * _.forOwn(new Foo, function(value, key) {
9475 * // => logs 'a' and 'b' (iteration order is not guaranteed)
9477 var forOwn = createForOwn(baseForOwn);
9480 * This method is like `_.forOwn` except that it iterates over properties of
9481 * `object` in the opposite order.
9486 * @param {Object} object The object to iterate over.
9487 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9488 * @param {*} [thisArg] The `this` binding of `iteratee`.
9489 * @returns {Object} Returns `object`.
9497 * Foo.prototype.c = 3;
9499 * _.forOwnRight(new Foo, function(value, key) {
9502 * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
9504 var forOwnRight = createForOwn(baseForOwnRight);
9507 * Creates an array of function property names from all enumerable properties,
9508 * own and inherited, of `object`.
9514 * @param {Object} object The object to inspect.
9515 * @returns {Array} Returns the new array of property names.
9519 * // => ['after', 'ary', 'assign', ...]
9521 function functions(object) {
9522 return baseFunctions(object, keysIn(object));
9526 * Gets the property value at `path` of `object`. If the resolved value is
9527 * `undefined` the `defaultValue` is used in its place.
9532 * @param {Object} object The object to query.
9533 * @param {Array|string} path The path of the property to get.
9534 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9535 * @returns {*} Returns the resolved value.
9538 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9540 * _.get(object, 'a[0].b.c');
9543 * _.get(object, ['a', '0', 'b', 'c']);
9546 * _.get(object, 'a.b.c', 'default');
9549 function get(object, path, defaultValue) {
9550 var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
9551 return result === undefined ? defaultValue : result;
9555 * Checks if `path` is a direct property.
9560 * @param {Object} object The object to query.
9561 * @param {Array|string} path The path to check.
9562 * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
9565 * var object = { 'a': { 'b': { 'c': 3 } } };
9567 * _.has(object, 'a');
9570 * _.has(object, 'a.b.c');
9573 * _.has(object, ['a', 'b', 'c']);
9576 function has(object, path) {
9577 if (object == null) {
9580 var result = hasOwnProperty.call(object, path);
9581 if (!result && !isKey(path)) {
9582 path = toPath(path);
9583 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9584 if (object == null) {
9588 result = hasOwnProperty.call(object, path);
9590 return result || (isLength(object.length) && isIndex(path, object.length) &&
9591 (isArray(object) || isArguments(object)));
9595 * Creates an object composed of the inverted keys and values of `object`.
9596 * If `object` contains duplicate values, subsequent values overwrite property
9597 * assignments of previous values unless `multiValue` is `true`.
9602 * @param {Object} object The object to invert.
9603 * @param {boolean} [multiValue] Allow multiple values per key.
9604 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9605 * @returns {Object} Returns the new inverted object.
9608 * var object = { 'a': 1, 'b': 2, 'c': 1 };
9611 * // => { '1': 'c', '2': 'b' }
9613 * // with `multiValue`
9614 * _.invert(object, true);
9615 * // => { '1': ['a', 'c'], '2': ['b'] }
9617 function invert(object, multiValue, guard) {
9618 if (guard && isIterateeCall(object, multiValue, guard)) {
9619 multiValue = undefined;
9622 props = keys(object),
9623 length = props.length,
9626 while (++index < length) {
9627 var key = props[index],
9628 value = object[key];
9631 if (hasOwnProperty.call(result, value)) {
9632 result[value].push(key);
9634 result[value] = [key];
9638 result[value] = key;
9645 * Creates an array of the own enumerable property names of `object`.
9647 * **Note:** Non-object values are coerced to objects. See the
9648 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
9654 * @param {Object} object The object to query.
9655 * @returns {Array} Returns the array of property names.
9663 * Foo.prototype.c = 3;
9666 * // => ['a', 'b'] (iteration order is not guaranteed)
9671 var keys = !nativeKeys ? shimKeys : function(object) {
9672 var Ctor = object == null ? undefined : object.constructor;
9673 if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
9674 (typeof object != 'function' && isArrayLike(object))) {
9675 return shimKeys(object);
9677 return isObject(object) ? nativeKeys(object) : [];
9681 * Creates an array of the own and inherited enumerable property names of `object`.
9683 * **Note:** Non-object values are coerced to objects.
9688 * @param {Object} object The object to query.
9689 * @returns {Array} Returns the array of property names.
9697 * Foo.prototype.c = 3;
9699 * _.keysIn(new Foo);
9700 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
9702 function keysIn(object) {
9703 if (object == null) {
9706 if (!isObject(object)) {
9707 object = Object(object);
9709 var length = object.length;
9710 length = (length && isLength(length) &&
9711 (isArray(object) || isArguments(object)) && length) || 0;
9713 var Ctor = object.constructor,
9715 isProto = typeof Ctor == 'function' && Ctor.prototype === object,
9716 result = Array(length),
9717 skipIndexes = length > 0;
9719 while (++index < length) {
9720 result[index] = (index + '');
9722 for (var key in object) {
9723 if (!(skipIndexes && isIndex(key, length)) &&
9724 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
9732 * The opposite of `_.mapValues`; this method creates an object with the
9733 * same values as `object` and keys generated by running each own enumerable
9734 * property of `object` through `iteratee`.
9739 * @param {Object} object The object to iterate over.
9740 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9742 * @param {*} [thisArg] The `this` binding of `iteratee`.
9743 * @returns {Object} Returns the new mapped object.
9746 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
9747 * return key + value;
9749 * // => { 'a1': 1, 'b2': 2 }
9751 var mapKeys = createObjectMapper(true);
9754 * Creates an object with the same keys as `object` and values generated by
9755 * running each own enumerable property of `object` through `iteratee`. The
9756 * iteratee function is bound to `thisArg` and invoked with three arguments:
9757 * (value, key, object).
9759 * If a property name is provided for `iteratee` the created `_.property`
9760 * style callback returns the property value of the given element.
9762 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9763 * style callback returns `true` for elements that have a matching property
9764 * value, else `false`.
9766 * If an object is provided for `iteratee` the created `_.matches` style
9767 * callback returns `true` for elements that have the properties of the given
9768 * object, else `false`.
9773 * @param {Object} object The object to iterate over.
9774 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9776 * @param {*} [thisArg] The `this` binding of `iteratee`.
9777 * @returns {Object} Returns the new mapped object.
9780 * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
9783 * // => { 'a': 3, 'b': 6 }
9786 * 'fred': { 'user': 'fred', 'age': 40 },
9787 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
9790 * // using the `_.property` callback shorthand
9791 * _.mapValues(users, 'age');
9792 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
9794 var mapValues = createObjectMapper();
9797 * The opposite of `_.pick`; this method creates an object composed of the
9798 * own and inherited enumerable properties of `object` that are not omitted.
9803 * @param {Object} object The source object.
9804 * @param {Function|...(string|string[])} [predicate] The function invoked per
9805 * iteration or property names to omit, specified as individual property
9806 * names or arrays of property names.
9807 * @param {*} [thisArg] The `this` binding of `predicate`.
9808 * @returns {Object} Returns the new object.
9811 * var object = { 'user': 'fred', 'age': 40 };
9813 * _.omit(object, 'age');
9814 * // => { 'user': 'fred' }
9816 * _.omit(object, _.isNumber);
9817 * // => { 'user': 'fred' }
9819 var omit = restParam(function(object, props) {
9820 if (object == null) {
9823 if (typeof props[0] != 'function') {
9824 var props = arrayMap(baseFlatten(props), String);
9825 return pickByArray(object, baseDifference(keysIn(object), props));
9827 var predicate = bindCallback(props[0], props[1], 3);
9828 return pickByCallback(object, function(value, key, object) {
9829 return !predicate(value, key, object);
9834 * Creates a two dimensional array of the key-value pairs for `object`,
9835 * e.g. `[[key1, value1], [key2, value2]]`.
9840 * @param {Object} object The object to query.
9841 * @returns {Array} Returns the new array of key-value pairs.
9844 * _.pairs({ 'barney': 36, 'fred': 40 });
9845 * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
9847 function pairs(object) {
9848 object = toObject(object);
9851 props = keys(object),
9852 length = props.length,
9853 result = Array(length);
9855 while (++index < length) {
9856 var key = props[index];
9857 result[index] = [key, object[key]];
9863 * Creates an object composed of the picked `object` properties. Property
9864 * names may be specified as individual arguments or as arrays of property
9865 * names. If `predicate` is provided it is invoked for each property of `object`
9866 * picking the properties `predicate` returns truthy for. The predicate is
9867 * bound to `thisArg` and invoked with three arguments: (value, key, object).
9872 * @param {Object} object The source object.
9873 * @param {Function|...(string|string[])} [predicate] The function invoked per
9874 * iteration or property names to pick, specified as individual property
9875 * names or arrays of property names.
9876 * @param {*} [thisArg] The `this` binding of `predicate`.
9877 * @returns {Object} Returns the new object.
9880 * var object = { 'user': 'fred', 'age': 40 };
9882 * _.pick(object, 'user');
9883 * // => { 'user': 'fred' }
9885 * _.pick(object, _.isString);
9886 * // => { 'user': 'fred' }
9888 var pick = restParam(function(object, props) {
9889 if (object == null) {
9892 return typeof props[0] == 'function'
9893 ? pickByCallback(object, bindCallback(props[0], props[1], 3))
9894 : pickByArray(object, baseFlatten(props));
9898 * This method is like `_.get` except that if the resolved value is a function
9899 * it is invoked with the `this` binding of its parent object and its result
9905 * @param {Object} object The object to query.
9906 * @param {Array|string} path The path of the property to resolve.
9907 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9908 * @returns {*} Returns the resolved value.
9911 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
9913 * _.result(object, 'a[0].b.c1');
9916 * _.result(object, 'a[0].b.c2');
9919 * _.result(object, 'a.b.c', 'default');
9922 * _.result(object, 'a.b.c', _.constant('default'));
9925 function result(object, path, defaultValue) {
9926 var result = object == null ? undefined : object[path];
9927 if (result === undefined) {
9928 if (object != null && !isKey(path, object)) {
9929 path = toPath(path);
9930 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9931 result = object == null ? undefined : object[last(path)];
9933 result = result === undefined ? defaultValue : result;
9935 return isFunction(result) ? result.call(object) : result;
9939 * Sets the property value of `path` on `object`. If a portion of `path`
9940 * does not exist it is created.
9945 * @param {Object} object The object to augment.
9946 * @param {Array|string} path The path of the property to set.
9947 * @param {*} value The value to set.
9948 * @returns {Object} Returns `object`.
9951 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9953 * _.set(object, 'a[0].b.c', 4);
9954 * console.log(object.a[0].b.c);
9957 * _.set(object, 'x[0].y.z', 5);
9958 * console.log(object.x[0].y.z);
9961 function set(object, path, value) {
9962 if (object == null) {
9965 var pathKey = (path + '');
9966 path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
9969 length = path.length,
9970 lastIndex = length - 1,
9973 while (nested != null && ++index < length) {
9974 var key = path[index];
9975 if (isObject(nested)) {
9976 if (index == lastIndex) {
9977 nested[key] = value;
9978 } else if (nested[key] == null) {
9979 nested[key] = isIndex(path[index + 1]) ? [] : {};
9982 nested = nested[key];
9988 * An alternative to `_.reduce`; this method transforms `object` to a new
9989 * `accumulator` object which is the result of running each of its own enumerable
9990 * properties through `iteratee`, with each invocation potentially mutating
9991 * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
9992 * with four arguments: (accumulator, value, key, object). Iteratee functions
9993 * may exit iteration early by explicitly returning `false`.
9998 * @param {Array|Object} object The object to iterate over.
9999 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10000 * @param {*} [accumulator] The custom accumulator value.
10001 * @param {*} [thisArg] The `this` binding of `iteratee`.
10002 * @returns {*} Returns the accumulated value.
10005 * _.transform([2, 3, 4], function(result, n) {
10006 * result.push(n *= n);
10007 * return n % 2 == 0;
10011 * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
10012 * result[key] = n * 3;
10014 * // => { 'a': 3, 'b': 6 }
10016 function transform(object, iteratee, accumulator, thisArg) {
10017 var isArr = isArray(object) || isTypedArray(object);
10018 iteratee = getCallback(iteratee, thisArg, 4);
10020 if (accumulator == null) {
10021 if (isArr || isObject(object)) {
10022 var Ctor = object.constructor;
10024 accumulator = isArray(object) ? new Ctor : [];
10026 accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
10032 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
10033 return iteratee(accumulator, value, index, object);
10035 return accumulator;
10039 * Creates an array of the own enumerable property values of `object`.
10041 * **Note:** Non-object values are coerced to objects.
10046 * @param {Object} object The object to query.
10047 * @returns {Array} Returns the array of property values.
10055 * Foo.prototype.c = 3;
10057 * _.values(new Foo);
10058 * // => [1, 2] (iteration order is not guaranteed)
10063 function values(object) {
10064 return baseValues(object, keys(object));
10068 * Creates an array of the own and inherited enumerable property values
10071 * **Note:** Non-object values are coerced to objects.
10076 * @param {Object} object The object to query.
10077 * @returns {Array} Returns the array of property values.
10085 * Foo.prototype.c = 3;
10087 * _.valuesIn(new Foo);
10088 * // => [1, 2, 3] (iteration order is not guaranteed)
10090 function valuesIn(object) {
10091 return baseValues(object, keysIn(object));
10094 /*------------------------------------------------------------------------*/
10097 * Checks if `n` is between `start` and up to but not including, `end`. If
10098 * `end` is not specified it is set to `start` with `start` then set to `0`.
10103 * @param {number} n The number to check.
10104 * @param {number} [start=0] The start of the range.
10105 * @param {number} end The end of the range.
10106 * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
10109 * _.inRange(3, 2, 4);
10121 * _.inRange(1.2, 2);
10124 * _.inRange(5.2, 4);
10127 function inRange(value, start, end) {
10128 start = +start || 0;
10129 if (end === undefined) {
10135 return value >= nativeMin(start, end) && value < nativeMax(start, end);
10139 * Produces a random number between `min` and `max` (inclusive). If only one
10140 * argument is provided a number between `0` and the given number is returned.
10141 * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
10142 * number is returned instead of an integer.
10147 * @param {number} [min=0] The minimum possible value.
10148 * @param {number} [max=1] The maximum possible value.
10149 * @param {boolean} [floating] Specify returning a floating-point number.
10150 * @returns {number} Returns the random number.
10154 * // => an integer between 0 and 5
10157 * // => also an integer between 0 and 5
10159 * _.random(5, true);
10160 * // => a floating-point number between 0 and 5
10162 * _.random(1.2, 5.2);
10163 * // => a floating-point number between 1.2 and 5.2
10165 function random(min, max, floating) {
10166 if (floating && isIterateeCall(min, max, floating)) {
10167 max = floating = undefined;
10169 var noMin = min == null,
10170 noMax = max == null;
10172 if (floating == null) {
10173 if (noMax && typeof min == 'boolean') {
10177 else if (typeof max == 'boolean') {
10182 if (noMin && noMax) {
10193 if (floating || min % 1 || max % 1) {
10194 var rand = nativeRandom();
10195 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
10197 return baseRandom(min, max);
10200 /*------------------------------------------------------------------------*/
10203 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
10208 * @param {string} [string=''] The string to convert.
10209 * @returns {string} Returns the camel cased string.
10212 * _.camelCase('Foo Bar');
10215 * _.camelCase('--foo-bar');
10218 * _.camelCase('__foo_bar__');
10221 var camelCase = createCompounder(function(result, word, index) {
10222 word = word.toLowerCase();
10223 return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
10227 * Capitalizes the first character of `string`.
10232 * @param {string} [string=''] The string to capitalize.
10233 * @returns {string} Returns the capitalized string.
10236 * _.capitalize('fred');
10239 function capitalize(string) {
10240 string = baseToString(string);
10241 return string && (string.charAt(0).toUpperCase() + string.slice(1));
10245 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
10246 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
10251 * @param {string} [string=''] The string to deburr.
10252 * @returns {string} Returns the deburred string.
10255 * _.deburr('déjà vu');
10258 function deburr(string) {
10259 string = baseToString(string);
10260 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
10264 * Checks if `string` ends with the given target string.
10269 * @param {string} [string=''] The string to search.
10270 * @param {string} [target] The string to search for.
10271 * @param {number} [position=string.length] The position to search from.
10272 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
10275 * _.endsWith('abc', 'c');
10278 * _.endsWith('abc', 'b');
10281 * _.endsWith('abc', 'b', 2);
10284 function endsWith(string, target, position) {
10285 string = baseToString(string);
10286 target = (target + '');
10288 var length = string.length;
10289 position = position === undefined
10291 : nativeMin(position < 0 ? 0 : (+position || 0), length);
10293 position -= target.length;
10294 return position >= 0 && string.indexOf(target, position) == position;
10298 * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
10299 * their corresponding HTML entities.
10301 * **Note:** No other characters are escaped. To escape additional characters
10302 * use a third-party library like [_he_](https://mths.be/he).
10304 * Though the ">" character is escaped for symmetry, characters like
10305 * ">" and "/" don't need escaping in HTML and have no special meaning
10306 * unless they're part of a tag or unquoted attribute value.
10307 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
10308 * (under "semi-related fun fact") for more details.
10310 * Backticks are escaped because in Internet Explorer < 9, they can break out
10311 * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
10312 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
10313 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
10314 * for more details.
10316 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
10317 * to reduce XSS vectors.
10322 * @param {string} [string=''] The string to escape.
10323 * @returns {string} Returns the escaped string.
10326 * _.escape('fred, barney, & pebbles');
10327 * // => 'fred, barney, & pebbles'
10329 function escape(string) {
10330 // Reset `lastIndex` because in IE < 9 `String#replace` does not.
10331 string = baseToString(string);
10332 return (string && reHasUnescapedHtml.test(string))
10333 ? string.replace(reUnescapedHtml, escapeHtmlChar)
10338 * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
10339 * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
10344 * @param {string} [string=''] The string to escape.
10345 * @returns {string} Returns the escaped string.
10348 * _.escapeRegExp('[lodash](https://lodash.com/)');
10349 * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
10351 function escapeRegExp(string) {
10352 string = baseToString(string);
10353 return (string && reHasRegExpChars.test(string))
10354 ? string.replace(reRegExpChars, escapeRegExpChar)
10355 : (string || '(?:)');
10359 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
10364 * @param {string} [string=''] The string to convert.
10365 * @returns {string} Returns the kebab cased string.
10368 * _.kebabCase('Foo Bar');
10371 * _.kebabCase('fooBar');
10374 * _.kebabCase('__foo_bar__');
10377 var kebabCase = createCompounder(function(result, word, index) {
10378 return result + (index ? '-' : '') + word.toLowerCase();
10382 * Pads `string` on the left and right sides if it's shorter than `length`.
10383 * Padding characters are truncated if they can't be evenly divided by `length`.
10388 * @param {string} [string=''] The string to pad.
10389 * @param {number} [length=0] The padding length.
10390 * @param {string} [chars=' '] The string used as padding.
10391 * @returns {string} Returns the padded string.
10397 * _.pad('abc', 8, '_-');
10403 function pad(string, length, chars) {
10404 string = baseToString(string);
10407 var strLength = string.length;
10408 if (strLength >= length || !nativeIsFinite(length)) {
10411 var mid = (length - strLength) / 2,
10412 leftLength = nativeFloor(mid),
10413 rightLength = nativeCeil(mid);
10415 chars = createPadding('', rightLength, chars);
10416 return chars.slice(0, leftLength) + string + chars;
10420 * Pads `string` on the left side if it's shorter than `length`. Padding
10421 * characters are truncated if they exceed `length`.
10426 * @param {string} [string=''] The string to pad.
10427 * @param {number} [length=0] The padding length.
10428 * @param {string} [chars=' '] The string used as padding.
10429 * @returns {string} Returns the padded string.
10432 * _.padLeft('abc', 6);
10435 * _.padLeft('abc', 6, '_-');
10438 * _.padLeft('abc', 3);
10441 var padLeft = createPadDir();
10444 * Pads `string` on the right side if it's shorter than `length`. Padding
10445 * characters are truncated if they exceed `length`.
10450 * @param {string} [string=''] The string to pad.
10451 * @param {number} [length=0] The padding length.
10452 * @param {string} [chars=' '] The string used as padding.
10453 * @returns {string} Returns the padded string.
10456 * _.padRight('abc', 6);
10459 * _.padRight('abc', 6, '_-');
10462 * _.padRight('abc', 3);
10465 var padRight = createPadDir(true);
10468 * Converts `string` to an integer of the specified radix. If `radix` is
10469 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
10470 * in which case a `radix` of `16` is used.
10472 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
10478 * @param {string} string The string to convert.
10479 * @param {number} [radix] The radix to interpret `value` by.
10480 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10481 * @returns {number} Returns the converted integer.
10484 * _.parseInt('08');
10487 * _.map(['6', '08', '10'], _.parseInt);
10490 function parseInt(string, radix, guard) {
10491 // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
10492 // Chrome fails to trim leading <BOM> whitespace characters.
10493 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
10494 if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
10496 } else if (radix) {
10499 string = trim(string);
10500 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
10504 * Repeats the given string `n` times.
10509 * @param {string} [string=''] The string to repeat.
10510 * @param {number} [n=0] The number of times to repeat the string.
10511 * @returns {string} Returns the repeated string.
10514 * _.repeat('*', 3);
10517 * _.repeat('abc', 2);
10520 * _.repeat('abc', 0);
10523 function repeat(string, n) {
10525 string = baseToString(string);
10527 if (n < 1 || !string || !nativeIsFinite(n)) {
10530 // Leverage the exponentiation by squaring algorithm for a faster repeat.
10531 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
10536 n = nativeFloor(n / 2);
10544 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
10549 * @param {string} [string=''] The string to convert.
10550 * @returns {string} Returns the snake cased string.
10553 * _.snakeCase('Foo Bar');
10556 * _.snakeCase('fooBar');
10559 * _.snakeCase('--foo-bar');
10562 var snakeCase = createCompounder(function(result, word, index) {
10563 return result + (index ? '_' : '') + word.toLowerCase();
10567 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
10572 * @param {string} [string=''] The string to convert.
10573 * @returns {string} Returns the start cased string.
10576 * _.startCase('--foo-bar');
10579 * _.startCase('fooBar');
10582 * _.startCase('__foo_bar__');
10585 var startCase = createCompounder(function(result, word, index) {
10586 return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
10590 * Checks if `string` starts with the given target string.
10595 * @param {string} [string=''] The string to search.
10596 * @param {string} [target] The string to search for.
10597 * @param {number} [position=0] The position to search from.
10598 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
10601 * _.startsWith('abc', 'a');
10604 * _.startsWith('abc', 'b');
10607 * _.startsWith('abc', 'b', 1);
10610 function startsWith(string, target, position) {
10611 string = baseToString(string);
10612 position = position == null
10614 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
10616 return string.lastIndexOf(target, position) == position;
10620 * Creates a compiled template function that can interpolate data properties
10621 * in "interpolate" delimiters, HTML-escape interpolated data properties in
10622 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
10623 * properties may be accessed as free variables in the template. If a setting
10624 * object is provided it takes precedence over `_.templateSettings` values.
10626 * **Note:** In the development build `_.template` utilizes
10627 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
10628 * for easier debugging.
10630 * For more information on precompiling templates see
10631 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
10633 * For more information on Chrome extension sandboxes see
10634 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
10639 * @param {string} [string=''] The template string.
10640 * @param {Object} [options] The options object.
10641 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
10642 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
10643 * @param {Object} [options.imports] An object to import into the template as free variables.
10644 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
10645 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
10646 * @param {string} [options.variable] The data object variable name.
10647 * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
10648 * @returns {Function} Returns the compiled template function.
10651 * // using the "interpolate" delimiter to create a compiled template
10652 * var compiled = _.template('hello <%= user %>!');
10653 * compiled({ 'user': 'fred' });
10654 * // => 'hello fred!'
10656 * // using the HTML "escape" delimiter to escape data property values
10657 * var compiled = _.template('<b><%- value %></b>');
10658 * compiled({ 'value': '<script>' });
10659 * // => '<b><script></b>'
10661 * // using the "evaluate" delimiter to execute JavaScript and generate HTML
10662 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
10663 * compiled({ 'users': ['fred', 'barney'] });
10664 * // => '<li>fred</li><li>barney</li>'
10666 * // using the internal `print` function in "evaluate" delimiters
10667 * var compiled = _.template('<% print("hello " + user); %>!');
10668 * compiled({ 'user': 'barney' });
10669 * // => 'hello barney!'
10671 * // using the ES delimiter as an alternative to the default "interpolate" delimiter
10672 * var compiled = _.template('hello ${ user }!');
10673 * compiled({ 'user': 'pebbles' });
10674 * // => 'hello pebbles!'
10676 * // using custom template delimiters
10677 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
10678 * var compiled = _.template('hello {{ user }}!');
10679 * compiled({ 'user': 'mustache' });
10680 * // => 'hello mustache!'
10682 * // using backslashes to treat delimiters as plain text
10683 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
10684 * compiled({ 'value': 'ignored' });
10685 * // => '<%- value %>'
10687 * // using the `imports` option to import `jQuery` as `jq`
10688 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
10689 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
10690 * compiled({ 'users': ['fred', 'barney'] });
10691 * // => '<li>fred</li><li>barney</li>'
10693 * // using the `sourceURL` option to specify a custom sourceURL for the template
10694 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
10696 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
10698 * // using the `variable` option to ensure a with-statement isn't used in the compiled template
10699 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
10701 * // => function(data) {
10702 * // var __t, __p = '';
10703 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
10707 * // using the `source` property to inline compiled templates for meaningful
10708 * // line numbers in error messages and a stack trace
10709 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
10711 * "main": ' + _.template(mainText).source + '\
10715 function template(string, options, otherOptions) {
10716 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
10717 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
10718 var settings = lodash.templateSettings;
10720 if (otherOptions && isIterateeCall(string, options, otherOptions)) {
10721 options = otherOptions = undefined;
10723 string = baseToString(string);
10724 options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
10726 var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
10727 importsKeys = keys(imports),
10728 importsValues = baseValues(imports, importsKeys);
10733 interpolate = options.interpolate || reNoMatch,
10734 source = "__p += '";
10736 // Compile the regexp to match each delimiter.
10737 var reDelimiters = RegExp(
10738 (options.escape || reNoMatch).source + '|' +
10739 interpolate.source + '|' +
10740 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
10741 (options.evaluate || reNoMatch).source + '|$'
10744 // Use a sourceURL for easier debugging.
10745 var sourceURL = '//# sourceURL=' +
10746 ('sourceURL' in options
10747 ? options.sourceURL
10748 : ('lodash.templateSources[' + (++templateCounter) + ']')
10751 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
10752 interpolateValue || (interpolateValue = esTemplateValue);
10754 // Escape characters that can't be included in string literals.
10755 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
10757 // Replace delimiters with snippets.
10760 source += "' +\n__e(" + escapeValue + ") +\n'";
10762 if (evaluateValue) {
10763 isEvaluating = true;
10764 source += "';\n" + evaluateValue + ";\n__p += '";
10766 if (interpolateValue) {
10767 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
10769 index = offset + match.length;
10771 // The JS engine embedded in Adobe products requires returning the `match`
10772 // string in order to produce the correct `offset` value.
10778 // If `variable` is not specified wrap a with-statement around the generated
10779 // code to add the data object to the top of the scope chain.
10780 var variable = options.variable;
10782 source = 'with (obj) {\n' + source + '\n}\n';
10784 // Cleanup code by stripping empty strings.
10785 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
10786 .replace(reEmptyStringMiddle, '$1')
10787 .replace(reEmptyStringTrailing, '$1;');
10789 // Frame code as the function body.
10790 source = 'function(' + (variable || 'obj') + ') {\n' +
10793 : 'obj || (obj = {});\n'
10795 "var __t, __p = ''" +
10797 ? ', __e = _.escape'
10801 ? ', __j = Array.prototype.join;\n' +
10802 "function print() { __p += __j.call(arguments, '') }\n"
10808 var result = attempt(function() {
10809 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
10812 // Provide the compiled function's source by its `toString` method or
10813 // the `source` property as a convenience for inlining compiled templates.
10814 result.source = source;
10815 if (isError(result)) {
10822 * Removes leading and trailing whitespace or specified characters from `string`.
10827 * @param {string} [string=''] The string to trim.
10828 * @param {string} [chars=whitespace] The characters to trim.
10829 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10830 * @returns {string} Returns the trimmed string.
10836 * _.trim('-_-abc-_-', '_-');
10839 * _.map([' foo ', ' bar '], _.trim);
10840 * // => ['foo', 'bar']
10842 function trim(string, chars, guard) {
10843 var value = string;
10844 string = baseToString(string);
10848 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10849 return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
10851 chars = (chars + '');
10852 return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
10856 * Removes leading whitespace or specified characters from `string`.
10861 * @param {string} [string=''] The string to trim.
10862 * @param {string} [chars=whitespace] The characters to trim.
10863 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10864 * @returns {string} Returns the trimmed string.
10867 * _.trimLeft(' abc ');
10870 * _.trimLeft('-_-abc-_-', '_-');
10873 function trimLeft(string, chars, guard) {
10874 var value = string;
10875 string = baseToString(string);
10879 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10880 return string.slice(trimmedLeftIndex(string));
10882 return string.slice(charsLeftIndex(string, (chars + '')));
10886 * Removes trailing whitespace or specified characters from `string`.
10891 * @param {string} [string=''] The string to trim.
10892 * @param {string} [chars=whitespace] The characters to trim.
10893 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10894 * @returns {string} Returns the trimmed string.
10897 * _.trimRight(' abc ');
10900 * _.trimRight('-_-abc-_-', '_-');
10903 function trimRight(string, chars, guard) {
10904 var value = string;
10905 string = baseToString(string);
10909 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10910 return string.slice(0, trimmedRightIndex(string) + 1);
10912 return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
10916 * Truncates `string` if it's longer than the given maximum string length.
10917 * The last characters of the truncated string are replaced with the omission
10918 * string which defaults to "...".
10923 * @param {string} [string=''] The string to truncate.
10924 * @param {Object|number} [options] The options object or maximum string length.
10925 * @param {number} [options.length=30] The maximum string length.
10926 * @param {string} [options.omission='...'] The string to indicate text is omitted.
10927 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
10928 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10929 * @returns {string} Returns the truncated string.
10932 * _.trunc('hi-diddly-ho there, neighborino');
10933 * // => 'hi-diddly-ho there, neighbo...'
10935 * _.trunc('hi-diddly-ho there, neighborino', 24);
10936 * // => 'hi-diddly-ho there, n...'
10938 * _.trunc('hi-diddly-ho there, neighborino', {
10942 * // => 'hi-diddly-ho there,...'
10944 * _.trunc('hi-diddly-ho there, neighborino', {
10946 * 'separator': /,? +/
10948 * // => 'hi-diddly-ho there...'
10950 * _.trunc('hi-diddly-ho there, neighborino', {
10951 * 'omission': ' [...]'
10953 * // => 'hi-diddly-ho there, neig [...]'
10955 function trunc(string, options, guard) {
10956 if (guard && isIterateeCall(string, options, guard)) {
10957 options = undefined;
10959 var length = DEFAULT_TRUNC_LENGTH,
10960 omission = DEFAULT_TRUNC_OMISSION;
10962 if (options != null) {
10963 if (isObject(options)) {
10964 var separator = 'separator' in options ? options.separator : separator;
10965 length = 'length' in options ? (+options.length || 0) : length;
10966 omission = 'omission' in options ? baseToString(options.omission) : omission;
10968 length = +options || 0;
10971 string = baseToString(string);
10972 if (length >= string.length) {
10975 var end = length - omission.length;
10979 var result = string.slice(0, end);
10980 if (separator == null) {
10981 return result + omission;
10983 if (isRegExp(separator)) {
10984 if (string.slice(end).search(separator)) {
10987 substring = string.slice(0, end);
10989 if (!separator.global) {
10990 separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
10992 separator.lastIndex = 0;
10993 while ((match = separator.exec(substring))) {
10994 newEnd = match.index;
10996 result = result.slice(0, newEnd == null ? end : newEnd);
10998 } else if (string.indexOf(separator, end) != end) {
10999 var index = result.lastIndexOf(separator);
11001 result = result.slice(0, index);
11004 return result + omission;
11008 * The inverse of `_.escape`; this method converts the HTML entities
11009 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
11010 * corresponding characters.
11012 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
11013 * entities use a third-party library like [_he_](https://mths.be/he).
11018 * @param {string} [string=''] The string to unescape.
11019 * @returns {string} Returns the unescaped string.
11022 * _.unescape('fred, barney, & pebbles');
11023 * // => 'fred, barney, & pebbles'
11025 function unescape(string) {
11026 string = baseToString(string);
11027 return (string && reHasEscapedHtml.test(string))
11028 ? string.replace(reEscapedHtml, unescapeHtmlChar)
11033 * Splits `string` into an array of its words.
11038 * @param {string} [string=''] The string to inspect.
11039 * @param {RegExp|string} [pattern] The pattern to match words.
11040 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11041 * @returns {Array} Returns the words of `string`.
11044 * _.words('fred, barney, & pebbles');
11045 * // => ['fred', 'barney', 'pebbles']
11047 * _.words('fred, barney, & pebbles', /[^, ]+/g);
11048 * // => ['fred', 'barney', '&', 'pebbles']
11050 function words(string, pattern, guard) {
11051 if (guard && isIterateeCall(string, pattern, guard)) {
11052 pattern = undefined;
11054 string = baseToString(string);
11055 return string.match(pattern || reWords) || [];
11058 /*------------------------------------------------------------------------*/
11061 * Attempts to invoke `func`, returning either the result or the caught error
11062 * object. Any additional arguments are provided to `func` when it is invoked.
11066 * @category Utility
11067 * @param {Function} func The function to attempt.
11068 * @returns {*} Returns the `func` result or error object.
11071 * // avoid throwing errors for invalid selectors
11072 * var elements = _.attempt(function(selector) {
11073 * return document.querySelectorAll(selector);
11076 * if (_.isError(elements)) {
11080 var attempt = restParam(function(func, args) {
11082 return func.apply(undefined, args);
11084 return isError(e) ? e : new Error(e);
11089 * Creates a function that invokes `func` with the `this` binding of `thisArg`
11090 * and arguments of the created function. If `func` is a property name the
11091 * created callback returns the property value for a given element. If `func`
11092 * is an object the created callback returns `true` for elements that contain
11093 * the equivalent object properties, otherwise it returns `false`.
11098 * @category Utility
11099 * @param {*} [func=_.identity] The value to convert to a callback.
11100 * @param {*} [thisArg] The `this` binding of `func`.
11101 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11102 * @returns {Function} Returns the callback.
11106 * { 'user': 'barney', 'age': 36 },
11107 * { 'user': 'fred', 'age': 40 }
11110 * // wrap to create custom callback shorthands
11111 * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
11112 * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
11114 * return callback(func, thisArg);
11116 * return function(object) {
11117 * return match[2] == 'gt'
11118 * ? object[match[1]] > match[3]
11119 * : object[match[1]] < match[3];
11123 * _.filter(users, 'age__gt36');
11124 * // => [{ 'user': 'fred', 'age': 40 }]
11126 function callback(func, thisArg, guard) {
11127 if (guard && isIterateeCall(func, thisArg, guard)) {
11128 thisArg = undefined;
11130 return isObjectLike(func)
11132 : baseCallback(func, thisArg);
11136 * Creates a function that returns `value`.
11140 * @category Utility
11141 * @param {*} value The value to return from the new function.
11142 * @returns {Function} Returns the new function.
11145 * var object = { 'user': 'fred' };
11146 * var getter = _.constant(object);
11148 * getter() === object;
11151 function constant(value) {
11152 return function() {
11158 * This method returns the first argument provided to it.
11162 * @category Utility
11163 * @param {*} value Any value.
11164 * @returns {*} Returns `value`.
11167 * var object = { 'user': 'fred' };
11169 * _.identity(object) === object;
11172 function identity(value) {
11177 * Creates a function that performs a deep comparison between a given object
11178 * and `source`, returning `true` if the given object has equivalent property
11179 * values, else `false`.
11181 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11182 * numbers, `Object` objects, regexes, and strings. Objects are compared by
11183 * their own, not inherited, enumerable properties. For comparing a single
11184 * own or inherited property value see `_.matchesProperty`.
11188 * @category Utility
11189 * @param {Object} source The object of property values to match.
11190 * @returns {Function} Returns the new function.
11194 * { 'user': 'barney', 'age': 36, 'active': true },
11195 * { 'user': 'fred', 'age': 40, 'active': false }
11198 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
11199 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
11201 function matches(source) {
11202 return baseMatches(baseClone(source, true));
11206 * Creates a function that compares the property value of `path` on a given
11207 * object to `value`.
11209 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11210 * numbers, `Object` objects, regexes, and strings. Objects are compared by
11211 * their own, not inherited, enumerable properties.
11215 * @category Utility
11216 * @param {Array|string} path The path of the property to get.
11217 * @param {*} srcValue The value to match.
11218 * @returns {Function} Returns the new function.
11222 * { 'user': 'barney' },
11223 * { 'user': 'fred' }
11226 * _.find(users, _.matchesProperty('user', 'fred'));
11227 * // => { 'user': 'fred' }
11229 function matchesProperty(path, srcValue) {
11230 return baseMatchesProperty(path, baseClone(srcValue, true));
11234 * Creates a function that invokes the method at `path` on a given object.
11235 * Any additional arguments are provided to the invoked method.
11239 * @category Utility
11240 * @param {Array|string} path The path of the method to invoke.
11241 * @param {...*} [args] The arguments to invoke the method with.
11242 * @returns {Function} Returns the new function.
11246 * { 'a': { 'b': { 'c': _.constant(2) } } },
11247 * { 'a': { 'b': { 'c': _.constant(1) } } }
11250 * _.map(objects, _.method('a.b.c'));
11253 * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
11256 var method = restParam(function(path, args) {
11257 return function(object) {
11258 return invokePath(object, path, args);
11263 * The opposite of `_.method`; this method creates a function that invokes
11264 * the method at a given path on `object`. Any additional arguments are
11265 * provided to the invoked method.
11269 * @category Utility
11270 * @param {Object} object The object to query.
11271 * @param {...*} [args] The arguments to invoke the method with.
11272 * @returns {Function} Returns the new function.
11275 * var array = _.times(3, _.constant),
11276 * object = { 'a': array, 'b': array, 'c': array };
11278 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
11281 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
11284 var methodOf = restParam(function(object, args) {
11285 return function(path) {
11286 return invokePath(object, path, args);
11291 * Adds all own enumerable function properties of a source object to the
11292 * destination object. If `object` is a function then methods are added to
11293 * its prototype as well.
11295 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
11296 * avoid conflicts caused by modifying the original.
11300 * @category Utility
11301 * @param {Function|Object} [object=lodash] The destination object.
11302 * @param {Object} source The object of functions to add.
11303 * @param {Object} [options] The options object.
11304 * @param {boolean} [options.chain=true] Specify whether the functions added
11306 * @returns {Function|Object} Returns `object`.
11309 * function vowels(string) {
11310 * return _.filter(string, function(v) {
11311 * return /[aeiou]/i.test(v);
11315 * _.mixin({ 'vowels': vowels });
11316 * _.vowels('fred');
11319 * _('fred').vowels().value();
11322 * _.mixin({ 'vowels': vowels }, { 'chain': false });
11323 * _('fred').vowels();
11326 function mixin(object, source, options) {
11327 if (options == null) {
11328 var isObj = isObject(source),
11329 props = isObj ? keys(source) : undefined,
11330 methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
11332 if (!(methodNames ? methodNames.length : isObj)) {
11333 methodNames = false;
11339 if (!methodNames) {
11340 methodNames = baseFunctions(source, keys(source));
11344 isFunc = isFunction(object),
11345 length = methodNames.length;
11347 if (options === false) {
11349 } else if (isObject(options) && 'chain' in options) {
11350 chain = options.chain;
11352 while (++index < length) {
11353 var methodName = methodNames[index],
11354 func = source[methodName];
11356 object[methodName] = func;
11358 object.prototype[methodName] = (function(func) {
11359 return function() {
11360 var chainAll = this.__chain__;
11361 if (chain || chainAll) {
11362 var result = object(this.__wrapped__),
11363 actions = result.__actions__ = arrayCopy(this.__actions__);
11365 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
11366 result.__chain__ = chainAll;
11369 return func.apply(object, arrayPush([this.value()], arguments));
11378 * Reverts the `_` variable to its previous value and returns a reference to
11379 * the `lodash` function.
11383 * @category Utility
11384 * @returns {Function} Returns the `lodash` function.
11387 * var lodash = _.noConflict();
11389 function noConflict() {
11395 * A no-operation function that returns `undefined` regardless of the
11396 * arguments it receives.
11400 * @category Utility
11403 * var object = { 'user': 'fred' };
11405 * _.noop(object) === undefined;
11409 // No operation performed.
11413 * Creates a function that returns the property value at `path` on a
11418 * @category Utility
11419 * @param {Array|string} path The path of the property to get.
11420 * @returns {Function} Returns the new function.
11424 * { 'a': { 'b': { 'c': 2 } } },
11425 * { 'a': { 'b': { 'c': 1 } } }
11428 * _.map(objects, _.property('a.b.c'));
11431 * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
11434 function property(path) {
11435 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
11439 * The opposite of `_.property`; this method creates a function that returns
11440 * the property value at a given path on `object`.
11444 * @category Utility
11445 * @param {Object} object The object to query.
11446 * @returns {Function} Returns the new function.
11449 * var array = [0, 1, 2],
11450 * object = { 'a': array, 'b': array, 'c': array };
11452 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
11455 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
11458 function propertyOf(object) {
11459 return function(path) {
11460 return baseGet(object, toPath(path), path + '');
11465 * Creates an array of numbers (positive and/or negative) progressing from
11466 * `start` up to, but not including, `end`. If `end` is not specified it is
11467 * set to `start` with `start` then set to `0`. If `end` is less than `start`
11468 * a zero-length range is created unless a negative `step` is specified.
11472 * @category Utility
11473 * @param {number} [start=0] The start of the range.
11474 * @param {number} end The end of the range.
11475 * @param {number} [step=1] The value to increment or decrement by.
11476 * @returns {Array} Returns the new array of numbers.
11480 * // => [0, 1, 2, 3]
11483 * // => [1, 2, 3, 4]
11485 * _.range(0, 20, 5);
11486 * // => [0, 5, 10, 15]
11488 * _.range(0, -4, -1);
11489 * // => [0, -1, -2, -3]
11491 * _.range(1, 4, 0);
11497 function range(start, end, step) {
11498 if (step && isIterateeCall(start, end, step)) {
11499 end = step = undefined;
11501 start = +start || 0;
11502 step = step == null ? 1 : (+step || 0);
11510 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
11511 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
11513 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
11514 result = Array(length);
11516 while (++index < length) {
11517 result[index] = start;
11524 * Invokes the iteratee function `n` times, returning an array of the results
11525 * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
11526 * one argument; (index).
11530 * @category Utility
11531 * @param {number} n The number of times to invoke `iteratee`.
11532 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11533 * @param {*} [thisArg] The `this` binding of `iteratee`.
11534 * @returns {Array} Returns the array of results.
11537 * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
11540 * _.times(3, function(n) {
11541 * mage.castSpell(n);
11543 * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
11545 * _.times(3, function(n) {
11548 * // => also invokes `mage.castSpell(n)` three times
11550 function times(n, iteratee, thisArg) {
11551 n = nativeFloor(n);
11553 // Exit early to avoid a JSC JIT bug in Safari 8
11554 // where `Array(0)` is treated as `Array(1)`.
11555 if (n < 1 || !nativeIsFinite(n)) {
11559 result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
11561 iteratee = bindCallback(iteratee, thisArg, 1);
11562 while (++index < n) {
11563 if (index < MAX_ARRAY_LENGTH) {
11564 result[index] = iteratee(index);
11573 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
11577 * @category Utility
11578 * @param {string} [prefix] The value to prefix the ID with.
11579 * @returns {string} Returns the unique ID.
11582 * _.uniqueId('contact_');
11583 * // => 'contact_104'
11588 function uniqueId(prefix) {
11589 var id = ++idCounter;
11590 return baseToString(prefix) + id;
11593 /*------------------------------------------------------------------------*/
11596 * Adds two numbers.
11601 * @param {number} augend The first number to add.
11602 * @param {number} addend The second number to add.
11603 * @returns {number} Returns the sum.
11609 function add(augend, addend) {
11610 return (+augend || 0) + (+addend || 0);
11614 * Calculates `n` rounded up to `precision`.
11619 * @param {number} n The number to round up.
11620 * @param {number} [precision=0] The precision to round up to.
11621 * @returns {number} Returns the rounded up number.
11627 * _.ceil(6.004, 2);
11630 * _.ceil(6040, -2);
11633 var ceil = createRound('ceil');
11636 * Calculates `n` rounded down to `precision`.
11641 * @param {number} n The number to round down.
11642 * @param {number} [precision=0] The precision to round down to.
11643 * @returns {number} Returns the rounded down number.
11649 * _.floor(0.046, 2);
11652 * _.floor(4060, -2);
11655 var floor = createRound('floor');
11658 * Gets the maximum value of `collection`. If `collection` is empty or falsey
11659 * `-Infinity` is returned. If an iteratee function is provided it is invoked
11660 * for each value in `collection` to generate the criterion by which the value
11661 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11662 * arguments: (value, index, collection).
11664 * If a property name is provided for `iteratee` the created `_.property`
11665 * style callback returns the property value of the given element.
11667 * If a value is also provided for `thisArg` the created `_.matchesProperty`
11668 * style callback returns `true` for elements that have a matching property
11669 * value, else `false`.
11671 * If an object is provided for `iteratee` the created `_.matches` style
11672 * callback returns `true` for elements that have the properties of the given
11673 * object, else `false`.
11678 * @param {Array|Object|string} collection The collection to iterate over.
11679 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11680 * @param {*} [thisArg] The `this` binding of `iteratee`.
11681 * @returns {*} Returns the maximum value.
11684 * _.max([4, 2, 8, 6]);
11691 * { 'user': 'barney', 'age': 36 },
11692 * { 'user': 'fred', 'age': 40 }
11695 * _.max(users, function(chr) {
11698 * // => { 'user': 'fred', 'age': 40 }
11700 * // using the `_.property` callback shorthand
11701 * _.max(users, 'age');
11702 * // => { 'user': 'fred', 'age': 40 }
11704 var max = createExtremum(gt, NEGATIVE_INFINITY);
11707 * Gets the minimum value of `collection`. If `collection` is empty or falsey
11708 * `Infinity` is returned. If an iteratee function is provided it is invoked
11709 * for each value in `collection` to generate the criterion by which the value
11710 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11711 * arguments: (value, index, collection).
11713 * If a property name is provided for `iteratee` the created `_.property`
11714 * style callback returns the property value of the given element.
11716 * If a value is also provided for `thisArg` the created `_.matchesProperty`
11717 * style callback returns `true` for elements that have a matching property
11718 * value, else `false`.
11720 * If an object is provided for `iteratee` the created `_.matches` style
11721 * callback returns `true` for elements that have the properties of the given
11722 * object, else `false`.
11727 * @param {Array|Object|string} collection The collection to iterate over.
11728 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11729 * @param {*} [thisArg] The `this` binding of `iteratee`.
11730 * @returns {*} Returns the minimum value.
11733 * _.min([4, 2, 8, 6]);
11740 * { 'user': 'barney', 'age': 36 },
11741 * { 'user': 'fred', 'age': 40 }
11744 * _.min(users, function(chr) {
11747 * // => { 'user': 'barney', 'age': 36 }
11749 * // using the `_.property` callback shorthand
11750 * _.min(users, 'age');
11751 * // => { 'user': 'barney', 'age': 36 }
11753 var min = createExtremum(lt, POSITIVE_INFINITY);
11756 * Calculates `n` rounded to `precision`.
11761 * @param {number} n The number to round.
11762 * @param {number} [precision=0] The precision to round to.
11763 * @returns {number} Returns the rounded number.
11769 * _.round(4.006, 2);
11772 * _.round(4060, -2);
11775 var round = createRound('round');
11778 * Gets the sum of the values in `collection`.
11783 * @param {Array|Object|string} collection The collection to iterate over.
11784 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11785 * @param {*} [thisArg] The `this` binding of `iteratee`.
11786 * @returns {number} Returns the sum.
11792 * _.sum({ 'a': 4, 'b': 6 });
11800 * _.sum(objects, function(object) {
11805 * // using the `_.property` callback shorthand
11806 * _.sum(objects, 'n');
11809 function sum(collection, iteratee, thisArg) {
11810 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
11811 iteratee = undefined;
11813 iteratee = getCallback(iteratee, thisArg, 3);
11814 return iteratee.length == 1
11815 ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
11816 : baseSum(collection, iteratee);
11819 /*------------------------------------------------------------------------*/
11821 // Ensure wrappers are instances of `baseLodash`.
11822 lodash.prototype = baseLodash.prototype;
11824 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
11825 LodashWrapper.prototype.constructor = LodashWrapper;
11827 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
11828 LazyWrapper.prototype.constructor = LazyWrapper;
11830 // Add functions to the `Map` cache.
11831 MapCache.prototype['delete'] = mapDelete;
11832 MapCache.prototype.get = mapGet;
11833 MapCache.prototype.has = mapHas;
11834 MapCache.prototype.set = mapSet;
11836 // Add functions to the `Set` cache.
11837 SetCache.prototype.push = cachePush;
11839 // Assign cache to `_.memoize`.
11840 memoize.Cache = MapCache;
11842 // Add functions that return wrapped values when chaining.
11843 lodash.after = after;
11845 lodash.assign = assign;
11847 lodash.before = before;
11848 lodash.bind = bind;
11849 lodash.bindAll = bindAll;
11850 lodash.bindKey = bindKey;
11851 lodash.callback = callback;
11852 lodash.chain = chain;
11853 lodash.chunk = chunk;
11854 lodash.compact = compact;
11855 lodash.constant = constant;
11856 lodash.countBy = countBy;
11857 lodash.create = create;
11858 lodash.curry = curry;
11859 lodash.curryRight = curryRight;
11860 lodash.debounce = debounce;
11861 lodash.defaults = defaults;
11862 lodash.defaultsDeep = defaultsDeep;
11863 lodash.defer = defer;
11864 lodash.delay = delay;
11865 lodash.difference = difference;
11866 lodash.drop = drop;
11867 lodash.dropRight = dropRight;
11868 lodash.dropRightWhile = dropRightWhile;
11869 lodash.dropWhile = dropWhile;
11870 lodash.fill = fill;
11871 lodash.filter = filter;
11872 lodash.flatten = flatten;
11873 lodash.flattenDeep = flattenDeep;
11874 lodash.flow = flow;
11875 lodash.flowRight = flowRight;
11876 lodash.forEach = forEach;
11877 lodash.forEachRight = forEachRight;
11878 lodash.forIn = forIn;
11879 lodash.forInRight = forInRight;
11880 lodash.forOwn = forOwn;
11881 lodash.forOwnRight = forOwnRight;
11882 lodash.functions = functions;
11883 lodash.groupBy = groupBy;
11884 lodash.indexBy = indexBy;
11885 lodash.initial = initial;
11886 lodash.intersection = intersection;
11887 lodash.invert = invert;
11888 lodash.invoke = invoke;
11889 lodash.keys = keys;
11890 lodash.keysIn = keysIn;
11892 lodash.mapKeys = mapKeys;
11893 lodash.mapValues = mapValues;
11894 lodash.matches = matches;
11895 lodash.matchesProperty = matchesProperty;
11896 lodash.memoize = memoize;
11897 lodash.merge = merge;
11898 lodash.method = method;
11899 lodash.methodOf = methodOf;
11900 lodash.mixin = mixin;
11901 lodash.modArgs = modArgs;
11902 lodash.negate = negate;
11903 lodash.omit = omit;
11904 lodash.once = once;
11905 lodash.pairs = pairs;
11906 lodash.partial = partial;
11907 lodash.partialRight = partialRight;
11908 lodash.partition = partition;
11909 lodash.pick = pick;
11910 lodash.pluck = pluck;
11911 lodash.property = property;
11912 lodash.propertyOf = propertyOf;
11913 lodash.pull = pull;
11914 lodash.pullAt = pullAt;
11915 lodash.range = range;
11916 lodash.rearg = rearg;
11917 lodash.reject = reject;
11918 lodash.remove = remove;
11919 lodash.rest = rest;
11920 lodash.restParam = restParam;
11922 lodash.shuffle = shuffle;
11923 lodash.slice = slice;
11924 lodash.sortBy = sortBy;
11925 lodash.sortByAll = sortByAll;
11926 lodash.sortByOrder = sortByOrder;
11927 lodash.spread = spread;
11928 lodash.take = take;
11929 lodash.takeRight = takeRight;
11930 lodash.takeRightWhile = takeRightWhile;
11931 lodash.takeWhile = takeWhile;
11933 lodash.throttle = throttle;
11934 lodash.thru = thru;
11935 lodash.times = times;
11936 lodash.toArray = toArray;
11937 lodash.toPlainObject = toPlainObject;
11938 lodash.transform = transform;
11939 lodash.union = union;
11940 lodash.uniq = uniq;
11941 lodash.unzip = unzip;
11942 lodash.unzipWith = unzipWith;
11943 lodash.values = values;
11944 lodash.valuesIn = valuesIn;
11945 lodash.where = where;
11946 lodash.without = without;
11947 lodash.wrap = wrap;
11950 lodash.zipObject = zipObject;
11951 lodash.zipWith = zipWith;
11954 lodash.backflow = flowRight;
11955 lodash.collect = map;
11956 lodash.compose = flowRight;
11957 lodash.each = forEach;
11958 lodash.eachRight = forEachRight;
11959 lodash.extend = assign;
11960 lodash.iteratee = callback;
11961 lodash.methods = functions;
11962 lodash.object = zipObject;
11963 lodash.select = filter;
11964 lodash.tail = rest;
11965 lodash.unique = uniq;
11967 // Add functions to `lodash.prototype`.
11968 mixin(lodash, lodash);
11970 /*------------------------------------------------------------------------*/
11972 // Add functions that return unwrapped values when chaining.
11974 lodash.attempt = attempt;
11975 lodash.camelCase = camelCase;
11976 lodash.capitalize = capitalize;
11977 lodash.ceil = ceil;
11978 lodash.clone = clone;
11979 lodash.cloneDeep = cloneDeep;
11980 lodash.deburr = deburr;
11981 lodash.endsWith = endsWith;
11982 lodash.escape = escape;
11983 lodash.escapeRegExp = escapeRegExp;
11984 lodash.every = every;
11985 lodash.find = find;
11986 lodash.findIndex = findIndex;
11987 lodash.findKey = findKey;
11988 lodash.findLast = findLast;
11989 lodash.findLastIndex = findLastIndex;
11990 lodash.findLastKey = findLastKey;
11991 lodash.findWhere = findWhere;
11992 lodash.first = first;
11993 lodash.floor = floor;
11998 lodash.identity = identity;
11999 lodash.includes = includes;
12000 lodash.indexOf = indexOf;
12001 lodash.inRange = inRange;
12002 lodash.isArguments = isArguments;
12003 lodash.isArray = isArray;
12004 lodash.isBoolean = isBoolean;
12005 lodash.isDate = isDate;
12006 lodash.isElement = isElement;
12007 lodash.isEmpty = isEmpty;
12008 lodash.isEqual = isEqual;
12009 lodash.isError = isError;
12010 lodash.isFinite = isFinite;
12011 lodash.isFunction = isFunction;
12012 lodash.isMatch = isMatch;
12013 lodash.isNaN = isNaN;
12014 lodash.isNative = isNative;
12015 lodash.isNull = isNull;
12016 lodash.isNumber = isNumber;
12017 lodash.isObject = isObject;
12018 lodash.isPlainObject = isPlainObject;
12019 lodash.isRegExp = isRegExp;
12020 lodash.isString = isString;
12021 lodash.isTypedArray = isTypedArray;
12022 lodash.isUndefined = isUndefined;
12023 lodash.kebabCase = kebabCase;
12024 lodash.last = last;
12025 lodash.lastIndexOf = lastIndexOf;
12030 lodash.noConflict = noConflict;
12031 lodash.noop = noop;
12034 lodash.padLeft = padLeft;
12035 lodash.padRight = padRight;
12036 lodash.parseInt = parseInt;
12037 lodash.random = random;
12038 lodash.reduce = reduce;
12039 lodash.reduceRight = reduceRight;
12040 lodash.repeat = repeat;
12041 lodash.result = result;
12042 lodash.round = round;
12043 lodash.runInContext = runInContext;
12044 lodash.size = size;
12045 lodash.snakeCase = snakeCase;
12046 lodash.some = some;
12047 lodash.sortedIndex = sortedIndex;
12048 lodash.sortedLastIndex = sortedLastIndex;
12049 lodash.startCase = startCase;
12050 lodash.startsWith = startsWith;
12052 lodash.template = template;
12053 lodash.trim = trim;
12054 lodash.trimLeft = trimLeft;
12055 lodash.trimRight = trimRight;
12056 lodash.trunc = trunc;
12057 lodash.unescape = unescape;
12058 lodash.uniqueId = uniqueId;
12059 lodash.words = words;
12062 lodash.all = every;
12064 lodash.contains = includes;
12065 lodash.eq = isEqual;
12066 lodash.detect = find;
12067 lodash.foldl = reduce;
12068 lodash.foldr = reduceRight;
12069 lodash.head = first;
12070 lodash.include = includes;
12071 lodash.inject = reduce;
12073 mixin(lodash, (function() {
12075 baseForOwn(lodash, function(func, methodName) {
12076 if (!lodash.prototype[methodName]) {
12077 source[methodName] = func;
12083 /*------------------------------------------------------------------------*/
12085 // Add functions capable of returning wrapped and unwrapped values when chaining.
12086 lodash.sample = sample;
12088 lodash.prototype.sample = function(n) {
12089 if (!this.__chain__ && n == null) {
12090 return sample(this.value());
12092 return this.thru(function(value) {
12093 return sample(value, n);
12097 /*------------------------------------------------------------------------*/
12100 * The semantic version number.
12106 lodash.VERSION = VERSION;
12108 // Assign default placeholders.
12109 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
12110 lodash[methodName].placeholder = lodash;
12113 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
12114 arrayEach(['drop', 'take'], function(methodName, index) {
12115 LazyWrapper.prototype[methodName] = function(n) {
12116 var filtered = this.__filtered__;
12117 if (filtered && !index) {
12118 return new LazyWrapper(this);
12120 n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
12122 var result = this.clone();
12124 result.__takeCount__ = nativeMin(result.__takeCount__, n);
12126 result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
12131 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
12132 return this.reverse()[methodName](n).reverse();
12136 // Add `LazyWrapper` methods that accept an `iteratee` value.
12137 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
12138 var type = index + 1,
12139 isFilter = type != LAZY_MAP_FLAG;
12141 LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
12142 var result = this.clone();
12143 result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
12144 result.__filtered__ = result.__filtered__ || isFilter;
12149 // Add `LazyWrapper` methods for `_.first` and `_.last`.
12150 arrayEach(['first', 'last'], function(methodName, index) {
12151 var takeName = 'take' + (index ? 'Right' : '');
12153 LazyWrapper.prototype[methodName] = function() {
12154 return this[takeName](1).value()[0];
12158 // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
12159 arrayEach(['initial', 'rest'], function(methodName, index) {
12160 var dropName = 'drop' + (index ? '' : 'Right');
12162 LazyWrapper.prototype[methodName] = function() {
12163 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
12167 // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
12168 arrayEach(['pluck', 'where'], function(methodName, index) {
12169 var operationName = index ? 'filter' : 'map',
12170 createCallback = index ? baseMatches : property;
12172 LazyWrapper.prototype[methodName] = function(value) {
12173 return this[operationName](createCallback(value));
12177 LazyWrapper.prototype.compact = function() {
12178 return this.filter(identity);
12181 LazyWrapper.prototype.reject = function(predicate, thisArg) {
12182 predicate = getCallback(predicate, thisArg, 1);
12183 return this.filter(function(value) {
12184 return !predicate(value);
12188 LazyWrapper.prototype.slice = function(start, end) {
12189 start = start == null ? 0 : (+start || 0);
12192 if (result.__filtered__ && (start > 0 || end < 0)) {
12193 return new LazyWrapper(result);
12196 result = result.takeRight(-start);
12197 } else if (start) {
12198 result = result.drop(start);
12200 if (end !== undefined) {
12202 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
12207 LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
12208 return this.reverse().takeWhile(predicate, thisArg).reverse();
12211 LazyWrapper.prototype.toArray = function() {
12212 return this.take(POSITIVE_INFINITY);
12215 // Add `LazyWrapper` methods to `lodash.prototype`.
12216 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12217 var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
12218 retUnwrapped = /^(?:first|last)$/.test(methodName),
12219 lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
12224 lodash.prototype[methodName] = function() {
12225 var args = retUnwrapped ? [1] : arguments,
12226 chainAll = this.__chain__,
12227 value = this.__wrapped__,
12228 isHybrid = !!this.__actions__.length,
12229 isLazy = value instanceof LazyWrapper,
12230 iteratee = args[0],
12231 useLazy = isLazy || isArray(value);
12233 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
12234 // Avoid lazy use if the iteratee has a "length" value other than `1`.
12235 isLazy = useLazy = false;
12237 var interceptor = function(value) {
12238 return (retUnwrapped && chainAll)
12239 ? lodashFunc(value, 1)[0]
12240 : lodashFunc.apply(undefined, arrayPush([value], args));
12243 var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
12244 onlyLazy = isLazy && !isHybrid;
12246 if (retUnwrapped && !chainAll) {
12248 value = value.clone();
12249 value.__actions__.push(action);
12250 return func.call(value);
12252 return lodashFunc.call(undefined, this.value())[0];
12254 if (!retUnwrapped && useLazy) {
12255 value = onlyLazy ? value : new LazyWrapper(this);
12256 var result = func.apply(value, args);
12257 result.__actions__.push(action);
12258 return new LodashWrapper(result, chainAll);
12260 return this.thru(interceptor);
12264 // Add `Array` and `String` methods to `lodash.prototype`.
12265 arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
12266 var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
12267 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
12268 retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
12270 lodash.prototype[methodName] = function() {
12271 var args = arguments;
12272 if (retUnwrapped && !this.__chain__) {
12273 return func.apply(this.value(), args);
12275 return this[chainName](function(value) {
12276 return func.apply(value, args);
12281 // Map minified function names to their real names.
12282 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12283 var lodashFunc = lodash[methodName];
12285 var key = lodashFunc.name,
12286 names = realNames[key] || (realNames[key] = []);
12288 names.push({ 'name': methodName, 'func': lodashFunc });
12292 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
12294 // Add functions to the lazy wrapper.
12295 LazyWrapper.prototype.clone = lazyClone;
12296 LazyWrapper.prototype.reverse = lazyReverse;
12297 LazyWrapper.prototype.value = lazyValue;
12299 // Add chaining functions to the `lodash` wrapper.
12300 lodash.prototype.chain = wrapperChain;
12301 lodash.prototype.commit = wrapperCommit;
12302 lodash.prototype.concat = wrapperConcat;
12303 lodash.prototype.plant = wrapperPlant;
12304 lodash.prototype.reverse = wrapperReverse;
12305 lodash.prototype.toString = wrapperToString;
12306 lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
12308 // Add function aliases to the `lodash` wrapper.
12309 lodash.prototype.collect = lodash.prototype.map;
12310 lodash.prototype.head = lodash.prototype.first;
12311 lodash.prototype.select = lodash.prototype.filter;
12312 lodash.prototype.tail = lodash.prototype.rest;
12317 /*--------------------------------------------------------------------------*/
12320 var _ = runInContext();
12322 // Some AMD build optimizers like r.js check for condition patterns like the following:
12323 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
12324 // Expose lodash to the global object when an AMD loader is present to avoid
12325 // errors in cases where lodash is loaded by a script tag and not intended
12326 // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
12330 // Define as an anonymous module so, through path mapping, it can be
12331 // referenced as the "underscore" module.
12332 define(function() {
12336 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
12337 else if (freeExports && freeModule) {
12338 // Export for Node.js or RingoJS.
12339 if (moduleExports) {
12340 (freeModule.exports = _)._ = _;
12342 // Export for Rhino with CommonJS support.
12348 // Export for a browser or Rhino.