3 * lodash 3.10.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash modern -o ./lodash.js`
5 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
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 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(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 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 other = lodash[funcName];
4146 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
4149 if (func === other) {
4152 var data = getData(other);
4153 return !!data && func === data[0];
4157 * Checks if `value` is a valid array-like length.
4159 * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
4162 * @param {*} value The value to check.
4163 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
4165 function isLength(value) {
4166 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
4170 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
4173 * @param {*} value The value to check.
4174 * @returns {boolean} Returns `true` if `value` if suitable for strict
4175 * equality comparisons, else `false`.
4177 function isStrictComparable(value) {
4178 return value === value && !isObject(value);
4182 * Merges the function metadata of `source` into `data`.
4184 * Merging metadata reduces the number of wrappers required to invoke a function.
4185 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
4186 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
4187 * augment function arguments, making the order in which they are executed important,
4188 * preventing the merging of metadata. However, we make an exception for a safe
4189 * common case where curried functions have `_.ary` and or `_.rearg` applied.
4192 * @param {Array} data The destination metadata.
4193 * @param {Array} source The source metadata.
4194 * @returns {Array} Returns `data`.
4196 function mergeData(data, source) {
4197 var bitmask = data[1],
4198 srcBitmask = source[1],
4199 newBitmask = bitmask | srcBitmask,
4200 isCommon = newBitmask < ARY_FLAG;
4203 (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
4204 (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
4205 (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
4207 // Exit early if metadata can't be merged.
4208 if (!(isCommon || isCombo)) {
4211 // Use source `thisArg` if available.
4212 if (srcBitmask & BIND_FLAG) {
4213 data[2] = source[2];
4214 // Set when currying a bound function.
4215 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
4217 // Compose partial arguments.
4218 var value = source[3];
4220 var partials = data[3];
4221 data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
4222 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
4224 // Compose partial right arguments.
4228 data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
4229 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
4231 // Use source `argPos` if available.
4234 data[7] = arrayCopy(value);
4236 // Use source `ary` if it's smaller.
4237 if (srcBitmask & ARY_FLAG) {
4238 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
4240 // Use source `arity` if one is not provided.
4241 if (data[9] == null) {
4242 data[9] = source[9];
4244 // Use source `func` and merge bitmasks.
4245 data[0] = source[0];
4246 data[1] = newBitmask;
4252 * Used by `_.defaultsDeep` to customize its `_.merge` use.
4255 * @param {*} objectValue The destination object property value.
4256 * @param {*} sourceValue The source object property value.
4257 * @returns {*} Returns the value to assign to the destination object.
4259 function mergeDefaults(objectValue, sourceValue) {
4260 return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
4264 * A specialized version of `_.pick` which picks `object` properties specified
4268 * @param {Object} object The source object.
4269 * @param {string[]} props The property names to pick.
4270 * @returns {Object} Returns the new object.
4272 function pickByArray(object, props) {
4273 object = toObject(object);
4276 length = props.length,
4279 while (++index < length) {
4280 var key = props[index];
4281 if (key in object) {
4282 result[key] = object[key];
4289 * A specialized version of `_.pick` which picks `object` properties `predicate`
4290 * returns truthy for.
4293 * @param {Object} object The source object.
4294 * @param {Function} predicate The function invoked per iteration.
4295 * @returns {Object} Returns the new object.
4297 function pickByCallback(object, predicate) {
4299 baseForIn(object, function(value, key, object) {
4300 if (predicate(value, key, object)) {
4301 result[key] = value;
4308 * Reorder `array` according to the specified indexes where the element at
4309 * the first index is assigned as the first element, the element at
4310 * the second index is assigned as the second element, and so on.
4313 * @param {Array} array The array to reorder.
4314 * @param {Array} indexes The arranged array indexes.
4315 * @returns {Array} Returns `array`.
4317 function reorder(array, indexes) {
4318 var arrLength = array.length,
4319 length = nativeMin(indexes.length, arrLength),
4320 oldArray = arrayCopy(array);
4323 var index = indexes[length];
4324 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
4330 * Sets metadata for `func`.
4332 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
4333 * period of time, it will trip its breaker and transition to an identity function
4334 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
4338 * @param {Function} func The function to associate metadata with.
4339 * @param {*} data The metadata.
4340 * @returns {Function} Returns `func`.
4342 var setData = (function() {
4346 return function(key, value) {
4348 remaining = HOT_SPAN - (stamp - lastCalled);
4351 if (remaining > 0) {
4352 if (++count >= HOT_COUNT) {
4358 return baseSetData(key, value);
4363 * A fallback implementation of `Object.keys` which creates an array of the
4364 * own enumerable property names of `object`.
4367 * @param {Object} object The object to query.
4368 * @returns {Array} Returns the array of property names.
4370 function shimKeys(object) {
4371 var props = keysIn(object),
4372 propsLength = props.length,
4373 length = propsLength && object.length;
4375 var allowIndexes = !!length && isLength(length) &&
4376 (isArray(object) || isArguments(object));
4381 while (++index < propsLength) {
4382 var key = props[index];
4383 if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
4391 * Converts `value` to an array-like object if it's not one.
4394 * @param {*} value The value to process.
4395 * @returns {Array|Object} Returns the array-like object.
4397 function toIterable(value) {
4398 if (value == null) {
4401 if (!isArrayLike(value)) {
4402 return values(value);
4404 return isObject(value) ? value : Object(value);
4408 * Converts `value` to an object if it's not one.
4411 * @param {*} value The value to process.
4412 * @returns {Object} Returns the object.
4414 function toObject(value) {
4415 return isObject(value) ? value : Object(value);
4419 * Converts `value` to property path array if it's not one.
4422 * @param {*} value The value to process.
4423 * @returns {Array} Returns the property path array.
4425 function toPath(value) {
4426 if (isArray(value)) {
4430 baseToString(value).replace(rePropName, function(match, number, quote, string) {
4431 result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
4437 * Creates a clone of `wrapper`.
4440 * @param {Object} wrapper The wrapper to clone.
4441 * @returns {Object} Returns the cloned wrapper.
4443 function wrapperClone(wrapper) {
4444 return wrapper instanceof LazyWrapper
4446 : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
4449 /*------------------------------------------------------------------------*/
4452 * Creates an array of elements split into groups the length of `size`.
4453 * If `collection` can't be split evenly, the final chunk will be the remaining
4459 * @param {Array} array The array to process.
4460 * @param {number} [size=1] The length of each chunk.
4461 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4462 * @returns {Array} Returns the new array containing chunks.
4465 * _.chunk(['a', 'b', 'c', 'd'], 2);
4466 * // => [['a', 'b'], ['c', 'd']]
4468 * _.chunk(['a', 'b', 'c', 'd'], 3);
4469 * // => [['a', 'b', 'c'], ['d']]
4471 function chunk(array, size, guard) {
4472 if (guard ? isIterateeCall(array, size, guard) : size == null) {
4475 size = nativeMax(nativeFloor(size) || 1, 1);
4478 length = array ? array.length : 0,
4480 result = Array(nativeCeil(length / size));
4482 while (index < length) {
4483 result[++resIndex] = baseSlice(array, index, (index += size));
4489 * Creates an array with all falsey values removed. The values `false`, `null`,
4490 * `0`, `""`, `undefined`, and `NaN` are falsey.
4495 * @param {Array} array The array to compact.
4496 * @returns {Array} Returns the new array of filtered values.
4499 * _.compact([0, 1, false, 2, '', 3]);
4502 function compact(array) {
4504 length = array ? array.length : 0,
4508 while (++index < length) {
4509 var value = array[index];
4511 result[++resIndex] = value;
4518 * Creates an array of unique `array` values not included in the other
4519 * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4520 * for equality comparisons.
4525 * @param {Array} array The array to inspect.
4526 * @param {...Array} [values] The arrays of values to exclude.
4527 * @returns {Array} Returns the new array of filtered values.
4530 * _.difference([1, 2, 3], [4, 2]);
4533 var difference = restParam(function(array, values) {
4534 return (isObjectLike(array) && isArrayLike(array))
4535 ? baseDifference(array, baseFlatten(values, false, true))
4540 * Creates a slice of `array` with `n` elements dropped from the beginning.
4545 * @param {Array} array The array to query.
4546 * @param {number} [n=1] The number of elements to drop.
4547 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4548 * @returns {Array} Returns the slice of `array`.
4551 * _.drop([1, 2, 3]);
4554 * _.drop([1, 2, 3], 2);
4557 * _.drop([1, 2, 3], 5);
4560 * _.drop([1, 2, 3], 0);
4563 function drop(array, n, guard) {
4564 var length = array ? array.length : 0;
4568 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4571 return baseSlice(array, n < 0 ? 0 : n);
4575 * Creates a slice of `array` with `n` elements dropped from the end.
4580 * @param {Array} array The array to query.
4581 * @param {number} [n=1] The number of elements to drop.
4582 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4583 * @returns {Array} Returns the slice of `array`.
4586 * _.dropRight([1, 2, 3]);
4589 * _.dropRight([1, 2, 3], 2);
4592 * _.dropRight([1, 2, 3], 5);
4595 * _.dropRight([1, 2, 3], 0);
4598 function dropRight(array, n, guard) {
4599 var length = array ? array.length : 0;
4603 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4606 n = length - (+n || 0);
4607 return baseSlice(array, 0, n < 0 ? 0 : n);
4611 * Creates a slice of `array` excluding elements dropped from the end.
4612 * Elements are dropped until `predicate` returns falsey. The predicate is
4613 * bound to `thisArg` and invoked with three arguments: (value, index, array).
4615 * If a property name is provided for `predicate` the created `_.property`
4616 * style callback returns the property value of the given element.
4618 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4619 * style callback returns `true` for elements that have a matching property
4620 * value, else `false`.
4622 * If an object is provided for `predicate` the created `_.matches` style
4623 * callback returns `true` for elements that match the properties of the given
4624 * object, else `false`.
4629 * @param {Array} array The array to query.
4630 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4632 * @param {*} [thisArg] The `this` binding of `predicate`.
4633 * @returns {Array} Returns the slice of `array`.
4636 * _.dropRightWhile([1, 2, 3], function(n) {
4642 * { 'user': 'barney', 'active': true },
4643 * { 'user': 'fred', 'active': false },
4644 * { 'user': 'pebbles', 'active': false }
4647 * // using the `_.matches` callback shorthand
4648 * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
4649 * // => ['barney', 'fred']
4651 * // using the `_.matchesProperty` callback shorthand
4652 * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
4655 * // using the `_.property` callback shorthand
4656 * _.pluck(_.dropRightWhile(users, 'active'), 'user');
4657 * // => ['barney', 'fred', 'pebbles']
4659 function dropRightWhile(array, predicate, thisArg) {
4660 return (array && array.length)
4661 ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
4666 * Creates a slice of `array` excluding elements dropped from the beginning.
4667 * Elements are dropped until `predicate` returns falsey. The predicate is
4668 * bound to `thisArg` and invoked with three arguments: (value, index, array).
4670 * If a property name is provided for `predicate` the created `_.property`
4671 * style callback returns the property value of the given element.
4673 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4674 * style callback returns `true` for elements that have a matching property
4675 * value, else `false`.
4677 * If an object is provided for `predicate` the created `_.matches` style
4678 * callback returns `true` for elements that have the properties of the given
4679 * object, else `false`.
4684 * @param {Array} array The array to query.
4685 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4687 * @param {*} [thisArg] The `this` binding of `predicate`.
4688 * @returns {Array} Returns the slice of `array`.
4691 * _.dropWhile([1, 2, 3], function(n) {
4697 * { 'user': 'barney', 'active': false },
4698 * { 'user': 'fred', 'active': false },
4699 * { 'user': 'pebbles', 'active': true }
4702 * // using the `_.matches` callback shorthand
4703 * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
4704 * // => ['fred', 'pebbles']
4706 * // using the `_.matchesProperty` callback shorthand
4707 * _.pluck(_.dropWhile(users, 'active', false), 'user');
4710 * // using the `_.property` callback shorthand
4711 * _.pluck(_.dropWhile(users, 'active'), 'user');
4712 * // => ['barney', 'fred', 'pebbles']
4714 function dropWhile(array, predicate, thisArg) {
4715 return (array && array.length)
4716 ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
4721 * Fills elements of `array` with `value` from `start` up to, but not
4724 * **Note:** This method mutates `array`.
4729 * @param {Array} array The array to fill.
4730 * @param {*} value The value to fill `array` with.
4731 * @param {number} [start=0] The start position.
4732 * @param {number} [end=array.length] The end position.
4733 * @returns {Array} Returns `array`.
4736 * var array = [1, 2, 3];
4738 * _.fill(array, 'a');
4739 * console.log(array);
4740 * // => ['a', 'a', 'a']
4742 * _.fill(Array(3), 2);
4745 * _.fill([4, 6, 8], '*', 1, 2);
4748 function fill(array, value, start, end) {
4749 var length = array ? array.length : 0;
4753 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
4757 return baseFill(array, value, start, end);
4761 * This method is like `_.find` except that it returns the index of the first
4762 * element `predicate` returns truthy for instead of the element itself.
4764 * If a property name is provided for `predicate` the created `_.property`
4765 * style callback returns the property value of the given element.
4767 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4768 * style callback returns `true` for elements that have a matching property
4769 * value, else `false`.
4771 * If an object is provided for `predicate` the created `_.matches` style
4772 * callback returns `true` for elements that have the properties of the given
4773 * object, else `false`.
4778 * @param {Array} array The array to search.
4779 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4781 * @param {*} [thisArg] The `this` binding of `predicate`.
4782 * @returns {number} Returns the index of the found element, else `-1`.
4786 * { 'user': 'barney', 'active': false },
4787 * { 'user': 'fred', 'active': false },
4788 * { 'user': 'pebbles', 'active': true }
4791 * _.findIndex(users, function(chr) {
4792 * return chr.user == 'barney';
4796 * // using the `_.matches` callback shorthand
4797 * _.findIndex(users, { 'user': 'fred', 'active': false });
4800 * // using the `_.matchesProperty` callback shorthand
4801 * _.findIndex(users, 'active', false);
4804 * // using the `_.property` callback shorthand
4805 * _.findIndex(users, 'active');
4808 var findIndex = createFindIndex();
4811 * This method is like `_.findIndex` except that it iterates over elements
4812 * of `collection` from right to left.
4814 * If a property name is provided for `predicate` the created `_.property`
4815 * style callback returns the property value of the given element.
4817 * If a value is also provided for `thisArg` the created `_.matchesProperty`
4818 * style callback returns `true` for elements that have a matching property
4819 * value, else `false`.
4821 * If an object is provided for `predicate` the created `_.matches` style
4822 * callback returns `true` for elements that have the properties of the given
4823 * object, else `false`.
4828 * @param {Array} array The array to search.
4829 * @param {Function|Object|string} [predicate=_.identity] The function invoked
4831 * @param {*} [thisArg] The `this` binding of `predicate`.
4832 * @returns {number} Returns the index of the found element, else `-1`.
4836 * { 'user': 'barney', 'active': true },
4837 * { 'user': 'fred', 'active': false },
4838 * { 'user': 'pebbles', 'active': false }
4841 * _.findLastIndex(users, function(chr) {
4842 * return chr.user == 'pebbles';
4846 * // using the `_.matches` callback shorthand
4847 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
4850 * // using the `_.matchesProperty` callback shorthand
4851 * _.findLastIndex(users, 'active', false);
4854 * // using the `_.property` callback shorthand
4855 * _.findLastIndex(users, 'active');
4858 var findLastIndex = createFindIndex(true);
4861 * Gets the first element of `array`.
4867 * @param {Array} array The array to query.
4868 * @returns {*} Returns the first element of `array`.
4871 * _.first([1, 2, 3]);
4877 function first(array) {
4878 return array ? array[0] : undefined;
4882 * Flattens a nested array. If `isDeep` is `true` the array is recursively
4883 * flattened, otherwise it's only flattened a single level.
4888 * @param {Array} array The array to flatten.
4889 * @param {boolean} [isDeep] Specify a deep flatten.
4890 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4891 * @returns {Array} Returns the new flattened array.
4894 * _.flatten([1, [2, 3, [4]]]);
4895 * // => [1, 2, 3, [4]]
4898 * _.flatten([1, [2, 3, [4]]], true);
4899 * // => [1, 2, 3, 4]
4901 function flatten(array, isDeep, guard) {
4902 var length = array ? array.length : 0;
4903 if (guard && isIterateeCall(array, isDeep, guard)) {
4906 return length ? baseFlatten(array, isDeep) : [];
4910 * Recursively flattens a nested array.
4915 * @param {Array} array The array to recursively flatten.
4916 * @returns {Array} Returns the new flattened array.
4919 * _.flattenDeep([1, [2, 3, [4]]]);
4920 * // => [1, 2, 3, 4]
4922 function flattenDeep(array) {
4923 var length = array ? array.length : 0;
4924 return length ? baseFlatten(array, true) : [];
4928 * Gets the index at which the first occurrence of `value` is found in `array`
4929 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4930 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
4931 * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
4932 * performs a faster binary search.
4937 * @param {Array} array The array to search.
4938 * @param {*} value The value to search for.
4939 * @param {boolean|number} [fromIndex=0] The index to search from or `true`
4940 * to perform a binary search on a sorted array.
4941 * @returns {number} Returns the index of the matched value, else `-1`.
4944 * _.indexOf([1, 2, 1, 2], 2);
4947 * // using `fromIndex`
4948 * _.indexOf([1, 2, 1, 2], 2, 2);
4951 * // performing a binary search
4952 * _.indexOf([1, 1, 2, 2], 2, true);
4955 function indexOf(array, value, fromIndex) {
4956 var length = array ? array.length : 0;
4960 if (typeof fromIndex == 'number') {
4961 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
4962 } else if (fromIndex) {
4963 var index = binaryIndex(array, value);
4964 if (index < length &&
4965 (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
4970 return baseIndexOf(array, value, fromIndex || 0);
4974 * Gets all but the last element of `array`.
4979 * @param {Array} array The array to query.
4980 * @returns {Array} Returns the slice of `array`.
4983 * _.initial([1, 2, 3]);
4986 function initial(array) {
4987 return dropRight(array, 1);
4991 * Creates an array of unique values that are included in all of the provided
4992 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
4993 * for equality comparisons.
4998 * @param {...Array} [arrays] The arrays to inspect.
4999 * @returns {Array} Returns the new array of shared values.
5001 * _.intersection([1, 2], [4, 2], [2, 1]);
5004 var intersection = restParam(function(arrays) {
5005 var othLength = arrays.length,
5006 othIndex = othLength,
5007 caches = Array(length),
5008 indexOf = getIndexOf(),
5009 isCommon = indexOf === baseIndexOf,
5012 while (othIndex--) {
5013 var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
5014 caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
5016 var array = arrays[0],
5018 length = array ? array.length : 0,
5022 while (++index < length) {
5023 value = array[index];
5024 if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
5025 var othIndex = othLength;
5026 while (--othIndex) {
5027 var cache = caches[othIndex];
5028 if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
5042 * Gets the last element of `array`.
5047 * @param {Array} array The array to query.
5048 * @returns {*} Returns the last element of `array`.
5051 * _.last([1, 2, 3]);
5054 function last(array) {
5055 var length = array ? array.length : 0;
5056 return length ? array[length - 1] : undefined;
5060 * This method is like `_.indexOf` except that it iterates over elements of
5061 * `array` from right to left.
5066 * @param {Array} array The array to search.
5067 * @param {*} value The value to search for.
5068 * @param {boolean|number} [fromIndex=array.length-1] The index to search from
5069 * or `true` to perform a binary search on a sorted array.
5070 * @returns {number} Returns the index of the matched value, else `-1`.
5073 * _.lastIndexOf([1, 2, 1, 2], 2);
5076 * // using `fromIndex`
5077 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
5080 * // performing a binary search
5081 * _.lastIndexOf([1, 1, 2, 2], 2, true);
5084 function lastIndexOf(array, value, fromIndex) {
5085 var length = array ? array.length : 0;
5090 if (typeof fromIndex == 'number') {
5091 index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
5092 } else if (fromIndex) {
5093 index = binaryIndex(array, value, true) - 1;
5094 var other = array[index];
5095 if (value === value ? (value === other) : (other !== other)) {
5100 if (value !== value) {
5101 return indexOfNaN(array, index, true);
5104 if (array[index] === value) {
5112 * Removes all provided values from `array` using
5113 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5114 * for equality comparisons.
5116 * **Note:** Unlike `_.without`, this method mutates `array`.
5121 * @param {Array} array The array to modify.
5122 * @param {...*} [values] The values to remove.
5123 * @returns {Array} Returns `array`.
5126 * var array = [1, 2, 3, 1, 2, 3];
5128 * _.pull(array, 2, 3);
5129 * console.log(array);
5133 var args = arguments,
5136 if (!(array && array.length)) {
5140 indexOf = getIndexOf(),
5141 length = args.length;
5143 while (++index < length) {
5145 value = args[index];
5147 while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
5148 splice.call(array, fromIndex, 1);
5155 * Removes elements from `array` corresponding to the given indexes and returns
5156 * an array of the removed elements. Indexes may be specified as an array of
5157 * indexes or as individual arguments.
5159 * **Note:** Unlike `_.at`, this method mutates `array`.
5164 * @param {Array} array The array to modify.
5165 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
5166 * specified as individual indexes or arrays of indexes.
5167 * @returns {Array} Returns the new array of removed elements.
5170 * var array = [5, 10, 15, 20];
5171 * var evens = _.pullAt(array, 1, 3);
5173 * console.log(array);
5176 * console.log(evens);
5179 var pullAt = restParam(function(array, indexes) {
5180 indexes = baseFlatten(indexes);
5182 var result = baseAt(array, indexes);
5183 basePullAt(array, indexes.sort(baseCompareAscending));
5188 * Removes all elements from `array` that `predicate` returns truthy for
5189 * and returns an array of the removed elements. The predicate is bound to
5190 * `thisArg` and invoked with three arguments: (value, index, array).
5192 * If a property name is provided for `predicate` the created `_.property`
5193 * style callback returns the property value of the given element.
5195 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5196 * style callback returns `true` for elements that have a matching property
5197 * value, else `false`.
5199 * If an object is provided for `predicate` the created `_.matches` style
5200 * callback returns `true` for elements that have the properties of the given
5201 * object, else `false`.
5203 * **Note:** Unlike `_.filter`, this method mutates `array`.
5208 * @param {Array} array The array to modify.
5209 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5211 * @param {*} [thisArg] The `this` binding of `predicate`.
5212 * @returns {Array} Returns the new array of removed elements.
5215 * var array = [1, 2, 3, 4];
5216 * var evens = _.remove(array, function(n) {
5217 * return n % 2 == 0;
5220 * console.log(array);
5223 * console.log(evens);
5226 function remove(array, predicate, thisArg) {
5228 if (!(array && array.length)) {
5233 length = array.length;
5235 predicate = getCallback(predicate, thisArg, 3);
5236 while (++index < length) {
5237 var value = array[index];
5238 if (predicate(value, index, array)) {
5240 indexes.push(index);
5243 basePullAt(array, indexes);
5248 * Gets all but the first element of `array`.
5254 * @param {Array} array The array to query.
5255 * @returns {Array} Returns the slice of `array`.
5258 * _.rest([1, 2, 3]);
5261 function rest(array) {
5262 return drop(array, 1);
5266 * Creates a slice of `array` from `start` up to, but not including, `end`.
5268 * **Note:** This method is used instead of `Array#slice` to support node
5269 * lists in IE < 9 and to ensure dense arrays are returned.
5274 * @param {Array} array The array to slice.
5275 * @param {number} [start=0] The start position.
5276 * @param {number} [end=array.length] The end position.
5277 * @returns {Array} Returns the slice of `array`.
5279 function slice(array, start, end) {
5280 var length = array ? array.length : 0;
5284 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
5288 return baseSlice(array, start, end);
5292 * Uses a binary search to determine the lowest index at which `value` should
5293 * be inserted into `array` in order to maintain its sort order. If an iteratee
5294 * function is provided it's invoked for `value` and each element of `array`
5295 * to compute their sort ranking. The iteratee is bound to `thisArg` and
5296 * invoked with one argument; (value).
5298 * If a property name is provided for `iteratee` the created `_.property`
5299 * style callback returns the property value of the given element.
5301 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5302 * style callback returns `true` for elements that have a matching property
5303 * value, else `false`.
5305 * If an object is provided for `iteratee` the created `_.matches` style
5306 * callback returns `true` for elements that have the properties of the given
5307 * object, else `false`.
5312 * @param {Array} array The sorted array to inspect.
5313 * @param {*} value The value to evaluate.
5314 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5316 * @param {*} [thisArg] The `this` binding of `iteratee`.
5317 * @returns {number} Returns the index at which `value` should be inserted
5321 * _.sortedIndex([30, 50], 40);
5324 * _.sortedIndex([4, 4, 5, 5], 5);
5327 * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
5329 * // using an iteratee function
5330 * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
5331 * return this.data[word];
5335 * // using the `_.property` callback shorthand
5336 * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
5339 var sortedIndex = createSortedIndex();
5342 * This method is like `_.sortedIndex` except that it returns the highest
5343 * index at which `value` should be inserted into `array` in order to
5344 * maintain its sort order.
5349 * @param {Array} array The sorted array to inspect.
5350 * @param {*} value The value to evaluate.
5351 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5353 * @param {*} [thisArg] The `this` binding of `iteratee`.
5354 * @returns {number} Returns the index at which `value` should be inserted
5358 * _.sortedLastIndex([4, 4, 5, 5], 5);
5361 var sortedLastIndex = createSortedIndex(true);
5364 * Creates a slice of `array` with `n` elements taken from the beginning.
5369 * @param {Array} array The array to query.
5370 * @param {number} [n=1] The number of elements to take.
5371 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5372 * @returns {Array} Returns the slice of `array`.
5375 * _.take([1, 2, 3]);
5378 * _.take([1, 2, 3], 2);
5381 * _.take([1, 2, 3], 5);
5384 * _.take([1, 2, 3], 0);
5387 function take(array, n, guard) {
5388 var length = array ? array.length : 0;
5392 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5395 return baseSlice(array, 0, n < 0 ? 0 : n);
5399 * Creates a slice of `array` with `n` elements taken from the end.
5404 * @param {Array} array The array to query.
5405 * @param {number} [n=1] The number of elements to take.
5406 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5407 * @returns {Array} Returns the slice of `array`.
5410 * _.takeRight([1, 2, 3]);
5413 * _.takeRight([1, 2, 3], 2);
5416 * _.takeRight([1, 2, 3], 5);
5419 * _.takeRight([1, 2, 3], 0);
5422 function takeRight(array, n, guard) {
5423 var length = array ? array.length : 0;
5427 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5430 n = length - (+n || 0);
5431 return baseSlice(array, n < 0 ? 0 : n);
5435 * Creates a slice of `array` with elements taken from the end. Elements are
5436 * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
5437 * and invoked with three arguments: (value, index, array).
5439 * If a property name is provided for `predicate` the created `_.property`
5440 * style callback returns the property value of the given element.
5442 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5443 * style callback returns `true` for elements that have a matching property
5444 * value, else `false`.
5446 * If an object is provided for `predicate` the created `_.matches` style
5447 * callback returns `true` for elements that have the properties of the given
5448 * object, else `false`.
5453 * @param {Array} array The array to query.
5454 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5456 * @param {*} [thisArg] The `this` binding of `predicate`.
5457 * @returns {Array} Returns the slice of `array`.
5460 * _.takeRightWhile([1, 2, 3], function(n) {
5466 * { 'user': 'barney', 'active': true },
5467 * { 'user': 'fred', 'active': false },
5468 * { 'user': 'pebbles', 'active': false }
5471 * // using the `_.matches` callback shorthand
5472 * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
5475 * // using the `_.matchesProperty` callback shorthand
5476 * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
5477 * // => ['fred', 'pebbles']
5479 * // using the `_.property` callback shorthand
5480 * _.pluck(_.takeRightWhile(users, 'active'), 'user');
5483 function takeRightWhile(array, predicate, thisArg) {
5484 return (array && array.length)
5485 ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
5490 * Creates a slice of `array` with elements taken from the beginning. Elements
5491 * are taken until `predicate` returns falsey. The predicate is bound to
5492 * `thisArg` and invoked with three arguments: (value, index, array).
5494 * If a property name is provided for `predicate` the created `_.property`
5495 * style callback returns the property value of the given element.
5497 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5498 * style callback returns `true` for elements that have a matching property
5499 * value, else `false`.
5501 * If an object is provided for `predicate` the created `_.matches` style
5502 * callback returns `true` for elements that have the properties of the given
5503 * object, else `false`.
5508 * @param {Array} array The array to query.
5509 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5511 * @param {*} [thisArg] The `this` binding of `predicate`.
5512 * @returns {Array} Returns the slice of `array`.
5515 * _.takeWhile([1, 2, 3], function(n) {
5521 * { 'user': 'barney', 'active': false },
5522 * { 'user': 'fred', 'active': false},
5523 * { 'user': 'pebbles', 'active': true }
5526 * // using the `_.matches` callback shorthand
5527 * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
5530 * // using the `_.matchesProperty` callback shorthand
5531 * _.pluck(_.takeWhile(users, 'active', false), 'user');
5532 * // => ['barney', 'fred']
5534 * // using the `_.property` callback shorthand
5535 * _.pluck(_.takeWhile(users, 'active'), 'user');
5538 function takeWhile(array, predicate, thisArg) {
5539 return (array && array.length)
5540 ? baseWhile(array, getCallback(predicate, thisArg, 3))
5545 * Creates an array of unique values, in order, from all of the provided arrays
5546 * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5547 * for equality comparisons.
5552 * @param {...Array} [arrays] The arrays to inspect.
5553 * @returns {Array} Returns the new array of combined values.
5556 * _.union([1, 2], [4, 2], [2, 1]);
5559 var union = restParam(function(arrays) {
5560 return baseUniq(baseFlatten(arrays, false, true));
5564 * Creates a duplicate-free version of an array, using
5565 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5566 * for equality comparisons, in which only the first occurence of each element
5567 * is kept. Providing `true` for `isSorted` performs a faster search algorithm
5568 * for sorted arrays. If an iteratee function is provided it's invoked for
5569 * each element in the array to generate the criterion by which uniqueness
5570 * is computed. The `iteratee` is bound to `thisArg` and invoked with three
5571 * arguments: (value, index, array).
5573 * If a property name is provided for `iteratee` the created `_.property`
5574 * style callback returns the property value of the given element.
5576 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5577 * style callback returns `true` for elements that have a matching property
5578 * value, else `false`.
5580 * If an object is provided for `iteratee` the created `_.matches` style
5581 * callback returns `true` for elements that have the properties of the given
5582 * object, else `false`.
5588 * @param {Array} array The array to inspect.
5589 * @param {boolean} [isSorted] Specify the array is sorted.
5590 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
5591 * @param {*} [thisArg] The `this` binding of `iteratee`.
5592 * @returns {Array} Returns the new duplicate-value-free array.
5595 * _.uniq([2, 1, 2]);
5598 * // using `isSorted`
5599 * _.uniq([1, 1, 2], true);
5602 * // using an iteratee function
5603 * _.uniq([1, 2.5, 1.5, 2], function(n) {
5604 * return this.floor(n);
5608 * // using the `_.property` callback shorthand
5609 * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
5610 * // => [{ 'x': 1 }, { 'x': 2 }]
5612 function uniq(array, isSorted, iteratee, thisArg) {
5613 var length = array ? array.length : 0;
5617 if (isSorted != null && typeof isSorted != 'boolean') {
5619 iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
5622 var callback = getCallback();
5623 if (!(iteratee == null && callback === baseCallback)) {
5624 iteratee = callback(iteratee, thisArg, 3);
5626 return (isSorted && getIndexOf() === baseIndexOf)
5627 ? sortedUniq(array, iteratee)
5628 : baseUniq(array, iteratee);
5632 * This method is like `_.zip` except that it accepts an array of grouped
5633 * elements and creates an array regrouping the elements to their pre-zip
5639 * @param {Array} array The array of grouped elements to process.
5640 * @returns {Array} Returns the new array of regrouped elements.
5643 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
5644 * // => [['fred', 30, true], ['barney', 40, false]]
5647 * // => [['fred', 'barney'], [30, 40], [true, false]]
5649 function unzip(array) {
5650 if (!(array && array.length)) {
5656 array = arrayFilter(array, function(group) {
5657 if (isArrayLike(group)) {
5658 length = nativeMax(group.length, length);
5662 var result = Array(length);
5663 while (++index < length) {
5664 result[index] = arrayMap(array, baseProperty(index));
5670 * This method is like `_.unzip` except that it accepts an iteratee to specify
5671 * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
5672 * and invoked with four arguments: (accumulator, value, index, group).
5677 * @param {Array} array The array of grouped elements to process.
5678 * @param {Function} [iteratee] The function to combine regrouped values.
5679 * @param {*} [thisArg] The `this` binding of `iteratee`.
5680 * @returns {Array} Returns the new array of regrouped elements.
5683 * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
5684 * // => [[1, 10, 100], [2, 20, 200]]
5686 * _.unzipWith(zipped, _.add);
5687 * // => [3, 30, 300]
5689 function unzipWith(array, iteratee, thisArg) {
5690 var length = array ? array.length : 0;
5694 var result = unzip(array);
5695 if (iteratee == null) {
5698 iteratee = bindCallback(iteratee, thisArg, 4);
5699 return arrayMap(result, function(group) {
5700 return arrayReduce(group, iteratee, undefined, true);
5705 * Creates an array excluding all provided values using
5706 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
5707 * for equality comparisons.
5712 * @param {Array} array The array to filter.
5713 * @param {...*} [values] The values to exclude.
5714 * @returns {Array} Returns the new array of filtered values.
5717 * _.without([1, 2, 1, 3], 1, 2);
5720 var without = restParam(function(array, values) {
5721 return isArrayLike(array)
5722 ? baseDifference(array, values)
5727 * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
5728 * of the provided arrays.
5733 * @param {...Array} [arrays] The arrays to inspect.
5734 * @returns {Array} Returns the new array of values.
5737 * _.xor([1, 2], [4, 2]);
5742 length = arguments.length;
5744 while (++index < length) {
5745 var array = arguments[index];
5746 if (isArrayLike(array)) {
5748 ? arrayPush(baseDifference(result, array), baseDifference(array, result))
5752 return result ? baseUniq(result) : [];
5756 * Creates an array of grouped elements, the first of which contains the first
5757 * elements of the given arrays, the second of which contains the second elements
5758 * of the given arrays, and so on.
5763 * @param {...Array} [arrays] The arrays to process.
5764 * @returns {Array} Returns the new array of grouped elements.
5767 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
5768 * // => [['fred', 30, true], ['barney', 40, false]]
5770 var zip = restParam(unzip);
5773 * The inverse of `_.pairs`; this method returns an object composed from arrays
5774 * of property names and values. Provide either a single two dimensional array,
5775 * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
5776 * and one of corresponding values.
5782 * @param {Array} props The property names.
5783 * @param {Array} [values=[]] The property values.
5784 * @returns {Object} Returns the new object.
5787 * _.zipObject([['fred', 30], ['barney', 40]]);
5788 * // => { 'fred': 30, 'barney': 40 }
5790 * _.zipObject(['fred', 'barney'], [30, 40]);
5791 * // => { 'fred': 30, 'barney': 40 }
5793 function zipObject(props, values) {
5795 length = props ? props.length : 0,
5798 if (length && !values && !isArray(props[0])) {
5801 while (++index < length) {
5802 var key = props[index];
5804 result[key] = values[index];
5806 result[key[0]] = key[1];
5813 * This method is like `_.zip` except that it accepts an iteratee to specify
5814 * how grouped values should be combined. The `iteratee` is bound to `thisArg`
5815 * and invoked with four arguments: (accumulator, value, index, group).
5820 * @param {...Array} [arrays] The arrays to process.
5821 * @param {Function} [iteratee] The function to combine grouped values.
5822 * @param {*} [thisArg] The `this` binding of `iteratee`.
5823 * @returns {Array} Returns the new array of grouped elements.
5826 * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
5829 var zipWith = restParam(function(arrays) {
5830 var length = arrays.length,
5831 iteratee = length > 2 ? arrays[length - 2] : undefined,
5832 thisArg = length > 1 ? arrays[length - 1] : undefined;
5834 if (length > 2 && typeof iteratee == 'function') {
5837 iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
5838 thisArg = undefined;
5840 arrays.length = length;
5841 return unzipWith(arrays, iteratee, thisArg);
5844 /*------------------------------------------------------------------------*/
5847 * Creates a `lodash` object that wraps `value` with explicit method
5853 * @param {*} value The value to wrap.
5854 * @returns {Object} Returns the new `lodash` wrapper instance.
5858 * { 'user': 'barney', 'age': 36 },
5859 * { 'user': 'fred', 'age': 40 },
5860 * { 'user': 'pebbles', 'age': 1 }
5863 * var youngest = _.chain(users)
5865 * .map(function(chr) {
5866 * return chr.user + ' is ' + chr.age;
5870 * // => 'pebbles is 1'
5872 function chain(value) {
5873 var result = lodash(value);
5874 result.__chain__ = true;
5879 * This method invokes `interceptor` and returns `value`. The interceptor is
5880 * bound to `thisArg` and invoked with one argument; (value). The purpose of
5881 * this method is to "tap into" a method chain in order to perform operations
5882 * on intermediate results within the chain.
5887 * @param {*} value The value to provide to `interceptor`.
5888 * @param {Function} interceptor The function to invoke.
5889 * @param {*} [thisArg] The `this` binding of `interceptor`.
5890 * @returns {*} Returns `value`.
5894 * .tap(function(array) {
5901 function tap(value, interceptor, thisArg) {
5902 interceptor.call(thisArg, value);
5907 * This method is like `_.tap` except that it returns the result of `interceptor`.
5912 * @param {*} value The value to provide to `interceptor`.
5913 * @param {Function} interceptor The function to invoke.
5914 * @param {*} [thisArg] The `this` binding of `interceptor`.
5915 * @returns {*} Returns the result of `interceptor`.
5921 * .thru(function(value) {
5927 function thru(value, interceptor, thisArg) {
5928 return interceptor.call(thisArg, value);
5932 * Enables explicit method chaining on the wrapper object.
5937 * @returns {Object} Returns the new `lodash` wrapper instance.
5941 * { 'user': 'barney', 'age': 36 },
5942 * { 'user': 'fred', 'age': 40 }
5945 * // without explicit chaining
5947 * // => { 'user': 'barney', 'age': 36 }
5949 * // with explicit chaining
5954 * // => { 'user': 'barney' }
5956 function wrapperChain() {
5961 * Executes the chained sequence and returns the wrapped result.
5966 * @returns {Object} Returns the new `lodash` wrapper instance.
5969 * var array = [1, 2];
5970 * var wrapped = _(array).push(3);
5972 * console.log(array);
5975 * wrapped = wrapped.commit();
5976 * console.log(array);
5982 * console.log(array);
5985 function wrapperCommit() {
5986 return new LodashWrapper(this.value(), this.__chain__);
5990 * Creates a new array joining a wrapped array with any additional arrays
5996 * @param {...*} [values] The values to concatenate.
5997 * @returns {Array} Returns the new concatenated array.
6001 * var wrapped = _(array).concat(2, [3], [[4]]);
6003 * console.log(wrapped.value());
6004 * // => [1, 2, 3, [4]]
6006 * console.log(array);
6009 var wrapperConcat = restParam(function(values) {
6010 values = baseFlatten(values);
6011 return this.thru(function(array) {
6012 return arrayConcat(isArray(array) ? array : [toObject(array)], values);
6017 * Creates a clone of the chained sequence planting `value` as the wrapped value.
6022 * @returns {Object} Returns the new `lodash` wrapper instance.
6025 * var array = [1, 2];
6026 * var wrapped = _(array).map(function(value) {
6027 * return Math.pow(value, 2);
6030 * var other = [3, 4];
6031 * var otherWrapped = wrapped.plant(other);
6033 * otherWrapped.value();
6039 function wrapperPlant(value) {
6043 while (parent instanceof baseLodash) {
6044 var clone = wrapperClone(parent);
6046 previous.__wrapped__ = clone;
6050 var previous = clone;
6051 parent = parent.__wrapped__;
6053 previous.__wrapped__ = value;
6058 * Reverses the wrapped array so the first element becomes the last, the
6059 * second element becomes the second to last, and so on.
6061 * **Note:** This method mutates the wrapped array.
6066 * @returns {Object} Returns the new reversed `lodash` wrapper instance.
6069 * var array = [1, 2, 3];
6071 * _(array).reverse().value()
6074 * console.log(array);
6077 function wrapperReverse() {
6078 var value = this.__wrapped__;
6080 var interceptor = function(value) {
6081 return value.reverse();
6083 if (value instanceof LazyWrapper) {
6084 var wrapped = value;
6085 if (this.__actions__.length) {
6086 wrapped = new LazyWrapper(this);
6088 wrapped = wrapped.reverse();
6089 wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
6090 return new LodashWrapper(wrapped, this.__chain__);
6092 return this.thru(interceptor);
6096 * Produces the result of coercing the unwrapped value to a string.
6101 * @returns {string} Returns the coerced string value.
6104 * _([1, 2, 3]).toString();
6107 function wrapperToString() {
6108 return (this.value() + '');
6112 * Executes the chained sequence to extract the unwrapped value.
6116 * @alias run, toJSON, valueOf
6118 * @returns {*} Returns the resolved unwrapped value.
6121 * _([1, 2, 3]).value();
6124 function wrapperValue() {
6125 return baseWrapperValue(this.__wrapped__, this.__actions__);
6128 /*------------------------------------------------------------------------*/
6131 * Creates an array of elements corresponding to the given keys, or indexes,
6132 * of `collection`. Keys may be specified as individual arguments or as arrays
6137 * @category Collection
6138 * @param {Array|Object|string} collection The collection to iterate over.
6139 * @param {...(number|number[]|string|string[])} [props] The property names
6140 * or indexes of elements to pick, specified individually or in arrays.
6141 * @returns {Array} Returns the new array of picked elements.
6144 * _.at(['a', 'b', 'c'], [0, 2]);
6147 * _.at(['barney', 'fred', 'pebbles'], 0, 2);
6148 * // => ['barney', 'pebbles']
6150 var at = restParam(function(collection, props) {
6151 return baseAt(collection, baseFlatten(props));
6155 * Creates an object composed of keys generated from the results of running
6156 * each element of `collection` through `iteratee`. The corresponding value
6157 * of each key is the number of times the key was returned by `iteratee`.
6158 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6159 * (value, index|key, collection).
6161 * If a property name is provided for `iteratee` the created `_.property`
6162 * style callback returns the property value of the given element.
6164 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6165 * style callback returns `true` for elements that have a matching property
6166 * value, else `false`.
6168 * If an object is provided for `iteratee` the created `_.matches` style
6169 * callback returns `true` for elements that have the properties of the given
6170 * object, else `false`.
6174 * @category Collection
6175 * @param {Array|Object|string} collection The collection to iterate over.
6176 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6178 * @param {*} [thisArg] The `this` binding of `iteratee`.
6179 * @returns {Object} Returns the composed aggregate object.
6182 * _.countBy([4.3, 6.1, 6.4], function(n) {
6183 * return Math.floor(n);
6185 * // => { '4': 1, '6': 2 }
6187 * _.countBy([4.3, 6.1, 6.4], function(n) {
6188 * return this.floor(n);
6190 * // => { '4': 1, '6': 2 }
6192 * _.countBy(['one', 'two', 'three'], 'length');
6193 * // => { '3': 2, '5': 1 }
6195 var countBy = createAggregator(function(result, value, key) {
6196 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
6200 * Checks if `predicate` returns truthy for **all** elements of `collection`.
6201 * The predicate is bound to `thisArg` and invoked with three arguments:
6202 * (value, index|key, collection).
6204 * If a property name is provided for `predicate` the created `_.property`
6205 * style callback returns the property value of the given element.
6207 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6208 * style callback returns `true` for elements that have a matching property
6209 * value, else `false`.
6211 * If an object is provided for `predicate` the created `_.matches` style
6212 * callback returns `true` for elements that have the properties of the given
6213 * object, else `false`.
6218 * @category Collection
6219 * @param {Array|Object|string} collection The collection to iterate over.
6220 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6222 * @param {*} [thisArg] The `this` binding of `predicate`.
6223 * @returns {boolean} Returns `true` if all elements pass the predicate check,
6227 * _.every([true, 1, null, 'yes'], Boolean);
6231 * { 'user': 'barney', 'active': false },
6232 * { 'user': 'fred', 'active': false }
6235 * // using the `_.matches` callback shorthand
6236 * _.every(users, { 'user': 'barney', 'active': false });
6239 * // using the `_.matchesProperty` callback shorthand
6240 * _.every(users, 'active', false);
6243 * // using the `_.property` callback shorthand
6244 * _.every(users, 'active');
6247 function every(collection, predicate, thisArg) {
6248 var func = isArray(collection) ? arrayEvery : baseEvery;
6249 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
6250 predicate = undefined;
6252 if (typeof predicate != 'function' || thisArg !== undefined) {
6253 predicate = getCallback(predicate, thisArg, 3);
6255 return func(collection, predicate);
6259 * Iterates over elements of `collection`, returning an array of all elements
6260 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6261 * invoked with three arguments: (value, index|key, collection).
6263 * If a property name is provided for `predicate` the created `_.property`
6264 * style callback returns the property value of the given element.
6266 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6267 * style callback returns `true` for elements that have a matching property
6268 * value, else `false`.
6270 * If an object is provided for `predicate` the created `_.matches` style
6271 * callback returns `true` for elements that have the properties of the given
6272 * object, else `false`.
6277 * @category Collection
6278 * @param {Array|Object|string} collection The collection to iterate over.
6279 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6281 * @param {*} [thisArg] The `this` binding of `predicate`.
6282 * @returns {Array} Returns the new filtered array.
6285 * _.filter([4, 5, 6], function(n) {
6286 * return n % 2 == 0;
6291 * { 'user': 'barney', 'age': 36, 'active': true },
6292 * { 'user': 'fred', 'age': 40, 'active': false }
6295 * // using the `_.matches` callback shorthand
6296 * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
6299 * // using the `_.matchesProperty` callback shorthand
6300 * _.pluck(_.filter(users, 'active', false), 'user');
6303 * // using the `_.property` callback shorthand
6304 * _.pluck(_.filter(users, 'active'), 'user');
6307 function filter(collection, predicate, thisArg) {
6308 var func = isArray(collection) ? arrayFilter : baseFilter;
6309 predicate = getCallback(predicate, thisArg, 3);
6310 return func(collection, predicate);
6314 * Iterates over elements of `collection`, returning the first element
6315 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6316 * invoked with three arguments: (value, index|key, collection).
6318 * If a property name is provided for `predicate` the created `_.property`
6319 * style callback returns the property value of the given element.
6321 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6322 * style callback returns `true` for elements that have a matching property
6323 * value, else `false`.
6325 * If an object is provided for `predicate` the created `_.matches` style
6326 * callback returns `true` for elements that have the properties of the given
6327 * object, else `false`.
6332 * @category Collection
6333 * @param {Array|Object|string} collection The collection to search.
6334 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6336 * @param {*} [thisArg] The `this` binding of `predicate`.
6337 * @returns {*} Returns the matched element, else `undefined`.
6341 * { 'user': 'barney', 'age': 36, 'active': true },
6342 * { 'user': 'fred', 'age': 40, 'active': false },
6343 * { 'user': 'pebbles', 'age': 1, 'active': true }
6346 * _.result(_.find(users, function(chr) {
6347 * return chr.age < 40;
6351 * // using the `_.matches` callback shorthand
6352 * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
6355 * // using the `_.matchesProperty` callback shorthand
6356 * _.result(_.find(users, 'active', false), 'user');
6359 * // using the `_.property` callback shorthand
6360 * _.result(_.find(users, 'active'), 'user');
6363 var find = createFind(baseEach);
6366 * This method is like `_.find` except that it iterates over elements of
6367 * `collection` from right to left.
6371 * @category Collection
6372 * @param {Array|Object|string} collection The collection to search.
6373 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6375 * @param {*} [thisArg] The `this` binding of `predicate`.
6376 * @returns {*} Returns the matched element, else `undefined`.
6379 * _.findLast([1, 2, 3, 4], function(n) {
6380 * return n % 2 == 1;
6384 var findLast = createFind(baseEachRight, true);
6387 * Performs a deep comparison between each element in `collection` and the
6388 * source object, returning the first element that has equivalent property
6391 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
6392 * numbers, `Object` objects, regexes, and strings. Objects are compared by
6393 * their own, not inherited, enumerable properties. For comparing a single
6394 * own or inherited property value see `_.matchesProperty`.
6398 * @category Collection
6399 * @param {Array|Object|string} collection The collection to search.
6400 * @param {Object} source The object of property values to match.
6401 * @returns {*} Returns the matched element, else `undefined`.
6405 * { 'user': 'barney', 'age': 36, 'active': true },
6406 * { 'user': 'fred', 'age': 40, 'active': false }
6409 * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
6412 * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
6415 function findWhere(collection, source) {
6416 return find(collection, baseMatches(source));
6420 * Iterates over elements of `collection` invoking `iteratee` for each element.
6421 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6422 * (value, index|key, collection). Iteratee functions may exit iteration early
6423 * by explicitly returning `false`.
6425 * **Note:** As with other "Collections" methods, objects with a "length" property
6426 * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
6427 * may be used for object iteration.
6432 * @category Collection
6433 * @param {Array|Object|string} collection The collection to iterate over.
6434 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6435 * @param {*} [thisArg] The `this` binding of `iteratee`.
6436 * @returns {Array|Object|string} Returns `collection`.
6439 * _([1, 2]).forEach(function(n) {
6442 * // => logs each value from left to right and returns the array
6444 * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
6445 * console.log(n, key);
6447 * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
6449 var forEach = createForEach(arrayEach, baseEach);
6452 * This method is like `_.forEach` except that it iterates over elements of
6453 * `collection` from right to left.
6458 * @category Collection
6459 * @param {Array|Object|string} collection The collection to iterate over.
6460 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6461 * @param {*} [thisArg] The `this` binding of `iteratee`.
6462 * @returns {Array|Object|string} Returns `collection`.
6465 * _([1, 2]).forEachRight(function(n) {
6468 * // => logs each value from right to left and returns the array
6470 var forEachRight = createForEach(arrayEachRight, baseEachRight);
6473 * Creates an object composed of keys generated from the results of running
6474 * each element of `collection` through `iteratee`. The corresponding value
6475 * of each key is an array of the elements responsible for generating the key.
6476 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6477 * (value, index|key, collection).
6479 * If a property name is provided for `iteratee` the created `_.property`
6480 * style callback returns the property value of the given element.
6482 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6483 * style callback returns `true` for elements that have a matching property
6484 * value, else `false`.
6486 * If an object is provided for `iteratee` the created `_.matches` style
6487 * callback returns `true` for elements that have the properties of the given
6488 * object, else `false`.
6492 * @category Collection
6493 * @param {Array|Object|string} collection The collection to iterate over.
6494 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6496 * @param {*} [thisArg] The `this` binding of `iteratee`.
6497 * @returns {Object} Returns the composed aggregate object.
6500 * _.groupBy([4.2, 6.1, 6.4], function(n) {
6501 * return Math.floor(n);
6503 * // => { '4': [4.2], '6': [6.1, 6.4] }
6505 * _.groupBy([4.2, 6.1, 6.4], function(n) {
6506 * return this.floor(n);
6508 * // => { '4': [4.2], '6': [6.1, 6.4] }
6510 * // using the `_.property` callback shorthand
6511 * _.groupBy(['one', 'two', 'three'], 'length');
6512 * // => { '3': ['one', 'two'], '5': ['three'] }
6514 var groupBy = createAggregator(function(result, value, key) {
6515 if (hasOwnProperty.call(result, key)) {
6516 result[key].push(value);
6518 result[key] = [value];
6523 * Checks if `target` is in `collection` using
6524 * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
6525 * for equality comparisons. If `fromIndex` is negative, it's used as the offset
6526 * from the end of `collection`.
6530 * @alias contains, include
6531 * @category Collection
6532 * @param {Array|Object|string} collection The collection to search.
6533 * @param {*} target The value to search for.
6534 * @param {number} [fromIndex=0] The index to search from.
6535 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
6536 * @returns {boolean} Returns `true` if a matching element is found, else `false`.
6539 * _.includes([1, 2, 3], 1);
6542 * _.includes([1, 2, 3], 1, 2);
6545 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
6548 * _.includes('pebbles', 'eb');
6551 function includes(collection, target, fromIndex, guard) {
6552 var length = collection ? getLength(collection) : 0;
6553 if (!isLength(length)) {
6554 collection = values(collection);
6555 length = collection.length;
6557 if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
6560 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
6562 return (typeof collection == 'string' || !isArray(collection) && isString(collection))
6563 ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
6564 : (!!length && getIndexOf(collection, target, fromIndex) > -1);
6568 * Creates an object composed of keys generated from the results of running
6569 * each element of `collection` through `iteratee`. The corresponding value
6570 * of each key is the last element responsible for generating the key. The
6571 * iteratee function is bound to `thisArg` and invoked with three arguments:
6572 * (value, index|key, collection).
6574 * If a property name is provided for `iteratee` the created `_.property`
6575 * style callback returns the property value of the given element.
6577 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6578 * style callback returns `true` for elements that have a matching property
6579 * value, else `false`.
6581 * If an object is provided for `iteratee` the created `_.matches` style
6582 * callback returns `true` for elements that have the properties of the given
6583 * object, else `false`.
6587 * @category Collection
6588 * @param {Array|Object|string} collection The collection to iterate over.
6589 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6591 * @param {*} [thisArg] The `this` binding of `iteratee`.
6592 * @returns {Object} Returns the composed aggregate object.
6596 * { 'dir': 'left', 'code': 97 },
6597 * { 'dir': 'right', 'code': 100 }
6600 * _.indexBy(keyData, 'dir');
6601 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
6603 * _.indexBy(keyData, function(object) {
6604 * return String.fromCharCode(object.code);
6606 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6608 * _.indexBy(keyData, function(object) {
6609 * return this.fromCharCode(object.code);
6611 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6613 var indexBy = createAggregator(function(result, value, key) {
6614 result[key] = value;
6618 * Invokes the method at `path` of each element in `collection`, returning
6619 * an array of the results of each invoked method. Any additional arguments
6620 * are provided to each invoked method. If `methodName` is a function it's
6621 * invoked for, and `this` bound to, each element in `collection`.
6625 * @category Collection
6626 * @param {Array|Object|string} collection The collection to iterate over.
6627 * @param {Array|Function|string} path The path of the method to invoke or
6628 * the function invoked per iteration.
6629 * @param {...*} [args] The arguments to invoke the method with.
6630 * @returns {Array} Returns the array of results.
6633 * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
6634 * // => [[1, 5, 7], [1, 2, 3]]
6636 * _.invoke([123, 456], String.prototype.split, '');
6637 * // => [['1', '2', '3'], ['4', '5', '6']]
6639 var invoke = restParam(function(collection, path, args) {
6641 isFunc = typeof path == 'function',
6642 isProp = isKey(path),
6643 result = isArrayLike(collection) ? Array(collection.length) : [];
6645 baseEach(collection, function(value) {
6646 var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
6647 result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
6653 * Creates an array of values by running each element in `collection` through
6654 * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
6655 * arguments: (value, index|key, collection).
6657 * If a property name is provided for `iteratee` the created `_.property`
6658 * style callback returns the property value of the given element.
6660 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6661 * style callback returns `true` for elements that have a matching property
6662 * value, else `false`.
6664 * If an object is provided for `iteratee` the created `_.matches` style
6665 * callback returns `true` for elements that have the properties of the given
6666 * object, else `false`.
6668 * Many lodash methods are guarded to work as iteratees for methods like
6669 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
6671 * The guarded methods are:
6672 * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
6673 * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
6674 * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
6675 * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
6676 * `sum`, `uniq`, and `words`
6681 * @category Collection
6682 * @param {Array|Object|string} collection The collection to iterate over.
6683 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6685 * @param {*} [thisArg] The `this` binding of `iteratee`.
6686 * @returns {Array} Returns the new mapped array.
6689 * function timesThree(n) {
6693 * _.map([1, 2], timesThree);
6696 * _.map({ 'a': 1, 'b': 2 }, timesThree);
6697 * // => [3, 6] (iteration order is not guaranteed)
6700 * { 'user': 'barney' },
6701 * { 'user': 'fred' }
6704 * // using the `_.property` callback shorthand
6705 * _.map(users, 'user');
6706 * // => ['barney', 'fred']
6708 function map(collection, iteratee, thisArg) {
6709 var func = isArray(collection) ? arrayMap : baseMap;
6710 iteratee = getCallback(iteratee, thisArg, 3);
6711 return func(collection, iteratee);
6715 * Creates an array of elements split into two groups, the first of which
6716 * contains elements `predicate` returns truthy for, while the second of which
6717 * contains elements `predicate` returns falsey for. The predicate is bound
6718 * to `thisArg` and invoked with three arguments: (value, index|key, collection).
6720 * If a property name is provided for `predicate` the created `_.property`
6721 * style callback returns the property value of the given element.
6723 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6724 * style callback returns `true` for elements that have a matching property
6725 * value, else `false`.
6727 * If an object is provided for `predicate` the created `_.matches` style
6728 * callback returns `true` for elements that have the properties of the given
6729 * object, else `false`.
6733 * @category Collection
6734 * @param {Array|Object|string} collection The collection to iterate over.
6735 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6737 * @param {*} [thisArg] The `this` binding of `predicate`.
6738 * @returns {Array} Returns the array of grouped elements.
6741 * _.partition([1, 2, 3], function(n) {
6744 * // => [[1, 3], [2]]
6746 * _.partition([1.2, 2.3, 3.4], function(n) {
6747 * return this.floor(n) % 2;
6749 * // => [[1.2, 3.4], [2.3]]
6752 * { 'user': 'barney', 'age': 36, 'active': false },
6753 * { 'user': 'fred', 'age': 40, 'active': true },
6754 * { 'user': 'pebbles', 'age': 1, 'active': false }
6757 * var mapper = function(array) {
6758 * return _.pluck(array, 'user');
6761 * // using the `_.matches` callback shorthand
6762 * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
6763 * // => [['pebbles'], ['barney', 'fred']]
6765 * // using the `_.matchesProperty` callback shorthand
6766 * _.map(_.partition(users, 'active', false), mapper);
6767 * // => [['barney', 'pebbles'], ['fred']]
6769 * // using the `_.property` callback shorthand
6770 * _.map(_.partition(users, 'active'), mapper);
6771 * // => [['fred'], ['barney', 'pebbles']]
6773 var partition = createAggregator(function(result, value, key) {
6774 result[key ? 0 : 1].push(value);
6775 }, function() { return [[], []]; });
6778 * Gets the property value of `path` from all elements in `collection`.
6782 * @category Collection
6783 * @param {Array|Object|string} collection The collection to iterate over.
6784 * @param {Array|string} path The path of the property to pluck.
6785 * @returns {Array} Returns the property values.
6789 * { 'user': 'barney', 'age': 36 },
6790 * { 'user': 'fred', 'age': 40 }
6793 * _.pluck(users, 'user');
6794 * // => ['barney', 'fred']
6796 * var userIndex = _.indexBy(users, 'user');
6797 * _.pluck(userIndex, 'age');
6798 * // => [36, 40] (iteration order is not guaranteed)
6800 function pluck(collection, path) {
6801 return map(collection, property(path));
6805 * Reduces `collection` to a value which is the accumulated result of running
6806 * each element in `collection` through `iteratee`, where each successive
6807 * invocation is supplied the return value of the previous. If `accumulator`
6808 * is not provided the first element of `collection` is used as the initial
6809 * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
6810 * (accumulator, value, index|key, collection).
6812 * Many lodash methods are guarded to work as iteratees for methods like
6813 * `_.reduce`, `_.reduceRight`, and `_.transform`.
6815 * The guarded methods are:
6816 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
6821 * @alias foldl, inject
6822 * @category Collection
6823 * @param {Array|Object|string} collection The collection to iterate over.
6824 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6825 * @param {*} [accumulator] The initial value.
6826 * @param {*} [thisArg] The `this` binding of `iteratee`.
6827 * @returns {*} Returns the accumulated value.
6830 * _.reduce([1, 2], function(total, n) {
6835 * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
6836 * result[key] = n * 3;
6839 * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
6841 var reduce = createReduce(arrayReduce, baseEach);
6844 * This method is like `_.reduce` except that it iterates over elements of
6845 * `collection` from right to left.
6850 * @category Collection
6851 * @param {Array|Object|string} collection The collection to iterate over.
6852 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6853 * @param {*} [accumulator] The initial value.
6854 * @param {*} [thisArg] The `this` binding of `iteratee`.
6855 * @returns {*} Returns the accumulated value.
6858 * var array = [[0, 1], [2, 3], [4, 5]];
6860 * _.reduceRight(array, function(flattened, other) {
6861 * return flattened.concat(other);
6863 * // => [4, 5, 2, 3, 0, 1]
6865 var reduceRight = createReduce(arrayReduceRight, baseEachRight);
6868 * The opposite of `_.filter`; this method returns the elements of `collection`
6869 * that `predicate` does **not** return truthy for.
6873 * @category Collection
6874 * @param {Array|Object|string} collection The collection to iterate over.
6875 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6877 * @param {*} [thisArg] The `this` binding of `predicate`.
6878 * @returns {Array} Returns the new filtered array.
6881 * _.reject([1, 2, 3, 4], function(n) {
6882 * return n % 2 == 0;
6887 * { 'user': 'barney', 'age': 36, 'active': false },
6888 * { 'user': 'fred', 'age': 40, 'active': true }
6891 * // using the `_.matches` callback shorthand
6892 * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
6895 * // using the `_.matchesProperty` callback shorthand
6896 * _.pluck(_.reject(users, 'active', false), 'user');
6899 * // using the `_.property` callback shorthand
6900 * _.pluck(_.reject(users, 'active'), 'user');
6903 function reject(collection, predicate, thisArg) {
6904 var func = isArray(collection) ? arrayFilter : baseFilter;
6905 predicate = getCallback(predicate, thisArg, 3);
6906 return func(collection, function(value, index, collection) {
6907 return !predicate(value, index, collection);
6912 * Gets a random element or `n` random elements from a collection.
6916 * @category Collection
6917 * @param {Array|Object|string} collection The collection to sample.
6918 * @param {number} [n] The number of elements to sample.
6919 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
6920 * @returns {*} Returns the random sample(s).
6923 * _.sample([1, 2, 3, 4]);
6926 * _.sample([1, 2, 3, 4], 2);
6929 function sample(collection, n, guard) {
6930 if (guard ? isIterateeCall(collection, n, guard) : n == null) {
6931 collection = toIterable(collection);
6932 var length = collection.length;
6933 return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
6936 result = toArray(collection),
6937 length = result.length,
6938 lastIndex = length - 1;
6940 n = nativeMin(n < 0 ? 0 : (+n || 0), length);
6941 while (++index < n) {
6942 var rand = baseRandom(index, lastIndex),
6943 value = result[rand];
6945 result[rand] = result[index];
6946 result[index] = value;
6953 * Creates an array of shuffled values, using a version of the
6954 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
6958 * @category Collection
6959 * @param {Array|Object|string} collection The collection to shuffle.
6960 * @returns {Array} Returns the new shuffled array.
6963 * _.shuffle([1, 2, 3, 4]);
6964 * // => [4, 1, 3, 2]
6966 function shuffle(collection) {
6967 return sample(collection, POSITIVE_INFINITY);
6971 * Gets the size of `collection` by returning its length for array-like
6972 * values or the number of own enumerable properties for objects.
6976 * @category Collection
6977 * @param {Array|Object|string} collection The collection to inspect.
6978 * @returns {number} Returns the size of `collection`.
6981 * _.size([1, 2, 3]);
6984 * _.size({ 'a': 1, 'b': 2 });
6987 * _.size('pebbles');
6990 function size(collection) {
6991 var length = collection ? getLength(collection) : 0;
6992 return isLength(length) ? length : keys(collection).length;
6996 * Checks if `predicate` returns truthy for **any** element of `collection`.
6997 * The function returns as soon as it finds a passing value and does not iterate
6998 * over the entire collection. The predicate is bound to `thisArg` and invoked
6999 * with three arguments: (value, index|key, collection).
7001 * If a property name is provided for `predicate` the created `_.property`
7002 * style callback returns the property value of the given element.
7004 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7005 * style callback returns `true` for elements that have a matching property
7006 * value, else `false`.
7008 * If an object is provided for `predicate` the created `_.matches` style
7009 * callback returns `true` for elements that have the properties of the given
7010 * object, else `false`.
7015 * @category Collection
7016 * @param {Array|Object|string} collection The collection to iterate over.
7017 * @param {Function|Object|string} [predicate=_.identity] The function invoked
7019 * @param {*} [thisArg] The `this` binding of `predicate`.
7020 * @returns {boolean} Returns `true` if any element passes the predicate check,
7024 * _.some([null, 0, 'yes', false], Boolean);
7028 * { 'user': 'barney', 'active': true },
7029 * { 'user': 'fred', 'active': false }
7032 * // using the `_.matches` callback shorthand
7033 * _.some(users, { 'user': 'barney', 'active': false });
7036 * // using the `_.matchesProperty` callback shorthand
7037 * _.some(users, 'active', false);
7040 * // using the `_.property` callback shorthand
7041 * _.some(users, 'active');
7044 function some(collection, predicate, thisArg) {
7045 var func = isArray(collection) ? arraySome : baseSome;
7046 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
7047 predicate = undefined;
7049 if (typeof predicate != 'function' || thisArg !== undefined) {
7050 predicate = getCallback(predicate, thisArg, 3);
7052 return func(collection, predicate);
7056 * Creates an array of elements, sorted in ascending order by the results of
7057 * running each element in a collection through `iteratee`. This method performs
7058 * a stable sort, that is, it preserves the original sort order of equal elements.
7059 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
7060 * (value, index|key, collection).
7062 * If a property name is provided for `iteratee` the created `_.property`
7063 * style callback returns the property value of the given element.
7065 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7066 * style callback returns `true` for elements that have a matching property
7067 * value, else `false`.
7069 * If an object is provided for `iteratee` the created `_.matches` style
7070 * callback returns `true` for elements that have the properties of the given
7071 * object, else `false`.
7075 * @category Collection
7076 * @param {Array|Object|string} collection The collection to iterate over.
7077 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
7079 * @param {*} [thisArg] The `this` binding of `iteratee`.
7080 * @returns {Array} Returns the new sorted array.
7083 * _.sortBy([1, 2, 3], function(n) {
7084 * return Math.sin(n);
7088 * _.sortBy([1, 2, 3], function(n) {
7089 * return this.sin(n);
7094 * { 'user': 'fred' },
7095 * { 'user': 'pebbles' },
7096 * { 'user': 'barney' }
7099 * // using the `_.property` callback shorthand
7100 * _.pluck(_.sortBy(users, 'user'), 'user');
7101 * // => ['barney', 'fred', 'pebbles']
7103 function sortBy(collection, iteratee, thisArg) {
7104 if (collection == null) {
7107 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
7108 iteratee = undefined;
7111 iteratee = getCallback(iteratee, thisArg, 3);
7113 var result = baseMap(collection, function(value, key, collection) {
7114 return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
7116 return baseSortBy(result, compareAscending);
7120 * This method is like `_.sortBy` except that it can sort by multiple iteratees
7121 * or property names.
7123 * If a property name is provided for an iteratee the created `_.property`
7124 * style callback returns the property value of the given element.
7126 * If an object is provided for an iteratee the created `_.matches` style
7127 * callback returns `true` for elements that have the properties of the given
7128 * object, else `false`.
7132 * @category Collection
7133 * @param {Array|Object|string} collection The collection to iterate over.
7134 * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
7135 * The iteratees to sort by, specified as individual values or arrays of values.
7136 * @returns {Array} Returns the new sorted array.
7140 * { 'user': 'fred', 'age': 48 },
7141 * { 'user': 'barney', 'age': 36 },
7142 * { 'user': 'fred', 'age': 42 },
7143 * { 'user': 'barney', 'age': 34 }
7146 * _.map(_.sortByAll(users, ['user', 'age']), _.values);
7147 * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
7149 * _.map(_.sortByAll(users, 'user', function(chr) {
7150 * return Math.floor(chr.age / 10);
7152 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7154 var sortByAll = restParam(function(collection, iteratees) {
7155 if (collection == null) {
7158 var guard = iteratees[2];
7159 if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
7160 iteratees.length = 1;
7162 return baseSortByOrder(collection, baseFlatten(iteratees), []);
7166 * This method is like `_.sortByAll` except that it allows specifying the
7167 * sort orders of the iteratees to sort by. If `orders` is unspecified, all
7168 * values are sorted in ascending order. Otherwise, a value is sorted in
7169 * ascending order if its corresponding order is "asc", and descending if "desc".
7171 * If a property name is provided for an iteratee the created `_.property`
7172 * style callback returns the property value of the given element.
7174 * If an object is provided for an iteratee the created `_.matches` style
7175 * callback returns `true` for elements that have the properties of the given
7176 * object, else `false`.
7180 * @category Collection
7181 * @param {Array|Object|string} collection The collection to iterate over.
7182 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
7183 * @param {boolean[]} [orders] The sort orders of `iteratees`.
7184 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
7185 * @returns {Array} Returns the new sorted array.
7189 * { 'user': 'fred', 'age': 48 },
7190 * { 'user': 'barney', 'age': 34 },
7191 * { 'user': 'fred', 'age': 42 },
7192 * { 'user': 'barney', 'age': 36 }
7195 * // sort by `user` in ascending order and by `age` in descending order
7196 * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
7197 * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
7199 function sortByOrder(collection, iteratees, orders, guard) {
7200 if (collection == null) {
7203 if (guard && isIterateeCall(iteratees, orders, guard)) {
7206 if (!isArray(iteratees)) {
7207 iteratees = iteratees == null ? [] : [iteratees];
7209 if (!isArray(orders)) {
7210 orders = orders == null ? [] : [orders];
7212 return baseSortByOrder(collection, iteratees, orders);
7216 * Performs a deep comparison between each element in `collection` and the
7217 * source object, returning an array of all elements that have equivalent
7220 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
7221 * numbers, `Object` objects, regexes, and strings. Objects are compared by
7222 * their own, not inherited, enumerable properties. For comparing a single
7223 * own or inherited property value see `_.matchesProperty`.
7227 * @category Collection
7228 * @param {Array|Object|string} collection The collection to search.
7229 * @param {Object} source The object of property values to match.
7230 * @returns {Array} Returns the new filtered array.
7234 * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
7235 * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
7238 * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
7241 * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
7244 function where(collection, source) {
7245 return filter(collection, baseMatches(source));
7248 /*------------------------------------------------------------------------*/
7251 * Gets the number of milliseconds that have elapsed since the Unix epoch
7252 * (1 January 1970 00:00:00 UTC).
7259 * _.defer(function(stamp) {
7260 * console.log(_.now() - stamp);
7262 * // => logs the number of milliseconds it took for the deferred function to be invoked
7264 var now = nativeNow || function() {
7265 return new Date().getTime();
7268 /*------------------------------------------------------------------------*/
7271 * The opposite of `_.before`; this method creates a function that invokes
7272 * `func` once it's called `n` or more times.
7276 * @category Function
7277 * @param {number} n The number of calls before `func` is invoked.
7278 * @param {Function} func The function to restrict.
7279 * @returns {Function} Returns the new restricted function.
7282 * var saves = ['profile', 'settings'];
7284 * var done = _.after(saves.length, function() {
7285 * console.log('done saving!');
7288 * _.forEach(saves, function(type) {
7289 * asyncSave({ 'type': type, 'complete': done });
7291 * // => logs 'done saving!' after the two async saves have completed
7293 function after(n, func) {
7294 if (typeof func != 'function') {
7295 if (typeof n == 'function') {
7300 throw new TypeError(FUNC_ERROR_TEXT);
7303 n = nativeIsFinite(n = +n) ? n : 0;
7306 return func.apply(this, arguments);
7312 * Creates a function that accepts up to `n` arguments ignoring any
7313 * additional arguments.
7317 * @category Function
7318 * @param {Function} func The function to cap arguments for.
7319 * @param {number} [n=func.length] The arity cap.
7320 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7321 * @returns {Function} Returns the new function.
7324 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
7327 function ary(func, n, guard) {
7328 if (guard && isIterateeCall(func, n, guard)) {
7331 n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
7332 return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
7336 * Creates a function that invokes `func`, with the `this` binding and arguments
7337 * of the created function, while it's called less than `n` times. Subsequent
7338 * calls to the created function return the result of the last `func` invocation.
7342 * @category Function
7343 * @param {number} n The number of calls at which `func` is no longer invoked.
7344 * @param {Function} func The function to restrict.
7345 * @returns {Function} Returns the new restricted function.
7348 * jQuery('#add').on('click', _.before(5, addContactToList));
7349 * // => allows adding up to 4 contacts to the list
7351 function before(n, func) {
7353 if (typeof func != 'function') {
7354 if (typeof n == 'function') {
7359 throw new TypeError(FUNC_ERROR_TEXT);
7364 result = func.apply(this, arguments);
7374 * Creates a function that invokes `func` with the `this` binding of `thisArg`
7375 * and prepends any additional `_.bind` arguments to those provided to the
7378 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
7379 * may be used as a placeholder for partially applied arguments.
7381 * **Note:** Unlike native `Function#bind` this method does not set the "length"
7382 * property of bound functions.
7386 * @category Function
7387 * @param {Function} func The function to bind.
7388 * @param {*} thisArg The `this` binding of `func`.
7389 * @param {...*} [partials] The arguments to be partially applied.
7390 * @returns {Function} Returns the new bound function.
7393 * var greet = function(greeting, punctuation) {
7394 * return greeting + ' ' + this.user + punctuation;
7397 * var object = { 'user': 'fred' };
7399 * var bound = _.bind(greet, object, 'hi');
7403 * // using placeholders
7404 * var bound = _.bind(greet, object, _, '!');
7408 var bind = restParam(function(func, thisArg, partials) {
7409 var bitmask = BIND_FLAG;
7410 if (partials.length) {
7411 var holders = replaceHolders(partials, bind.placeholder);
7412 bitmask |= PARTIAL_FLAG;
7414 return createWrapper(func, bitmask, thisArg, partials, holders);
7418 * Binds methods of an object to the object itself, overwriting the existing
7419 * method. Method names may be specified as individual arguments or as arrays
7420 * of method names. If no method names are provided all enumerable function
7421 * properties, own and inherited, of `object` are bound.
7423 * **Note:** This method does not set the "length" property of bound functions.
7427 * @category Function
7428 * @param {Object} object The object to bind and assign the bound methods to.
7429 * @param {...(string|string[])} [methodNames] The object method names to bind,
7430 * specified as individual method names or arrays of method names.
7431 * @returns {Object} Returns `object`.
7436 * 'onClick': function() {
7437 * console.log('clicked ' + this.label);
7442 * jQuery('#docs').on('click', view.onClick);
7443 * // => logs 'clicked docs' when the element is clicked
7445 var bindAll = restParam(function(object, methodNames) {
7446 methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
7449 length = methodNames.length;
7451 while (++index < length) {
7452 var key = methodNames[index];
7453 object[key] = createWrapper(object[key], BIND_FLAG, object);
7459 * Creates a function that invokes the method at `object[key]` and prepends
7460 * any additional `_.bindKey` arguments to those provided to the bound function.
7462 * This method differs from `_.bind` by allowing bound functions to reference
7463 * methods that may be redefined or don't yet exist.
7464 * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
7467 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
7468 * builds, may be used as a placeholder for partially applied arguments.
7472 * @category Function
7473 * @param {Object} object The object the method belongs to.
7474 * @param {string} key The key of the method.
7475 * @param {...*} [partials] The arguments to be partially applied.
7476 * @returns {Function} Returns the new bound function.
7481 * 'greet': function(greeting, punctuation) {
7482 * return greeting + ' ' + this.user + punctuation;
7486 * var bound = _.bindKey(object, 'greet', 'hi');
7490 * object.greet = function(greeting, punctuation) {
7491 * return greeting + 'ya ' + this.user + punctuation;
7495 * // => 'hiya fred!'
7497 * // using placeholders
7498 * var bound = _.bindKey(object, 'greet', _, '!');
7500 * // => 'hiya fred!'
7502 var bindKey = restParam(function(object, key, partials) {
7503 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
7504 if (partials.length) {
7505 var holders = replaceHolders(partials, bindKey.placeholder);
7506 bitmask |= PARTIAL_FLAG;
7508 return createWrapper(key, bitmask, object, partials, holders);
7512 * Creates a function that accepts one or more arguments of `func` that when
7513 * called either invokes `func` returning its result, if all `func` arguments
7514 * have been provided, or returns a function that accepts one or more of the
7515 * remaining `func` arguments, and so on. The arity of `func` may be specified
7516 * if `func.length` is not sufficient.
7518 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
7519 * may be used as a placeholder for provided arguments.
7521 * **Note:** This method does not set the "length" property of curried functions.
7525 * @category Function
7526 * @param {Function} func The function to curry.
7527 * @param {number} [arity=func.length] The arity of `func`.
7528 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7529 * @returns {Function} Returns the new curried function.
7532 * var abc = function(a, b, c) {
7536 * var curried = _.curry(abc);
7547 * // using placeholders
7548 * curried(1)(_, 3)(2);
7551 var curry = createCurry(CURRY_FLAG);
7554 * This method is like `_.curry` except that arguments are applied to `func`
7555 * in the manner of `_.partialRight` instead of `_.partial`.
7557 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
7558 * builds, may be used as a placeholder for provided arguments.
7560 * **Note:** This method does not set the "length" property of curried functions.
7564 * @category Function
7565 * @param {Function} func The function to curry.
7566 * @param {number} [arity=func.length] The arity of `func`.
7567 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7568 * @returns {Function} Returns the new curried function.
7571 * var abc = function(a, b, c) {
7575 * var curried = _.curryRight(abc);
7586 * // using placeholders
7587 * curried(3)(1, _)(2);
7590 var curryRight = createCurry(CURRY_RIGHT_FLAG);
7593 * Creates a debounced function that delays invoking `func` until after `wait`
7594 * milliseconds have elapsed since the last time the debounced function was
7595 * invoked. The debounced function comes with a `cancel` method to cancel
7596 * delayed invocations. Provide an options object to indicate that `func`
7597 * should be invoked on the leading and/or trailing edge of the `wait` timeout.
7598 * Subsequent calls to the debounced function return the result of the last
7599 * `func` invocation.
7601 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
7602 * on the trailing edge of the timeout only if the the debounced function is
7603 * invoked more than once during the `wait` timeout.
7605 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
7606 * for details over the differences between `_.debounce` and `_.throttle`.
7610 * @category Function
7611 * @param {Function} func The function to debounce.
7612 * @param {number} [wait=0] The number of milliseconds to delay.
7613 * @param {Object} [options] The options object.
7614 * @param {boolean} [options.leading=false] Specify invoking on the leading
7615 * edge of the timeout.
7616 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
7617 * delayed before it's invoked.
7618 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
7619 * edge of the timeout.
7620 * @returns {Function} Returns the new debounced function.
7623 * // avoid costly calculations while the window size is in flux
7624 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
7626 * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
7627 * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
7632 * // ensure `batchLog` is invoked once after 1 second of debounced calls
7633 * var source = new EventSource('/stream');
7634 * jQuery(source).on('message', _.debounce(batchLog, 250, {
7638 * // cancel a debounced call
7639 * var todoChanges = _.debounce(batchLog, 1000);
7640 * Object.observe(models.todo, todoChanges);
7642 * Object.observe(models, function(changes) {
7643 * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
7644 * todoChanges.cancel();
7648 * // ...at some point `models.todo` is changed
7649 * models.todo.completed = true;
7651 * // ...before 1 second has passed `models.todo` is deleted
7652 * // which cancels the debounced `todoChanges` call
7653 * delete models.todo;
7655 function debounce(func, wait, options) {
7667 if (typeof func != 'function') {
7668 throw new TypeError(FUNC_ERROR_TEXT);
7670 wait = wait < 0 ? 0 : (+wait || 0);
7671 if (options === true) {
7674 } else if (isObject(options)) {
7675 leading = !!options.leading;
7676 maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
7677 trailing = 'trailing' in options ? !!options.trailing : trailing;
7682 clearTimeout(timeoutId);
7685 clearTimeout(maxTimeoutId);
7688 maxTimeoutId = timeoutId = trailingCall = undefined;
7691 function complete(isCalled, id) {
7695 maxTimeoutId = timeoutId = trailingCall = undefined;
7698 result = func.apply(thisArg, args);
7699 if (!timeoutId && !maxTimeoutId) {
7700 args = thisArg = undefined;
7705 function delayed() {
7706 var remaining = wait - (now() - stamp);
7707 if (remaining <= 0 || remaining > wait) {
7708 complete(trailingCall, maxTimeoutId);
7710 timeoutId = setTimeout(delayed, remaining);
7714 function maxDelayed() {
7715 complete(trailing, timeoutId);
7718 function debounced() {
7722 trailingCall = trailing && (timeoutId || !leading);
7724 if (maxWait === false) {
7725 var leadingCall = leading && !timeoutId;
7727 if (!maxTimeoutId && !leading) {
7730 var remaining = maxWait - (stamp - lastCalled),
7731 isCalled = remaining <= 0 || remaining > maxWait;
7735 maxTimeoutId = clearTimeout(maxTimeoutId);
7738 result = func.apply(thisArg, args);
7740 else if (!maxTimeoutId) {
7741 maxTimeoutId = setTimeout(maxDelayed, remaining);
7744 if (isCalled && timeoutId) {
7745 timeoutId = clearTimeout(timeoutId);
7747 else if (!timeoutId && wait !== maxWait) {
7748 timeoutId = setTimeout(delayed, wait);
7752 result = func.apply(thisArg, args);
7754 if (isCalled && !timeoutId && !maxTimeoutId) {
7755 args = thisArg = undefined;
7759 debounced.cancel = cancel;
7764 * Defers invoking the `func` until the current call stack has cleared. Any
7765 * additional arguments are provided to `func` when it's invoked.
7769 * @category Function
7770 * @param {Function} func The function to defer.
7771 * @param {...*} [args] The arguments to invoke the function with.
7772 * @returns {number} Returns the timer id.
7775 * _.defer(function(text) {
7776 * console.log(text);
7778 * // logs 'deferred' after one or more milliseconds
7780 var defer = restParam(function(func, args) {
7781 return baseDelay(func, 1, args);
7785 * Invokes `func` after `wait` milliseconds. Any additional arguments are
7786 * provided to `func` when it's invoked.
7790 * @category Function
7791 * @param {Function} func The function to delay.
7792 * @param {number} wait The number of milliseconds to delay invocation.
7793 * @param {...*} [args] The arguments to invoke the function with.
7794 * @returns {number} Returns the timer id.
7797 * _.delay(function(text) {
7798 * console.log(text);
7799 * }, 1000, 'later');
7800 * // => logs 'later' after one second
7802 var delay = restParam(function(func, wait, args) {
7803 return baseDelay(func, wait, args);
7807 * Creates a function that returns the result of invoking the provided
7808 * functions with the `this` binding of the created function, where each
7809 * successive invocation is supplied the return value of the previous.
7813 * @category Function
7814 * @param {...Function} [funcs] Functions to invoke.
7815 * @returns {Function} Returns the new function.
7818 * function square(n) {
7822 * var addSquare = _.flow(_.add, square);
7826 var flow = createFlow();
7829 * This method is like `_.flow` except that it creates a function that
7830 * invokes the provided functions from right to left.
7834 * @alias backflow, compose
7835 * @category Function
7836 * @param {...Function} [funcs] Functions to invoke.
7837 * @returns {Function} Returns the new function.
7840 * function square(n) {
7844 * var addSquare = _.flowRight(square, _.add);
7848 var flowRight = createFlow(true);
7851 * Creates a function that memoizes the result of `func`. If `resolver` is
7852 * provided it determines the cache key for storing the result based on the
7853 * arguments provided to the memoized function. By default, the first argument
7854 * provided to the memoized function is coerced to a string and used as the
7855 * cache key. The `func` is invoked with the `this` binding of the memoized
7858 * **Note:** The cache is exposed as the `cache` property on the memoized
7859 * function. Its creation may be customized by replacing the `_.memoize.Cache`
7860 * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
7861 * method interface of `get`, `has`, and `set`.
7865 * @category Function
7866 * @param {Function} func The function to have its output memoized.
7867 * @param {Function} [resolver] The function to resolve the cache key.
7868 * @returns {Function} Returns the new memoizing function.
7871 * var upperCase = _.memoize(function(string) {
7872 * return string.toUpperCase();
7875 * upperCase('fred');
7878 * // modifying the result cache
7879 * upperCase.cache.set('fred', 'BARNEY');
7880 * upperCase('fred');
7883 * // replacing `_.memoize.Cache`
7884 * var object = { 'user': 'fred' };
7885 * var other = { 'user': 'barney' };
7886 * var identity = _.memoize(_.identity);
7889 * // => { 'user': 'fred' }
7891 * // => { 'user': 'fred' }
7893 * _.memoize.Cache = WeakMap;
7894 * var identity = _.memoize(_.identity);
7897 * // => { 'user': 'fred' }
7899 * // => { 'user': 'barney' }
7901 function memoize(func, resolver) {
7902 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
7903 throw new TypeError(FUNC_ERROR_TEXT);
7905 var memoized = function() {
7906 var args = arguments,
7907 key = resolver ? resolver.apply(this, args) : args[0],
7908 cache = memoized.cache;
7910 if (cache.has(key)) {
7911 return cache.get(key);
7913 var result = func.apply(this, args);
7914 memoized.cache = cache.set(key, result);
7917 memoized.cache = new memoize.Cache;
7922 * Creates a function that runs each argument through a corresponding
7923 * transform function.
7927 * @category Function
7928 * @param {Function} func The function to wrap.
7929 * @param {...(Function|Function[])} [transforms] The functions to transform
7930 * arguments, specified as individual functions or arrays of functions.
7931 * @returns {Function} Returns the new function.
7934 * function doubled(n) {
7938 * function square(n) {
7942 * var modded = _.modArgs(function(x, y) {
7944 * }, square, doubled);
7952 var modArgs = restParam(function(func, transforms) {
7953 transforms = baseFlatten(transforms);
7954 if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
7955 throw new TypeError(FUNC_ERROR_TEXT);
7957 var length = transforms.length;
7958 return restParam(function(args) {
7959 var index = nativeMin(args.length, length);
7961 args[index] = transforms[index](args[index]);
7963 return func.apply(this, args);
7968 * Creates a function that negates the result of the predicate `func`. The
7969 * `func` predicate is invoked with the `this` binding and arguments of the
7974 * @category Function
7975 * @param {Function} predicate The predicate to negate.
7976 * @returns {Function} Returns the new function.
7979 * function isEven(n) {
7980 * return n % 2 == 0;
7983 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
7986 function negate(predicate) {
7987 if (typeof predicate != 'function') {
7988 throw new TypeError(FUNC_ERROR_TEXT);
7991 return !predicate.apply(this, arguments);
7996 * Creates a function that is restricted to invoking `func` once. Repeat calls
7997 * to the function return the value of the first call. The `func` is invoked
7998 * with the `this` binding and arguments of the created function.
8002 * @category Function
8003 * @param {Function} func The function to restrict.
8004 * @returns {Function} Returns the new restricted function.
8007 * var initialize = _.once(createApplication);
8010 * // `initialize` invokes `createApplication` once
8012 function once(func) {
8013 return before(2, func);
8017 * Creates a function that invokes `func` with `partial` arguments prepended
8018 * to those provided to the new function. This method is like `_.bind` except
8019 * it does **not** alter the `this` binding.
8021 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
8022 * builds, may be used as a placeholder for partially applied arguments.
8024 * **Note:** This method does not set the "length" property of partially
8025 * applied functions.
8029 * @category Function
8030 * @param {Function} func The function to partially apply arguments to.
8031 * @param {...*} [partials] The arguments to be partially applied.
8032 * @returns {Function} Returns the new partially applied function.
8035 * var greet = function(greeting, name) {
8036 * return greeting + ' ' + name;
8039 * var sayHelloTo = _.partial(greet, 'hello');
8040 * sayHelloTo('fred');
8041 * // => 'hello fred'
8043 * // using placeholders
8044 * var greetFred = _.partial(greet, _, 'fred');
8048 var partial = createPartial(PARTIAL_FLAG);
8051 * This method is like `_.partial` except that partially applied arguments
8052 * are appended to those provided to the new function.
8054 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
8055 * builds, may be used as a placeholder for partially applied arguments.
8057 * **Note:** This method does not set the "length" property of partially
8058 * applied functions.
8062 * @category Function
8063 * @param {Function} func The function to partially apply arguments to.
8064 * @param {...*} [partials] The arguments to be partially applied.
8065 * @returns {Function} Returns the new partially applied function.
8068 * var greet = function(greeting, name) {
8069 * return greeting + ' ' + name;
8072 * var greetFred = _.partialRight(greet, 'fred');
8076 * // using placeholders
8077 * var sayHelloTo = _.partialRight(greet, 'hello', _);
8078 * sayHelloTo('fred');
8079 * // => 'hello fred'
8081 var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
8084 * Creates a function that invokes `func` with arguments arranged according
8085 * to the specified indexes where the argument value at the first index is
8086 * provided as the first argument, the argument value at the second index is
8087 * provided as the second argument, and so on.
8091 * @category Function
8092 * @param {Function} func The function to rearrange arguments for.
8093 * @param {...(number|number[])} indexes The arranged argument indexes,
8094 * specified as individual indexes or arrays of indexes.
8095 * @returns {Function} Returns the new function.
8098 * var rearged = _.rearg(function(a, b, c) {
8102 * rearged('b', 'c', 'a')
8103 * // => ['a', 'b', 'c']
8105 * var map = _.rearg(_.map, [1, 0]);
8111 var rearg = restParam(function(func, indexes) {
8112 return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
8116 * Creates a function that invokes `func` with the `this` binding of the
8117 * created function and arguments from `start` and beyond provided as an array.
8119 * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
8123 * @category Function
8124 * @param {Function} func The function to apply a rest parameter to.
8125 * @param {number} [start=func.length-1] The start position of the rest parameter.
8126 * @returns {Function} Returns the new function.
8129 * var say = _.restParam(function(what, names) {
8130 * return what + ' ' + _.initial(names).join(', ') +
8131 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
8134 * say('hello', 'fred', 'barney', 'pebbles');
8135 * // => 'hello fred, barney, & pebbles'
8137 function restParam(func, start) {
8138 if (typeof func != 'function') {
8139 throw new TypeError(FUNC_ERROR_TEXT);
8141 start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
8143 var args = arguments,
8145 length = nativeMax(args.length - start, 0),
8146 rest = Array(length);
8148 while (++index < length) {
8149 rest[index] = args[start + index];
8152 case 0: return func.call(this, rest);
8153 case 1: return func.call(this, args[0], rest);
8154 case 2: return func.call(this, args[0], args[1], rest);
8156 var otherArgs = Array(start + 1);
8158 while (++index < start) {
8159 otherArgs[index] = args[index];
8161 otherArgs[start] = rest;
8162 return func.apply(this, otherArgs);
8167 * Creates a function that invokes `func` with the `this` binding of the created
8168 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
8170 * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
8174 * @category Function
8175 * @param {Function} func The function to spread arguments over.
8176 * @returns {Function} Returns the new function.
8179 * var say = _.spread(function(who, what) {
8180 * return who + ' says ' + what;
8183 * say(['fred', 'hello']);
8184 * // => 'fred says hello'
8187 * var numbers = Promise.all([
8188 * Promise.resolve(40),
8189 * Promise.resolve(36)
8192 * numbers.then(_.spread(function(x, y) {
8195 * // => a Promise of 76
8197 function spread(func) {
8198 if (typeof func != 'function') {
8199 throw new TypeError(FUNC_ERROR_TEXT);
8201 return function(array) {
8202 return func.apply(this, array);
8207 * Creates a throttled function that only invokes `func` at most once per
8208 * every `wait` milliseconds. The throttled function comes with a `cancel`
8209 * method to cancel delayed invocations. Provide an options object to indicate
8210 * that `func` should be invoked on the leading and/or trailing edge of the
8211 * `wait` timeout. Subsequent calls to the throttled function return the
8212 * result of the last `func` call.
8214 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8215 * on the trailing edge of the timeout only if the the throttled function is
8216 * invoked more than once during the `wait` timeout.
8218 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8219 * for details over the differences between `_.throttle` and `_.debounce`.
8223 * @category Function
8224 * @param {Function} func The function to throttle.
8225 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
8226 * @param {Object} [options] The options object.
8227 * @param {boolean} [options.leading=true] Specify invoking on the leading
8228 * edge of the timeout.
8229 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8230 * edge of the timeout.
8231 * @returns {Function} Returns the new throttled function.
8234 * // avoid excessively updating the position while scrolling
8235 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
8237 * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
8238 * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
8242 * // cancel a trailing throttled call
8243 * jQuery(window).on('popstate', throttled.cancel);
8245 function throttle(func, wait, options) {
8249 if (typeof func != 'function') {
8250 throw new TypeError(FUNC_ERROR_TEXT);
8252 if (options === false) {
8254 } else if (isObject(options)) {
8255 leading = 'leading' in options ? !!options.leading : leading;
8256 trailing = 'trailing' in options ? !!options.trailing : trailing;
8258 return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
8262 * Creates a function that provides `value` to the wrapper function as its
8263 * first argument. Any additional arguments provided to the function are
8264 * appended to those provided to the wrapper function. The wrapper is invoked
8265 * with the `this` binding of the created function.
8269 * @category Function
8270 * @param {*} value The value to wrap.
8271 * @param {Function} wrapper The wrapper function.
8272 * @returns {Function} Returns the new function.
8275 * var p = _.wrap(_.escape, function(func, text) {
8276 * return '<p>' + func(text) + '</p>';
8279 * p('fred, barney, & pebbles');
8280 * // => '<p>fred, barney, & pebbles</p>'
8282 function wrap(value, wrapper) {
8283 wrapper = wrapper == null ? identity : wrapper;
8284 return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
8287 /*------------------------------------------------------------------------*/
8290 * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
8291 * otherwise they are assigned by reference. If `customizer` is provided it's
8292 * invoked to produce the cloned values. If `customizer` returns `undefined`
8293 * cloning is handled by the method instead. The `customizer` is bound to
8294 * `thisArg` and invoked with up to three argument; (value [, index|key, object]).
8296 * **Note:** This method is loosely based on the
8297 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8298 * The enumerable properties of `arguments` objects and objects created by
8299 * constructors other than `Object` are cloned to plain `Object` objects. An
8300 * empty object is returned for uncloneable values such as functions, DOM nodes,
8301 * Maps, Sets, and WeakMaps.
8306 * @param {*} value The value to clone.
8307 * @param {boolean} [isDeep] Specify a deep clone.
8308 * @param {Function} [customizer] The function to customize cloning values.
8309 * @param {*} [thisArg] The `this` binding of `customizer`.
8310 * @returns {*} Returns the cloned value.
8314 * { 'user': 'barney' },
8315 * { 'user': 'fred' }
8318 * var shallow = _.clone(users);
8319 * shallow[0] === users[0];
8322 * var deep = _.clone(users, true);
8323 * deep[0] === users[0];
8326 * // using a customizer callback
8327 * var el = _.clone(document.body, function(value) {
8328 * if (_.isElement(value)) {
8329 * return value.cloneNode(false);
8333 * el === document.body
8337 * el.childNodes.length;
8340 function clone(value, isDeep, customizer, thisArg) {
8341 if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
8344 else if (typeof isDeep == 'function') {
8345 thisArg = customizer;
8346 customizer = isDeep;
8349 return typeof customizer == 'function'
8350 ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 3))
8351 : baseClone(value, isDeep);
8355 * Creates a deep clone of `value`. If `customizer` is provided it's invoked
8356 * to produce the cloned values. If `customizer` returns `undefined` cloning
8357 * is handled by the method instead. The `customizer` is bound to `thisArg`
8358 * and invoked with up to three argument; (value [, index|key, object]).
8360 * **Note:** This method is loosely based on the
8361 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8362 * The enumerable properties of `arguments` objects and objects created by
8363 * constructors other than `Object` are cloned to plain `Object` objects. An
8364 * empty object is returned for uncloneable values such as functions, DOM nodes,
8365 * Maps, Sets, and WeakMaps.
8370 * @param {*} value The value to deep clone.
8371 * @param {Function} [customizer] The function to customize cloning values.
8372 * @param {*} [thisArg] The `this` binding of `customizer`.
8373 * @returns {*} Returns the deep cloned value.
8377 * { 'user': 'barney' },
8378 * { 'user': 'fred' }
8381 * var deep = _.cloneDeep(users);
8382 * deep[0] === users[0];
8385 * // using a customizer callback
8386 * var el = _.cloneDeep(document.body, function(value) {
8387 * if (_.isElement(value)) {
8388 * return value.cloneNode(true);
8392 * el === document.body
8396 * el.childNodes.length;
8399 function cloneDeep(value, customizer, thisArg) {
8400 return typeof customizer == 'function'
8401 ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
8402 : baseClone(value, true);
8406 * Checks if `value` is greater than `other`.
8411 * @param {*} value The value to compare.
8412 * @param {*} other The other value to compare.
8413 * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
8425 function gt(value, other) {
8426 return value > other;
8430 * Checks if `value` is greater than or equal to `other`.
8435 * @param {*} value The value to compare.
8436 * @param {*} other The other value to compare.
8437 * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
8449 function gte(value, other) {
8450 return value >= other;
8454 * Checks if `value` is classified as an `arguments` object.
8459 * @param {*} value The value to check.
8460 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8463 * _.isArguments(function() { return arguments; }());
8466 * _.isArguments([1, 2, 3]);
8469 function isArguments(value) {
8470 return isObjectLike(value) && isArrayLike(value) &&
8471 hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
8475 * Checks if `value` is classified as an `Array` object.
8480 * @param {*} value The value to check.
8481 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8484 * _.isArray([1, 2, 3]);
8487 * _.isArray(function() { return arguments; }());
8490 var isArray = nativeIsArray || function(value) {
8491 return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
8495 * Checks if `value` is classified as a boolean primitive or object.
8500 * @param {*} value The value to check.
8501 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8504 * _.isBoolean(false);
8507 * _.isBoolean(null);
8510 function isBoolean(value) {
8511 return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
8515 * Checks if `value` is classified as a `Date` object.
8520 * @param {*} value The value to check.
8521 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8524 * _.isDate(new Date);
8527 * _.isDate('Mon April 23 2012');
8530 function isDate(value) {
8531 return isObjectLike(value) && objToString.call(value) == dateTag;
8535 * Checks if `value` is a DOM element.
8540 * @param {*} value The value to check.
8541 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
8544 * _.isElement(document.body);
8547 * _.isElement('<body>');
8550 function isElement(value) {
8551 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
8555 * Checks if `value` is empty. A value is considered empty unless it's an
8556 * `arguments` object, array, string, or jQuery-like collection with a length
8557 * greater than `0` or an object with own enumerable properties.
8562 * @param {Array|Object|string} value The value to inspect.
8563 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
8575 * _.isEmpty([1, 2, 3]);
8578 * _.isEmpty({ 'a': 1 });
8581 function isEmpty(value) {
8582 if (value == null) {
8585 if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
8586 (isObjectLike(value) && isFunction(value.splice)))) {
8587 return !value.length;
8589 return !keys(value).length;
8593 * Performs a deep comparison between two values to determine if they are
8594 * equivalent. If `customizer` is provided it's invoked to compare values.
8595 * If `customizer` returns `undefined` comparisons are handled by the method
8596 * instead. The `customizer` is bound to `thisArg` and invoked with up to
8597 * three arguments: (value, other [, index|key]).
8599 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
8600 * numbers, `Object` objects, regexes, and strings. Objects are compared by
8601 * their own, not inherited, enumerable properties. Functions and DOM nodes
8602 * are **not** supported. Provide a customizer function to extend support
8603 * for comparing other values.
8609 * @param {*} value The value to compare.
8610 * @param {*} other The other value to compare.
8611 * @param {Function} [customizer] The function to customize value comparisons.
8612 * @param {*} [thisArg] The `this` binding of `customizer`.
8613 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
8616 * var object = { 'user': 'fred' };
8617 * var other = { 'user': 'fred' };
8622 * _.isEqual(object, other);
8625 * // using a customizer callback
8626 * var array = ['hello', 'goodbye'];
8627 * var other = ['hi', 'goodbye'];
8629 * _.isEqual(array, other, function(value, other) {
8630 * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
8636 function isEqual(value, other, customizer, thisArg) {
8637 customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
8638 var result = customizer ? customizer(value, other) : undefined;
8639 return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
8643 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
8644 * `SyntaxError`, `TypeError`, or `URIError` object.
8649 * @param {*} value The value to check.
8650 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
8653 * _.isError(new Error);
8659 function isError(value) {
8660 return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
8664 * Checks if `value` is a finite primitive number.
8666 * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
8671 * @param {*} value The value to check.
8672 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
8684 * _.isFinite(Object(10));
8687 * _.isFinite(Infinity);
8690 function isFinite(value) {
8691 return typeof value == 'number' && nativeIsFinite(value);
8695 * Checks if `value` is classified as a `Function` object.
8700 * @param {*} value The value to check.
8701 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8707 * _.isFunction(/abc/);
8710 function isFunction(value) {
8711 // The use of `Object#toString` avoids issues with the `typeof` operator
8712 // in older versions of Chrome and Safari which return 'function' for regexes
8713 // and Safari 8 which returns 'object' for typed array constructors.
8714 return isObject(value) && objToString.call(value) == funcTag;
8718 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
8719 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
8724 * @param {*} value The value to check.
8725 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
8731 * _.isObject([1, 2, 3]);
8737 function isObject(value) {
8738 // Avoid a V8 JIT bug in Chrome 19-20.
8739 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
8740 var type = typeof value;
8741 return !!value && (type == 'object' || type == 'function');
8745 * Performs a deep comparison between `object` and `source` to determine if
8746 * `object` contains equivalent property values. If `customizer` is provided
8747 * it's invoked to compare values. If `customizer` returns `undefined`
8748 * comparisons are handled by the method instead. The `customizer` is bound
8749 * to `thisArg` and invoked with three arguments: (value, other, index|key).
8751 * **Note:** This method supports comparing properties of arrays, booleans,
8752 * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
8753 * and DOM nodes are **not** supported. Provide a customizer function to extend
8754 * support for comparing other values.
8759 * @param {Object} object The object to inspect.
8760 * @param {Object} source The object of property values to match.
8761 * @param {Function} [customizer] The function to customize value comparisons.
8762 * @param {*} [thisArg] The `this` binding of `customizer`.
8763 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
8766 * var object = { 'user': 'fred', 'age': 40 };
8768 * _.isMatch(object, { 'age': 40 });
8771 * _.isMatch(object, { 'age': 36 });
8774 * // using a customizer callback
8775 * var object = { 'greeting': 'hello' };
8776 * var source = { 'greeting': 'hi' };
8778 * _.isMatch(object, source, function(value, other) {
8779 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
8783 function isMatch(object, source, customizer, thisArg) {
8784 customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
8785 return baseIsMatch(object, getMatchData(source), customizer);
8789 * Checks if `value` is `NaN`.
8791 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
8792 * which returns `true` for `undefined` and other non-numeric values.
8797 * @param {*} value The value to check.
8798 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
8804 * _.isNaN(new Number(NaN));
8810 * _.isNaN(undefined);
8813 function isNaN(value) {
8814 // An `NaN` primitive is the only value that is not equal to itself.
8815 // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
8816 return isNumber(value) && value != +value;
8820 * Checks if `value` is a native function.
8825 * @param {*} value The value to check.
8826 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
8829 * _.isNative(Array.prototype.push);
8835 function isNative(value) {
8836 if (value == null) {
8839 if (isFunction(value)) {
8840 return reIsNative.test(fnToString.call(value));
8842 return isObjectLike(value) && reIsHostCtor.test(value);
8846 * Checks if `value` is `null`.
8851 * @param {*} value The value to check.
8852 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
8861 function isNull(value) {
8862 return value === null;
8866 * Checks if `value` is classified as a `Number` primitive or object.
8868 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
8869 * as numbers, use the `_.isFinite` method.
8874 * @param {*} value The value to check.
8875 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8884 * _.isNumber('8.4');
8887 function isNumber(value) {
8888 return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
8892 * Checks if `value` is a plain object, that is, an object created by the
8893 * `Object` constructor or one with a `[[Prototype]]` of `null`.
8895 * **Note:** This method assumes objects created by the `Object` constructor
8896 * have no inherited enumerable properties.
8901 * @param {*} value The value to check.
8902 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
8909 * _.isPlainObject(new Foo);
8912 * _.isPlainObject([1, 2, 3]);
8915 * _.isPlainObject({ 'x': 0, 'y': 0 });
8918 * _.isPlainObject(Object.create(null));
8921 function isPlainObject(value) {
8924 // Exit early for non `Object` objects.
8925 if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
8926 (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
8929 // IE < 9 iterates inherited properties before own properties. If the first
8930 // iterated property is an object's own property then there are no inherited
8931 // enumerable properties.
8933 // In most environments an object's own properties are iterated before
8934 // its inherited properties. If the last iterated property is an object's
8935 // own property then there are no inherited enumerable properties.
8936 baseForIn(value, function(subValue, key) {
8939 return result === undefined || hasOwnProperty.call(value, result);
8943 * Checks if `value` is classified as a `RegExp` object.
8948 * @param {*} value The value to check.
8949 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8952 * _.isRegExp(/abc/);
8955 * _.isRegExp('/abc/');
8958 function isRegExp(value) {
8959 return isObject(value) && objToString.call(value) == regexpTag;
8963 * Checks if `value` is classified as a `String` primitive or object.
8968 * @param {*} value The value to check.
8969 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8972 * _.isString('abc');
8978 function isString(value) {
8979 return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
8983 * Checks if `value` is classified as a typed array.
8988 * @param {*} value The value to check.
8989 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8992 * _.isTypedArray(new Uint8Array);
8995 * _.isTypedArray([]);
8998 function isTypedArray(value) {
8999 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
9003 * Checks if `value` is `undefined`.
9008 * @param {*} value The value to check.
9009 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
9012 * _.isUndefined(void 0);
9015 * _.isUndefined(null);
9018 function isUndefined(value) {
9019 return value === undefined;
9023 * Checks if `value` is less than `other`.
9028 * @param {*} value The value to compare.
9029 * @param {*} other The other value to compare.
9030 * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
9042 function lt(value, other) {
9043 return value < other;
9047 * Checks if `value` is less than or equal to `other`.
9052 * @param {*} value The value to compare.
9053 * @param {*} other The other value to compare.
9054 * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
9066 function lte(value, other) {
9067 return value <= other;
9071 * Converts `value` to an array.
9076 * @param {*} value The value to convert.
9077 * @returns {Array} Returns the converted array.
9081 * return _.toArray(arguments).slice(1);
9085 function toArray(value) {
9086 var length = value ? getLength(value) : 0;
9087 if (!isLength(length)) {
9088 return values(value);
9093 return arrayCopy(value);
9097 * Converts `value` to a plain object flattening inherited enumerable
9098 * properties of `value` to own properties of the plain object.
9103 * @param {*} value The value to convert.
9104 * @returns {Object} Returns the converted plain object.
9111 * Foo.prototype.c = 3;
9113 * _.assign({ 'a': 1 }, new Foo);
9114 * // => { 'a': 1, 'b': 2 }
9116 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
9117 * // => { 'a': 1, 'b': 2, 'c': 3 }
9119 function toPlainObject(value) {
9120 return baseCopy(value, keysIn(value));
9123 /*------------------------------------------------------------------------*/
9126 * Recursively merges own enumerable properties of the source object(s), that
9127 * don't resolve to `undefined` into the destination object. Subsequent sources
9128 * overwrite property assignments of previous sources. If `customizer` is
9129 * provided it's invoked to produce the merged values of the destination and
9130 * source properties. If `customizer` returns `undefined` merging is handled
9131 * by the method instead. The `customizer` is bound to `thisArg` and invoked
9132 * with five arguments: (objectValue, sourceValue, key, object, source).
9137 * @param {Object} object The destination object.
9138 * @param {...Object} [sources] The source objects.
9139 * @param {Function} [customizer] The function to customize assigned values.
9140 * @param {*} [thisArg] The `this` binding of `customizer`.
9141 * @returns {Object} Returns `object`.
9145 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
9149 * 'data': [{ 'age': 36 }, { 'age': 40 }]
9152 * _.merge(users, ages);
9153 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
9155 * // using a customizer callback
9157 * 'fruits': ['apple'],
9158 * 'vegetables': ['beet']
9162 * 'fruits': ['banana'],
9163 * 'vegetables': ['carrot']
9166 * _.merge(object, other, function(a, b) {
9167 * if (_.isArray(a)) {
9168 * return a.concat(b);
9171 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
9173 var merge = createAssigner(baseMerge);
9176 * Assigns own enumerable properties of source object(s) to the destination
9177 * object. Subsequent sources overwrite property assignments of previous sources.
9178 * If `customizer` is provided it's invoked to produce the assigned values.
9179 * The `customizer` is bound to `thisArg` and invoked with five arguments:
9180 * (objectValue, sourceValue, key, object, source).
9182 * **Note:** This method mutates `object` and is based on
9183 * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
9189 * @param {Object} object The destination object.
9190 * @param {...Object} [sources] The source objects.
9191 * @param {Function} [customizer] The function to customize assigned values.
9192 * @param {*} [thisArg] The `this` binding of `customizer`.
9193 * @returns {Object} Returns `object`.
9196 * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
9197 * // => { 'user': 'fred', 'age': 40 }
9199 * // using a customizer callback
9200 * var defaults = _.partialRight(_.assign, function(value, other) {
9201 * return _.isUndefined(value) ? other : value;
9204 * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9205 * // => { 'user': 'barney', 'age': 36 }
9207 var assign = createAssigner(function(object, source, customizer) {
9209 ? assignWith(object, source, customizer)
9210 : baseAssign(object, source);
9214 * Creates an object that inherits from the given `prototype` object. If a
9215 * `properties` object is provided its own enumerable properties are assigned
9216 * to the created object.
9221 * @param {Object} prototype The object to inherit from.
9222 * @param {Object} [properties] The properties to assign to the object.
9223 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9224 * @returns {Object} Returns the new object.
9227 * function Shape() {
9232 * function Circle() {
9236 * Circle.prototype = _.create(Shape.prototype, {
9237 * 'constructor': Circle
9240 * var circle = new Circle;
9241 * circle instanceof Circle;
9244 * circle instanceof Shape;
9247 function create(prototype, properties, guard) {
9248 var result = baseCreate(prototype);
9249 if (guard && isIterateeCall(prototype, properties, guard)) {
9250 properties = undefined;
9252 return properties ? baseAssign(result, properties) : result;
9256 * Assigns own enumerable properties of source object(s) to the destination
9257 * object for all destination properties that resolve to `undefined`. Once a
9258 * property is set, additional values of the same property are ignored.
9260 * **Note:** This method mutates `object`.
9265 * @param {Object} object The destination object.
9266 * @param {...Object} [sources] The source objects.
9267 * @returns {Object} Returns `object`.
9270 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9271 * // => { 'user': 'barney', 'age': 36 }
9273 var defaults = createDefaults(assign, assignDefaults);
9276 * This method is like `_.defaults` except that it recursively assigns
9277 * default properties.
9279 * **Note:** This method mutates `object`.
9284 * @param {Object} object The destination object.
9285 * @param {...Object} [sources] The source objects.
9286 * @returns {Object} Returns `object`.
9289 * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
9290 * // => { 'user': { 'name': 'barney', 'age': 36 } }
9293 var defaultsDeep = createDefaults(merge, mergeDefaults);
9296 * This method is like `_.find` except that it returns the key of the first
9297 * element `predicate` returns truthy for instead of the element itself.
9299 * If a property name is provided for `predicate` the created `_.property`
9300 * style callback returns the property value of the given element.
9302 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9303 * style callback returns `true` for elements that have a matching property
9304 * value, else `false`.
9306 * If an object is provided for `predicate` the created `_.matches` style
9307 * callback returns `true` for elements that have the properties of the given
9308 * object, else `false`.
9313 * @param {Object} object The object to search.
9314 * @param {Function|Object|string} [predicate=_.identity] The function invoked
9316 * @param {*} [thisArg] The `this` binding of `predicate`.
9317 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9321 * 'barney': { 'age': 36, 'active': true },
9322 * 'fred': { 'age': 40, 'active': false },
9323 * 'pebbles': { 'age': 1, 'active': true }
9326 * _.findKey(users, function(chr) {
9327 * return chr.age < 40;
9329 * // => 'barney' (iteration order is not guaranteed)
9331 * // using the `_.matches` callback shorthand
9332 * _.findKey(users, { 'age': 1, 'active': true });
9335 * // using the `_.matchesProperty` callback shorthand
9336 * _.findKey(users, 'active', false);
9339 * // using the `_.property` callback shorthand
9340 * _.findKey(users, 'active');
9343 var findKey = createFindKey(baseForOwn);
9346 * This method is like `_.findKey` except that it iterates over elements of
9347 * a collection in the opposite order.
9349 * If a property name is provided for `predicate` the created `_.property`
9350 * style callback returns the property value of the given element.
9352 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9353 * style callback returns `true` for elements that have a matching property
9354 * value, else `false`.
9356 * If an object is provided for `predicate` the created `_.matches` style
9357 * callback returns `true` for elements that have the properties of the given
9358 * object, else `false`.
9363 * @param {Object} object The object to search.
9364 * @param {Function|Object|string} [predicate=_.identity] The function invoked
9366 * @param {*} [thisArg] The `this` binding of `predicate`.
9367 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9371 * 'barney': { 'age': 36, 'active': true },
9372 * 'fred': { 'age': 40, 'active': false },
9373 * 'pebbles': { 'age': 1, 'active': true }
9376 * _.findLastKey(users, function(chr) {
9377 * return chr.age < 40;
9379 * // => returns `pebbles` assuming `_.findKey` returns `barney`
9381 * // using the `_.matches` callback shorthand
9382 * _.findLastKey(users, { 'age': 36, 'active': true });
9385 * // using the `_.matchesProperty` callback shorthand
9386 * _.findLastKey(users, 'active', false);
9389 * // using the `_.property` callback shorthand
9390 * _.findLastKey(users, 'active');
9393 var findLastKey = createFindKey(baseForOwnRight);
9396 * Iterates over own and inherited enumerable properties of an object invoking
9397 * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
9398 * with three arguments: (value, key, object). Iteratee functions may exit
9399 * iteration early by explicitly returning `false`.
9404 * @param {Object} object The object to iterate over.
9405 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9406 * @param {*} [thisArg] The `this` binding of `iteratee`.
9407 * @returns {Object} Returns `object`.
9415 * Foo.prototype.c = 3;
9417 * _.forIn(new Foo, function(value, key) {
9420 * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
9422 var forIn = createForIn(baseFor);
9425 * This method is like `_.forIn` except that it iterates over properties of
9426 * `object` in the opposite order.
9431 * @param {Object} object The object to iterate over.
9432 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9433 * @param {*} [thisArg] The `this` binding of `iteratee`.
9434 * @returns {Object} Returns `object`.
9442 * Foo.prototype.c = 3;
9444 * _.forInRight(new Foo, function(value, key) {
9447 * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
9449 var forInRight = createForIn(baseForRight);
9452 * Iterates over own enumerable properties of an object invoking `iteratee`
9453 * for each property. The `iteratee` is bound to `thisArg` and invoked with
9454 * three arguments: (value, key, object). Iteratee functions may exit iteration
9455 * early by explicitly returning `false`.
9460 * @param {Object} object The object to iterate over.
9461 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9462 * @param {*} [thisArg] The `this` binding of `iteratee`.
9463 * @returns {Object} Returns `object`.
9471 * Foo.prototype.c = 3;
9473 * _.forOwn(new Foo, function(value, key) {
9476 * // => logs 'a' and 'b' (iteration order is not guaranteed)
9478 var forOwn = createForOwn(baseForOwn);
9481 * This method is like `_.forOwn` except that it iterates over properties of
9482 * `object` in the opposite order.
9487 * @param {Object} object The object to iterate over.
9488 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9489 * @param {*} [thisArg] The `this` binding of `iteratee`.
9490 * @returns {Object} Returns `object`.
9498 * Foo.prototype.c = 3;
9500 * _.forOwnRight(new Foo, function(value, key) {
9503 * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
9505 var forOwnRight = createForOwn(baseForOwnRight);
9508 * Creates an array of function property names from all enumerable properties,
9509 * own and inherited, of `object`.
9515 * @param {Object} object The object to inspect.
9516 * @returns {Array} Returns the new array of property names.
9520 * // => ['after', 'ary', 'assign', ...]
9522 function functions(object) {
9523 return baseFunctions(object, keysIn(object));
9527 * Gets the property value at `path` of `object`. If the resolved value is
9528 * `undefined` the `defaultValue` is used in its place.
9533 * @param {Object} object The object to query.
9534 * @param {Array|string} path The path of the property to get.
9535 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9536 * @returns {*} Returns the resolved value.
9539 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9541 * _.get(object, 'a[0].b.c');
9544 * _.get(object, ['a', '0', 'b', 'c']);
9547 * _.get(object, 'a.b.c', 'default');
9550 function get(object, path, defaultValue) {
9551 var result = object == null ? undefined : baseGet(object, toPath(path), (path + ''));
9552 return result === undefined ? defaultValue : result;
9556 * Checks if `path` is a direct property.
9561 * @param {Object} object The object to query.
9562 * @param {Array|string} path The path to check.
9563 * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
9566 * var object = { 'a': { 'b': { 'c': 3 } } };
9568 * _.has(object, 'a');
9571 * _.has(object, 'a.b.c');
9574 * _.has(object, ['a', 'b', 'c']);
9577 function has(object, path) {
9578 if (object == null) {
9581 var result = hasOwnProperty.call(object, path);
9582 if (!result && !isKey(path)) {
9583 path = toPath(path);
9584 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9585 if (object == null) {
9589 result = hasOwnProperty.call(object, path);
9591 return result || (isLength(object.length) && isIndex(path, object.length) &&
9592 (isArray(object) || isArguments(object)));
9596 * Creates an object composed of the inverted keys and values of `object`.
9597 * If `object` contains duplicate values, subsequent values overwrite property
9598 * assignments of previous values unless `multiValue` is `true`.
9603 * @param {Object} object The object to invert.
9604 * @param {boolean} [multiValue] Allow multiple values per key.
9605 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9606 * @returns {Object} Returns the new inverted object.
9609 * var object = { 'a': 1, 'b': 2, 'c': 1 };
9612 * // => { '1': 'c', '2': 'b' }
9614 * // with `multiValue`
9615 * _.invert(object, true);
9616 * // => { '1': ['a', 'c'], '2': ['b'] }
9618 function invert(object, multiValue, guard) {
9619 if (guard && isIterateeCall(object, multiValue, guard)) {
9620 multiValue = undefined;
9623 props = keys(object),
9624 length = props.length,
9627 while (++index < length) {
9628 var key = props[index],
9629 value = object[key];
9632 if (hasOwnProperty.call(result, value)) {
9633 result[value].push(key);
9635 result[value] = [key];
9639 result[value] = key;
9646 * Creates an array of the own enumerable property names of `object`.
9648 * **Note:** Non-object values are coerced to objects. See the
9649 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
9655 * @param {Object} object The object to query.
9656 * @returns {Array} Returns the array of property names.
9664 * Foo.prototype.c = 3;
9667 * // => ['a', 'b'] (iteration order is not guaranteed)
9672 var keys = !nativeKeys ? shimKeys : function(object) {
9673 var Ctor = object == null ? undefined : object.constructor;
9674 if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
9675 (typeof object != 'function' && isArrayLike(object))) {
9676 return shimKeys(object);
9678 return isObject(object) ? nativeKeys(object) : [];
9682 * Creates an array of the own and inherited enumerable property names of `object`.
9684 * **Note:** Non-object values are coerced to objects.
9689 * @param {Object} object The object to query.
9690 * @returns {Array} Returns the array of property names.
9698 * Foo.prototype.c = 3;
9700 * _.keysIn(new Foo);
9701 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
9703 function keysIn(object) {
9704 if (object == null) {
9707 if (!isObject(object)) {
9708 object = Object(object);
9710 var length = object.length;
9711 length = (length && isLength(length) &&
9712 (isArray(object) || isArguments(object)) && length) || 0;
9714 var Ctor = object.constructor,
9716 isProto = typeof Ctor == 'function' && Ctor.prototype === object,
9717 result = Array(length),
9718 skipIndexes = length > 0;
9720 while (++index < length) {
9721 result[index] = (index + '');
9723 for (var key in object) {
9724 if (!(skipIndexes && isIndex(key, length)) &&
9725 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
9733 * The opposite of `_.mapValues`; this method creates an object with the
9734 * same values as `object` and keys generated by running each own enumerable
9735 * property of `object` through `iteratee`.
9740 * @param {Object} object The object to iterate over.
9741 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9743 * @param {*} [thisArg] The `this` binding of `iteratee`.
9744 * @returns {Object} Returns the new mapped object.
9747 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
9748 * return key + value;
9750 * // => { 'a1': 1, 'b2': 2 }
9752 var mapKeys = createObjectMapper(true);
9755 * Creates an object with the same keys as `object` and values generated by
9756 * running each own enumerable property of `object` through `iteratee`. The
9757 * iteratee function is bound to `thisArg` and invoked with three arguments:
9758 * (value, key, object).
9760 * If a property name is provided for `iteratee` the created `_.property`
9761 * style callback returns the property value of the given element.
9763 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9764 * style callback returns `true` for elements that have a matching property
9765 * value, else `false`.
9767 * If an object is provided for `iteratee` the created `_.matches` style
9768 * callback returns `true` for elements that have the properties of the given
9769 * object, else `false`.
9774 * @param {Object} object The object to iterate over.
9775 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9777 * @param {*} [thisArg] The `this` binding of `iteratee`.
9778 * @returns {Object} Returns the new mapped object.
9781 * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
9784 * // => { 'a': 3, 'b': 6 }
9787 * 'fred': { 'user': 'fred', 'age': 40 },
9788 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
9791 * // using the `_.property` callback shorthand
9792 * _.mapValues(users, 'age');
9793 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
9795 var mapValues = createObjectMapper();
9798 * The opposite of `_.pick`; this method creates an object composed of the
9799 * own and inherited enumerable properties of `object` that are not omitted.
9804 * @param {Object} object The source object.
9805 * @param {Function|...(string|string[])} [predicate] The function invoked per
9806 * iteration or property names to omit, specified as individual property
9807 * names or arrays of property names.
9808 * @param {*} [thisArg] The `this` binding of `predicate`.
9809 * @returns {Object} Returns the new object.
9812 * var object = { 'user': 'fred', 'age': 40 };
9814 * _.omit(object, 'age');
9815 * // => { 'user': 'fred' }
9817 * _.omit(object, _.isNumber);
9818 * // => { 'user': 'fred' }
9820 var omit = restParam(function(object, props) {
9821 if (object == null) {
9824 if (typeof props[0] != 'function') {
9825 var props = arrayMap(baseFlatten(props), String);
9826 return pickByArray(object, baseDifference(keysIn(object), props));
9828 var predicate = bindCallback(props[0], props[1], 3);
9829 return pickByCallback(object, function(value, key, object) {
9830 return !predicate(value, key, object);
9835 * Creates a two dimensional array of the key-value pairs for `object`,
9836 * e.g. `[[key1, value1], [key2, value2]]`.
9841 * @param {Object} object The object to query.
9842 * @returns {Array} Returns the new array of key-value pairs.
9845 * _.pairs({ 'barney': 36, 'fred': 40 });
9846 * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
9848 function pairs(object) {
9849 object = toObject(object);
9852 props = keys(object),
9853 length = props.length,
9854 result = Array(length);
9856 while (++index < length) {
9857 var key = props[index];
9858 result[index] = [key, object[key]];
9864 * Creates an object composed of the picked `object` properties. Property
9865 * names may be specified as individual arguments or as arrays of property
9866 * names. If `predicate` is provided it's invoked for each property of `object`
9867 * picking the properties `predicate` returns truthy for. The predicate is
9868 * bound to `thisArg` and invoked with three arguments: (value, key, object).
9873 * @param {Object} object The source object.
9874 * @param {Function|...(string|string[])} [predicate] The function invoked per
9875 * iteration or property names to pick, specified as individual property
9876 * names or arrays of property names.
9877 * @param {*} [thisArg] The `this` binding of `predicate`.
9878 * @returns {Object} Returns the new object.
9881 * var object = { 'user': 'fred', 'age': 40 };
9883 * _.pick(object, 'user');
9884 * // => { 'user': 'fred' }
9886 * _.pick(object, _.isString);
9887 * // => { 'user': 'fred' }
9889 var pick = restParam(function(object, props) {
9890 if (object == null) {
9893 return typeof props[0] == 'function'
9894 ? pickByCallback(object, bindCallback(props[0], props[1], 3))
9895 : pickByArray(object, baseFlatten(props));
9899 * This method is like `_.get` except that if the resolved value is a function
9900 * it's invoked with the `this` binding of its parent object and its result
9906 * @param {Object} object The object to query.
9907 * @param {Array|string} path The path of the property to resolve.
9908 * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
9909 * @returns {*} Returns the resolved value.
9912 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
9914 * _.result(object, 'a[0].b.c1');
9917 * _.result(object, 'a[0].b.c2');
9920 * _.result(object, 'a.b.c', 'default');
9923 * _.result(object, 'a.b.c', _.constant('default'));
9926 function result(object, path, defaultValue) {
9927 var result = object == null ? undefined : object[path];
9928 if (result === undefined) {
9929 if (object != null && !isKey(path, object)) {
9930 path = toPath(path);
9931 object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
9932 result = object == null ? undefined : object[last(path)];
9934 result = result === undefined ? defaultValue : result;
9936 return isFunction(result) ? result.call(object) : result;
9940 * Sets the property value of `path` on `object`. If a portion of `path`
9941 * does not exist it's created.
9946 * @param {Object} object The object to augment.
9947 * @param {Array|string} path The path of the property to set.
9948 * @param {*} value The value to set.
9949 * @returns {Object} Returns `object`.
9952 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
9954 * _.set(object, 'a[0].b.c', 4);
9955 * console.log(object.a[0].b.c);
9958 * _.set(object, 'x[0].y.z', 5);
9959 * console.log(object.x[0].y.z);
9962 function set(object, path, value) {
9963 if (object == null) {
9966 var pathKey = (path + '');
9967 path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
9970 length = path.length,
9971 lastIndex = length - 1,
9974 while (nested != null && ++index < length) {
9975 var key = path[index];
9976 if (isObject(nested)) {
9977 if (index == lastIndex) {
9978 nested[key] = value;
9979 } else if (nested[key] == null) {
9980 nested[key] = isIndex(path[index + 1]) ? [] : {};
9983 nested = nested[key];
9989 * An alternative to `_.reduce`; this method transforms `object` to a new
9990 * `accumulator` object which is the result of running each of its own enumerable
9991 * properties through `iteratee`, with each invocation potentially mutating
9992 * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
9993 * with four arguments: (accumulator, value, key, object). Iteratee functions
9994 * may exit iteration early by explicitly returning `false`.
9999 * @param {Array|Object} object The object to iterate over.
10000 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10001 * @param {*} [accumulator] The custom accumulator value.
10002 * @param {*} [thisArg] The `this` binding of `iteratee`.
10003 * @returns {*} Returns the accumulated value.
10006 * _.transform([2, 3, 4], function(result, n) {
10007 * result.push(n *= n);
10008 * return n % 2 == 0;
10012 * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
10013 * result[key] = n * 3;
10015 * // => { 'a': 3, 'b': 6 }
10017 function transform(object, iteratee, accumulator, thisArg) {
10018 var isArr = isArray(object) || isTypedArray(object);
10019 iteratee = getCallback(iteratee, thisArg, 4);
10021 if (accumulator == null) {
10022 if (isArr || isObject(object)) {
10023 var Ctor = object.constructor;
10025 accumulator = isArray(object) ? new Ctor : [];
10027 accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
10033 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
10034 return iteratee(accumulator, value, index, object);
10036 return accumulator;
10040 * Creates an array of the own enumerable property values of `object`.
10042 * **Note:** Non-object values are coerced to objects.
10047 * @param {Object} object The object to query.
10048 * @returns {Array} Returns the array of property values.
10056 * Foo.prototype.c = 3;
10058 * _.values(new Foo);
10059 * // => [1, 2] (iteration order is not guaranteed)
10064 function values(object) {
10065 return baseValues(object, keys(object));
10069 * Creates an array of the own and inherited enumerable property values
10072 * **Note:** Non-object values are coerced to objects.
10077 * @param {Object} object The object to query.
10078 * @returns {Array} Returns the array of property values.
10086 * Foo.prototype.c = 3;
10088 * _.valuesIn(new Foo);
10089 * // => [1, 2, 3] (iteration order is not guaranteed)
10091 function valuesIn(object) {
10092 return baseValues(object, keysIn(object));
10095 /*------------------------------------------------------------------------*/
10098 * Checks if `n` is between `start` and up to but not including, `end`. If
10099 * `end` is not specified it's set to `start` with `start` then set to `0`.
10104 * @param {number} n The number to check.
10105 * @param {number} [start=0] The start of the range.
10106 * @param {number} end The end of the range.
10107 * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
10110 * _.inRange(3, 2, 4);
10122 * _.inRange(1.2, 2);
10125 * _.inRange(5.2, 4);
10128 function inRange(value, start, end) {
10129 start = +start || 0;
10130 if (end === undefined) {
10136 return value >= nativeMin(start, end) && value < nativeMax(start, end);
10140 * Produces a random number between `min` and `max` (inclusive). If only one
10141 * argument is provided a number between `0` and the given number is returned.
10142 * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
10143 * number is returned instead of an integer.
10148 * @param {number} [min=0] The minimum possible value.
10149 * @param {number} [max=1] The maximum possible value.
10150 * @param {boolean} [floating] Specify returning a floating-point number.
10151 * @returns {number} Returns the random number.
10155 * // => an integer between 0 and 5
10158 * // => also an integer between 0 and 5
10160 * _.random(5, true);
10161 * // => a floating-point number between 0 and 5
10163 * _.random(1.2, 5.2);
10164 * // => a floating-point number between 1.2 and 5.2
10166 function random(min, max, floating) {
10167 if (floating && isIterateeCall(min, max, floating)) {
10168 max = floating = undefined;
10170 var noMin = min == null,
10171 noMax = max == null;
10173 if (floating == null) {
10174 if (noMax && typeof min == 'boolean') {
10178 else if (typeof max == 'boolean') {
10183 if (noMin && noMax) {
10194 if (floating || min % 1 || max % 1) {
10195 var rand = nativeRandom();
10196 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
10198 return baseRandom(min, max);
10201 /*------------------------------------------------------------------------*/
10204 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
10209 * @param {string} [string=''] The string to convert.
10210 * @returns {string} Returns the camel cased string.
10213 * _.camelCase('Foo Bar');
10216 * _.camelCase('--foo-bar');
10219 * _.camelCase('__foo_bar__');
10222 var camelCase = createCompounder(function(result, word, index) {
10223 word = word.toLowerCase();
10224 return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
10228 * Capitalizes the first character of `string`.
10233 * @param {string} [string=''] The string to capitalize.
10234 * @returns {string} Returns the capitalized string.
10237 * _.capitalize('fred');
10240 function capitalize(string) {
10241 string = baseToString(string);
10242 return string && (string.charAt(0).toUpperCase() + string.slice(1));
10246 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
10247 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
10252 * @param {string} [string=''] The string to deburr.
10253 * @returns {string} Returns the deburred string.
10256 * _.deburr('déjà vu');
10259 function deburr(string) {
10260 string = baseToString(string);
10261 return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
10265 * Checks if `string` ends with the given target string.
10270 * @param {string} [string=''] The string to search.
10271 * @param {string} [target] The string to search for.
10272 * @param {number} [position=string.length] The position to search from.
10273 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
10276 * _.endsWith('abc', 'c');
10279 * _.endsWith('abc', 'b');
10282 * _.endsWith('abc', 'b', 2);
10285 function endsWith(string, target, position) {
10286 string = baseToString(string);
10287 target = (target + '');
10289 var length = string.length;
10290 position = position === undefined
10292 : nativeMin(position < 0 ? 0 : (+position || 0), length);
10294 position -= target.length;
10295 return position >= 0 && string.indexOf(target, position) == position;
10299 * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
10300 * their corresponding HTML entities.
10302 * **Note:** No other characters are escaped. To escape additional characters
10303 * use a third-party library like [_he_](https://mths.be/he).
10305 * Though the ">" character is escaped for symmetry, characters like
10306 * ">" and "/" don't need escaping in HTML and have no special meaning
10307 * unless they're part of a tag or unquoted attribute value.
10308 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
10309 * (under "semi-related fun fact") for more details.
10311 * Backticks are escaped because in Internet Explorer < 9, they can break out
10312 * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
10313 * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
10314 * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
10315 * for more details.
10317 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
10318 * to reduce XSS vectors.
10323 * @param {string} [string=''] The string to escape.
10324 * @returns {string} Returns the escaped string.
10327 * _.escape('fred, barney, & pebbles');
10328 * // => 'fred, barney, & pebbles'
10330 function escape(string) {
10331 // Reset `lastIndex` because in IE < 9 `String#replace` does not.
10332 string = baseToString(string);
10333 return (string && reHasUnescapedHtml.test(string))
10334 ? string.replace(reUnescapedHtml, escapeHtmlChar)
10339 * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
10340 * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
10345 * @param {string} [string=''] The string to escape.
10346 * @returns {string} Returns the escaped string.
10349 * _.escapeRegExp('[lodash](https://lodash.com/)');
10350 * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
10352 function escapeRegExp(string) {
10353 string = baseToString(string);
10354 return (string && reHasRegExpChars.test(string))
10355 ? string.replace(reRegExpChars, escapeRegExpChar)
10356 : (string || '(?:)');
10360 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
10365 * @param {string} [string=''] The string to convert.
10366 * @returns {string} Returns the kebab cased string.
10369 * _.kebabCase('Foo Bar');
10372 * _.kebabCase('fooBar');
10375 * _.kebabCase('__foo_bar__');
10378 var kebabCase = createCompounder(function(result, word, index) {
10379 return result + (index ? '-' : '') + word.toLowerCase();
10383 * Pads `string` on the left and right sides if it's shorter than `length`.
10384 * Padding characters are truncated if they can't be evenly divided by `length`.
10389 * @param {string} [string=''] The string to pad.
10390 * @param {number} [length=0] The padding length.
10391 * @param {string} [chars=' '] The string used as padding.
10392 * @returns {string} Returns the padded string.
10398 * _.pad('abc', 8, '_-');
10404 function pad(string, length, chars) {
10405 string = baseToString(string);
10408 var strLength = string.length;
10409 if (strLength >= length || !nativeIsFinite(length)) {
10412 var mid = (length - strLength) / 2,
10413 leftLength = nativeFloor(mid),
10414 rightLength = nativeCeil(mid);
10416 chars = createPadding('', rightLength, chars);
10417 return chars.slice(0, leftLength) + string + chars;
10421 * Pads `string` on the left side if it's shorter than `length`. Padding
10422 * characters are truncated if they exceed `length`.
10427 * @param {string} [string=''] The string to pad.
10428 * @param {number} [length=0] The padding length.
10429 * @param {string} [chars=' '] The string used as padding.
10430 * @returns {string} Returns the padded string.
10433 * _.padLeft('abc', 6);
10436 * _.padLeft('abc', 6, '_-');
10439 * _.padLeft('abc', 3);
10442 var padLeft = createPadDir();
10445 * Pads `string` on the right side if it's shorter than `length`. Padding
10446 * characters are truncated if they exceed `length`.
10451 * @param {string} [string=''] The string to pad.
10452 * @param {number} [length=0] The padding length.
10453 * @param {string} [chars=' '] The string used as padding.
10454 * @returns {string} Returns the padded string.
10457 * _.padRight('abc', 6);
10460 * _.padRight('abc', 6, '_-');
10463 * _.padRight('abc', 3);
10466 var padRight = createPadDir(true);
10469 * Converts `string` to an integer of the specified radix. If `radix` is
10470 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
10471 * in which case a `radix` of `16` is used.
10473 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
10479 * @param {string} string The string to convert.
10480 * @param {number} [radix] The radix to interpret `value` by.
10481 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10482 * @returns {number} Returns the converted integer.
10485 * _.parseInt('08');
10488 * _.map(['6', '08', '10'], _.parseInt);
10491 function parseInt(string, radix, guard) {
10492 // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
10493 // Chrome fails to trim leading <BOM> whitespace characters.
10494 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
10495 if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
10497 } else if (radix) {
10500 string = trim(string);
10501 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
10505 * Repeats the given string `n` times.
10510 * @param {string} [string=''] The string to repeat.
10511 * @param {number} [n=0] The number of times to repeat the string.
10512 * @returns {string} Returns the repeated string.
10515 * _.repeat('*', 3);
10518 * _.repeat('abc', 2);
10521 * _.repeat('abc', 0);
10524 function repeat(string, n) {
10526 string = baseToString(string);
10528 if (n < 1 || !string || !nativeIsFinite(n)) {
10531 // Leverage the exponentiation by squaring algorithm for a faster repeat.
10532 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
10537 n = nativeFloor(n / 2);
10545 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
10550 * @param {string} [string=''] The string to convert.
10551 * @returns {string} Returns the snake cased string.
10554 * _.snakeCase('Foo Bar');
10557 * _.snakeCase('fooBar');
10560 * _.snakeCase('--foo-bar');
10563 var snakeCase = createCompounder(function(result, word, index) {
10564 return result + (index ? '_' : '') + word.toLowerCase();
10568 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
10573 * @param {string} [string=''] The string to convert.
10574 * @returns {string} Returns the start cased string.
10577 * _.startCase('--foo-bar');
10580 * _.startCase('fooBar');
10583 * _.startCase('__foo_bar__');
10586 var startCase = createCompounder(function(result, word, index) {
10587 return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
10591 * Checks if `string` starts with the given target string.
10596 * @param {string} [string=''] The string to search.
10597 * @param {string} [target] The string to search for.
10598 * @param {number} [position=0] The position to search from.
10599 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
10602 * _.startsWith('abc', 'a');
10605 * _.startsWith('abc', 'b');
10608 * _.startsWith('abc', 'b', 1);
10611 function startsWith(string, target, position) {
10612 string = baseToString(string);
10613 position = position == null
10615 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
10617 return string.lastIndexOf(target, position) == position;
10621 * Creates a compiled template function that can interpolate data properties
10622 * in "interpolate" delimiters, HTML-escape interpolated data properties in
10623 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
10624 * properties may be accessed as free variables in the template. If a setting
10625 * object is provided it takes precedence over `_.templateSettings` values.
10627 * **Note:** In the development build `_.template` utilizes
10628 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
10629 * for easier debugging.
10631 * For more information on precompiling templates see
10632 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
10634 * For more information on Chrome extension sandboxes see
10635 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
10640 * @param {string} [string=''] The template string.
10641 * @param {Object} [options] The options object.
10642 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
10643 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
10644 * @param {Object} [options.imports] An object to import into the template as free variables.
10645 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
10646 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
10647 * @param {string} [options.variable] The data object variable name.
10648 * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
10649 * @returns {Function} Returns the compiled template function.
10652 * // using the "interpolate" delimiter to create a compiled template
10653 * var compiled = _.template('hello <%= user %>!');
10654 * compiled({ 'user': 'fred' });
10655 * // => 'hello fred!'
10657 * // using the HTML "escape" delimiter to escape data property values
10658 * var compiled = _.template('<b><%- value %></b>');
10659 * compiled({ 'value': '<script>' });
10660 * // => '<b><script></b>'
10662 * // using the "evaluate" delimiter to execute JavaScript and generate HTML
10663 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
10664 * compiled({ 'users': ['fred', 'barney'] });
10665 * // => '<li>fred</li><li>barney</li>'
10667 * // using the internal `print` function in "evaluate" delimiters
10668 * var compiled = _.template('<% print("hello " + user); %>!');
10669 * compiled({ 'user': 'barney' });
10670 * // => 'hello barney!'
10672 * // using the ES delimiter as an alternative to the default "interpolate" delimiter
10673 * var compiled = _.template('hello ${ user }!');
10674 * compiled({ 'user': 'pebbles' });
10675 * // => 'hello pebbles!'
10677 * // using custom template delimiters
10678 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
10679 * var compiled = _.template('hello {{ user }}!');
10680 * compiled({ 'user': 'mustache' });
10681 * // => 'hello mustache!'
10683 * // using backslashes to treat delimiters as plain text
10684 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
10685 * compiled({ 'value': 'ignored' });
10686 * // => '<%- value %>'
10688 * // using the `imports` option to import `jQuery` as `jq`
10689 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
10690 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
10691 * compiled({ 'users': ['fred', 'barney'] });
10692 * // => '<li>fred</li><li>barney</li>'
10694 * // using the `sourceURL` option to specify a custom sourceURL for the template
10695 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
10697 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
10699 * // using the `variable` option to ensure a with-statement isn't used in the compiled template
10700 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
10702 * // => function(data) {
10703 * // var __t, __p = '';
10704 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
10708 * // using the `source` property to inline compiled templates for meaningful
10709 * // line numbers in error messages and a stack trace
10710 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
10712 * "main": ' + _.template(mainText).source + '\
10716 function template(string, options, otherOptions) {
10717 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
10718 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
10719 var settings = lodash.templateSettings;
10721 if (otherOptions && isIterateeCall(string, options, otherOptions)) {
10722 options = otherOptions = undefined;
10724 string = baseToString(string);
10725 options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
10727 var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
10728 importsKeys = keys(imports),
10729 importsValues = baseValues(imports, importsKeys);
10734 interpolate = options.interpolate || reNoMatch,
10735 source = "__p += '";
10737 // Compile the regexp to match each delimiter.
10738 var reDelimiters = RegExp(
10739 (options.escape || reNoMatch).source + '|' +
10740 interpolate.source + '|' +
10741 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
10742 (options.evaluate || reNoMatch).source + '|$'
10745 // Use a sourceURL for easier debugging.
10746 var sourceURL = '//# sourceURL=' +
10747 ('sourceURL' in options
10748 ? options.sourceURL
10749 : ('lodash.templateSources[' + (++templateCounter) + ']')
10752 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
10753 interpolateValue || (interpolateValue = esTemplateValue);
10755 // Escape characters that can't be included in string literals.
10756 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
10758 // Replace delimiters with snippets.
10761 source += "' +\n__e(" + escapeValue + ") +\n'";
10763 if (evaluateValue) {
10764 isEvaluating = true;
10765 source += "';\n" + evaluateValue + ";\n__p += '";
10767 if (interpolateValue) {
10768 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
10770 index = offset + match.length;
10772 // The JS engine embedded in Adobe products requires returning the `match`
10773 // string in order to produce the correct `offset` value.
10779 // If `variable` is not specified wrap a with-statement around the generated
10780 // code to add the data object to the top of the scope chain.
10781 var variable = options.variable;
10783 source = 'with (obj) {\n' + source + '\n}\n';
10785 // Cleanup code by stripping empty strings.
10786 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
10787 .replace(reEmptyStringMiddle, '$1')
10788 .replace(reEmptyStringTrailing, '$1;');
10790 // Frame code as the function body.
10791 source = 'function(' + (variable || 'obj') + ') {\n' +
10794 : 'obj || (obj = {});\n'
10796 "var __t, __p = ''" +
10798 ? ', __e = _.escape'
10802 ? ', __j = Array.prototype.join;\n' +
10803 "function print() { __p += __j.call(arguments, '') }\n"
10809 var result = attempt(function() {
10810 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
10813 // Provide the compiled function's source by its `toString` method or
10814 // the `source` property as a convenience for inlining compiled templates.
10815 result.source = source;
10816 if (isError(result)) {
10823 * Removes leading and trailing whitespace or specified characters from `string`.
10828 * @param {string} [string=''] The string to trim.
10829 * @param {string} [chars=whitespace] The characters to trim.
10830 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10831 * @returns {string} Returns the trimmed string.
10837 * _.trim('-_-abc-_-', '_-');
10840 * _.map([' foo ', ' bar '], _.trim);
10841 * // => ['foo', 'bar']
10843 function trim(string, chars, guard) {
10844 var value = string;
10845 string = baseToString(string);
10849 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10850 return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
10852 chars = (chars + '');
10853 return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
10857 * Removes leading whitespace or specified characters from `string`.
10862 * @param {string} [string=''] The string to trim.
10863 * @param {string} [chars=whitespace] The characters to trim.
10864 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10865 * @returns {string} Returns the trimmed string.
10868 * _.trimLeft(' abc ');
10871 * _.trimLeft('-_-abc-_-', '_-');
10874 function trimLeft(string, chars, guard) {
10875 var value = string;
10876 string = baseToString(string);
10880 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10881 return string.slice(trimmedLeftIndex(string));
10883 return string.slice(charsLeftIndex(string, (chars + '')));
10887 * Removes trailing whitespace or specified characters from `string`.
10892 * @param {string} [string=''] The string to trim.
10893 * @param {string} [chars=whitespace] The characters to trim.
10894 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10895 * @returns {string} Returns the trimmed string.
10898 * _.trimRight(' abc ');
10901 * _.trimRight('-_-abc-_-', '_-');
10904 function trimRight(string, chars, guard) {
10905 var value = string;
10906 string = baseToString(string);
10910 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10911 return string.slice(0, trimmedRightIndex(string) + 1);
10913 return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
10917 * Truncates `string` if it's longer than the given maximum string length.
10918 * The last characters of the truncated string are replaced with the omission
10919 * string which defaults to "...".
10924 * @param {string} [string=''] The string to truncate.
10925 * @param {Object|number} [options] The options object or maximum string length.
10926 * @param {number} [options.length=30] The maximum string length.
10927 * @param {string} [options.omission='...'] The string to indicate text is omitted.
10928 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
10929 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10930 * @returns {string} Returns the truncated string.
10933 * _.trunc('hi-diddly-ho there, neighborino');
10934 * // => 'hi-diddly-ho there, neighbo...'
10936 * _.trunc('hi-diddly-ho there, neighborino', 24);
10937 * // => 'hi-diddly-ho there, n...'
10939 * _.trunc('hi-diddly-ho there, neighborino', {
10943 * // => 'hi-diddly-ho there,...'
10945 * _.trunc('hi-diddly-ho there, neighborino', {
10947 * 'separator': /,? +/
10949 * // => 'hi-diddly-ho there...'
10951 * _.trunc('hi-diddly-ho there, neighborino', {
10952 * 'omission': ' [...]'
10954 * // => 'hi-diddly-ho there, neig [...]'
10956 function trunc(string, options, guard) {
10957 if (guard && isIterateeCall(string, options, guard)) {
10958 options = undefined;
10960 var length = DEFAULT_TRUNC_LENGTH,
10961 omission = DEFAULT_TRUNC_OMISSION;
10963 if (options != null) {
10964 if (isObject(options)) {
10965 var separator = 'separator' in options ? options.separator : separator;
10966 length = 'length' in options ? (+options.length || 0) : length;
10967 omission = 'omission' in options ? baseToString(options.omission) : omission;
10969 length = +options || 0;
10972 string = baseToString(string);
10973 if (length >= string.length) {
10976 var end = length - omission.length;
10980 var result = string.slice(0, end);
10981 if (separator == null) {
10982 return result + omission;
10984 if (isRegExp(separator)) {
10985 if (string.slice(end).search(separator)) {
10988 substring = string.slice(0, end);
10990 if (!separator.global) {
10991 separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
10993 separator.lastIndex = 0;
10994 while ((match = separator.exec(substring))) {
10995 newEnd = match.index;
10997 result = result.slice(0, newEnd == null ? end : newEnd);
10999 } else if (string.indexOf(separator, end) != end) {
11000 var index = result.lastIndexOf(separator);
11002 result = result.slice(0, index);
11005 return result + omission;
11009 * The inverse of `_.escape`; this method converts the HTML entities
11010 * `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
11011 * corresponding characters.
11013 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
11014 * entities use a third-party library like [_he_](https://mths.be/he).
11019 * @param {string} [string=''] The string to unescape.
11020 * @returns {string} Returns the unescaped string.
11023 * _.unescape('fred, barney, & pebbles');
11024 * // => 'fred, barney, & pebbles'
11026 function unescape(string) {
11027 string = baseToString(string);
11028 return (string && reHasEscapedHtml.test(string))
11029 ? string.replace(reEscapedHtml, unescapeHtmlChar)
11034 * Splits `string` into an array of its words.
11039 * @param {string} [string=''] The string to inspect.
11040 * @param {RegExp|string} [pattern] The pattern to match words.
11041 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11042 * @returns {Array} Returns the words of `string`.
11045 * _.words('fred, barney, & pebbles');
11046 * // => ['fred', 'barney', 'pebbles']
11048 * _.words('fred, barney, & pebbles', /[^, ]+/g);
11049 * // => ['fred', 'barney', '&', 'pebbles']
11051 function words(string, pattern, guard) {
11052 if (guard && isIterateeCall(string, pattern, guard)) {
11053 pattern = undefined;
11055 string = baseToString(string);
11056 return string.match(pattern || reWords) || [];
11059 /*------------------------------------------------------------------------*/
11062 * Attempts to invoke `func`, returning either the result or the caught error
11063 * object. Any additional arguments are provided to `func` when it's invoked.
11067 * @category Utility
11068 * @param {Function} func The function to attempt.
11069 * @returns {*} Returns the `func` result or error object.
11072 * // avoid throwing errors for invalid selectors
11073 * var elements = _.attempt(function(selector) {
11074 * return document.querySelectorAll(selector);
11077 * if (_.isError(elements)) {
11081 var attempt = restParam(function(func, args) {
11083 return func.apply(undefined, args);
11085 return isError(e) ? e : new Error(e);
11090 * Creates a function that invokes `func` with the `this` binding of `thisArg`
11091 * and arguments of the created function. If `func` is a property name the
11092 * created callback returns the property value for a given element. If `func`
11093 * is an object the created callback returns `true` for elements that contain
11094 * the equivalent object properties, otherwise it returns `false`.
11099 * @category Utility
11100 * @param {*} [func=_.identity] The value to convert to a callback.
11101 * @param {*} [thisArg] The `this` binding of `func`.
11102 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11103 * @returns {Function} Returns the callback.
11107 * { 'user': 'barney', 'age': 36 },
11108 * { 'user': 'fred', 'age': 40 }
11111 * // wrap to create custom callback shorthands
11112 * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
11113 * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
11115 * return callback(func, thisArg);
11117 * return function(object) {
11118 * return match[2] == 'gt'
11119 * ? object[match[1]] > match[3]
11120 * : object[match[1]] < match[3];
11124 * _.filter(users, 'age__gt36');
11125 * // => [{ 'user': 'fred', 'age': 40 }]
11127 function callback(func, thisArg, guard) {
11128 if (guard && isIterateeCall(func, thisArg, guard)) {
11129 thisArg = undefined;
11131 return isObjectLike(func)
11133 : baseCallback(func, thisArg);
11137 * Creates a function that returns `value`.
11141 * @category Utility
11142 * @param {*} value The value to return from the new function.
11143 * @returns {Function} Returns the new function.
11146 * var object = { 'user': 'fred' };
11147 * var getter = _.constant(object);
11149 * getter() === object;
11152 function constant(value) {
11153 return function() {
11159 * This method returns the first argument provided to it.
11163 * @category Utility
11164 * @param {*} value Any value.
11165 * @returns {*} Returns `value`.
11168 * var object = { 'user': 'fred' };
11170 * _.identity(object) === object;
11173 function identity(value) {
11178 * Creates a function that performs a deep comparison between a given object
11179 * and `source`, returning `true` if the given object has equivalent property
11180 * values, else `false`.
11182 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11183 * numbers, `Object` objects, regexes, and strings. Objects are compared by
11184 * their own, not inherited, enumerable properties. For comparing a single
11185 * own or inherited property value see `_.matchesProperty`.
11189 * @category Utility
11190 * @param {Object} source The object of property values to match.
11191 * @returns {Function} Returns the new function.
11195 * { 'user': 'barney', 'age': 36, 'active': true },
11196 * { 'user': 'fred', 'age': 40, 'active': false }
11199 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
11200 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
11202 function matches(source) {
11203 return baseMatches(baseClone(source, true));
11207 * Creates a function that compares the property value of `path` on a given
11208 * object to `value`.
11210 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11211 * numbers, `Object` objects, regexes, and strings. Objects are compared by
11212 * their own, not inherited, enumerable properties.
11216 * @category Utility
11217 * @param {Array|string} path The path of the property to get.
11218 * @param {*} srcValue The value to match.
11219 * @returns {Function} Returns the new function.
11223 * { 'user': 'barney' },
11224 * { 'user': 'fred' }
11227 * _.find(users, _.matchesProperty('user', 'fred'));
11228 * // => { 'user': 'fred' }
11230 function matchesProperty(path, srcValue) {
11231 return baseMatchesProperty(path, baseClone(srcValue, true));
11235 * Creates a function that invokes the method at `path` on a given object.
11236 * Any additional arguments are provided to the invoked method.
11240 * @category Utility
11241 * @param {Array|string} path The path of the method to invoke.
11242 * @param {...*} [args] The arguments to invoke the method with.
11243 * @returns {Function} Returns the new function.
11247 * { 'a': { 'b': { 'c': _.constant(2) } } },
11248 * { 'a': { 'b': { 'c': _.constant(1) } } }
11251 * _.map(objects, _.method('a.b.c'));
11254 * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
11257 var method = restParam(function(path, args) {
11258 return function(object) {
11259 return invokePath(object, path, args);
11264 * The opposite of `_.method`; this method creates a function that invokes
11265 * the method at a given path on `object`. Any additional arguments are
11266 * provided to the invoked method.
11270 * @category Utility
11271 * @param {Object} object The object to query.
11272 * @param {...*} [args] The arguments to invoke the method with.
11273 * @returns {Function} Returns the new function.
11276 * var array = _.times(3, _.constant),
11277 * object = { 'a': array, 'b': array, 'c': array };
11279 * _.map(['a[2]', 'c[0]'], _.methodOf(object));
11282 * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
11285 var methodOf = restParam(function(object, args) {
11286 return function(path) {
11287 return invokePath(object, path, args);
11292 * Adds all own enumerable function properties of a source object to the
11293 * destination object. If `object` is a function then methods are added to
11294 * its prototype as well.
11296 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
11297 * avoid conflicts caused by modifying the original.
11301 * @category Utility
11302 * @param {Function|Object} [object=lodash] The destination object.
11303 * @param {Object} source The object of functions to add.
11304 * @param {Object} [options] The options object.
11305 * @param {boolean} [options.chain=true] Specify whether the functions added
11307 * @returns {Function|Object} Returns `object`.
11310 * function vowels(string) {
11311 * return _.filter(string, function(v) {
11312 * return /[aeiou]/i.test(v);
11316 * _.mixin({ 'vowels': vowels });
11317 * _.vowels('fred');
11320 * _('fred').vowels().value();
11323 * _.mixin({ 'vowels': vowels }, { 'chain': false });
11324 * _('fred').vowels();
11327 function mixin(object, source, options) {
11328 if (options == null) {
11329 var isObj = isObject(source),
11330 props = isObj ? keys(source) : undefined,
11331 methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
11333 if (!(methodNames ? methodNames.length : isObj)) {
11334 methodNames = false;
11340 if (!methodNames) {
11341 methodNames = baseFunctions(source, keys(source));
11345 isFunc = isFunction(object),
11346 length = methodNames.length;
11348 if (options === false) {
11350 } else if (isObject(options) && 'chain' in options) {
11351 chain = options.chain;
11353 while (++index < length) {
11354 var methodName = methodNames[index],
11355 func = source[methodName];
11357 object[methodName] = func;
11359 object.prototype[methodName] = (function(func) {
11360 return function() {
11361 var chainAll = this.__chain__;
11362 if (chain || chainAll) {
11363 var result = object(this.__wrapped__),
11364 actions = result.__actions__ = arrayCopy(this.__actions__);
11366 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
11367 result.__chain__ = chainAll;
11370 return func.apply(object, arrayPush([this.value()], arguments));
11379 * Reverts the `_` variable to its previous value and returns a reference to
11380 * the `lodash` function.
11384 * @category Utility
11385 * @returns {Function} Returns the `lodash` function.
11388 * var lodash = _.noConflict();
11390 function noConflict() {
11396 * A no-operation function that returns `undefined` regardless of the
11397 * arguments it receives.
11401 * @category Utility
11404 * var object = { 'user': 'fred' };
11406 * _.noop(object) === undefined;
11410 // No operation performed.
11414 * Creates a function that returns the property value at `path` on a
11419 * @category Utility
11420 * @param {Array|string} path The path of the property to get.
11421 * @returns {Function} Returns the new function.
11425 * { 'a': { 'b': { 'c': 2 } } },
11426 * { 'a': { 'b': { 'c': 1 } } }
11429 * _.map(objects, _.property('a.b.c'));
11432 * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
11435 function property(path) {
11436 return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
11440 * The opposite of `_.property`; this method creates a function that returns
11441 * the property value at a given path on `object`.
11445 * @category Utility
11446 * @param {Object} object The object to query.
11447 * @returns {Function} Returns the new function.
11450 * var array = [0, 1, 2],
11451 * object = { 'a': array, 'b': array, 'c': array };
11453 * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
11456 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
11459 function propertyOf(object) {
11460 return function(path) {
11461 return baseGet(object, toPath(path), (path + ''));
11466 * Creates an array of numbers (positive and/or negative) progressing from
11467 * `start` up to, but not including, `end`. If `end` is not specified it's
11468 * set to `start` with `start` then set to `0`. If `end` is less than `start`
11469 * a zero-length range is created unless a negative `step` is specified.
11473 * @category Utility
11474 * @param {number} [start=0] The start of the range.
11475 * @param {number} end The end of the range.
11476 * @param {number} [step=1] The value to increment or decrement by.
11477 * @returns {Array} Returns the new array of numbers.
11481 * // => [0, 1, 2, 3]
11484 * // => [1, 2, 3, 4]
11486 * _.range(0, 20, 5);
11487 * // => [0, 5, 10, 15]
11489 * _.range(0, -4, -1);
11490 * // => [0, -1, -2, -3]
11492 * _.range(1, 4, 0);
11498 function range(start, end, step) {
11499 if (step && isIterateeCall(start, end, step)) {
11500 end = step = undefined;
11502 start = +start || 0;
11503 step = step == null ? 1 : (+step || 0);
11511 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
11512 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
11514 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
11515 result = Array(length);
11517 while (++index < length) {
11518 result[index] = start;
11525 * Invokes the iteratee function `n` times, returning an array of the results
11526 * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
11527 * one argument; (index).
11531 * @category Utility
11532 * @param {number} n The number of times to invoke `iteratee`.
11533 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11534 * @param {*} [thisArg] The `this` binding of `iteratee`.
11535 * @returns {Array} Returns the array of results.
11538 * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
11541 * _.times(3, function(n) {
11542 * mage.castSpell(n);
11544 * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
11546 * _.times(3, function(n) {
11549 * // => also invokes `mage.castSpell(n)` three times
11551 function times(n, iteratee, thisArg) {
11552 n = nativeFloor(n);
11554 // Exit early to avoid a JSC JIT bug in Safari 8
11555 // where `Array(0)` is treated as `Array(1)`.
11556 if (n < 1 || !nativeIsFinite(n)) {
11560 result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
11562 iteratee = bindCallback(iteratee, thisArg, 1);
11563 while (++index < n) {
11564 if (index < MAX_ARRAY_LENGTH) {
11565 result[index] = iteratee(index);
11574 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
11578 * @category Utility
11579 * @param {string} [prefix] The value to prefix the ID with.
11580 * @returns {string} Returns the unique ID.
11583 * _.uniqueId('contact_');
11584 * // => 'contact_104'
11589 function uniqueId(prefix) {
11590 var id = ++idCounter;
11591 return baseToString(prefix) + id;
11594 /*------------------------------------------------------------------------*/
11597 * Adds two numbers.
11602 * @param {number} augend The first number to add.
11603 * @param {number} addend The second number to add.
11604 * @returns {number} Returns the sum.
11610 function add(augend, addend) {
11611 return (+augend || 0) + (+addend || 0);
11615 * Calculates `n` rounded up to `precision`.
11620 * @param {number} n The number to round up.
11621 * @param {number} [precision=0] The precision to round up to.
11622 * @returns {number} Returns the rounded up number.
11628 * _.ceil(6.004, 2);
11631 * _.ceil(6040, -2);
11634 var ceil = createRound('ceil');
11637 * Calculates `n` rounded down to `precision`.
11642 * @param {number} n The number to round down.
11643 * @param {number} [precision=0] The precision to round down to.
11644 * @returns {number} Returns the rounded down number.
11650 * _.floor(0.046, 2);
11653 * _.floor(4060, -2);
11656 var floor = createRound('floor');
11659 * Gets the maximum value of `collection`. If `collection` is empty or falsey
11660 * `-Infinity` is returned. If an iteratee function is provided it's invoked
11661 * for each value in `collection` to generate the criterion by which the value
11662 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11663 * arguments: (value, index, collection).
11665 * If a property name is provided for `iteratee` the created `_.property`
11666 * style callback returns the property value of the given element.
11668 * If a value is also provided for `thisArg` the created `_.matchesProperty`
11669 * style callback returns `true` for elements that have a matching property
11670 * value, else `false`.
11672 * If an object is provided for `iteratee` the created `_.matches` style
11673 * callback returns `true` for elements that have the properties of the given
11674 * object, else `false`.
11679 * @param {Array|Object|string} collection The collection to iterate over.
11680 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11681 * @param {*} [thisArg] The `this` binding of `iteratee`.
11682 * @returns {*} Returns the maximum value.
11685 * _.max([4, 2, 8, 6]);
11692 * { 'user': 'barney', 'age': 36 },
11693 * { 'user': 'fred', 'age': 40 }
11696 * _.max(users, function(chr) {
11699 * // => { 'user': 'fred', 'age': 40 }
11701 * // using the `_.property` callback shorthand
11702 * _.max(users, 'age');
11703 * // => { 'user': 'fred', 'age': 40 }
11705 var max = createExtremum(gt, NEGATIVE_INFINITY);
11708 * Gets the minimum value of `collection`. If `collection` is empty or falsey
11709 * `Infinity` is returned. If an iteratee function is provided it's invoked
11710 * for each value in `collection` to generate the criterion by which the value
11711 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11712 * arguments: (value, index, collection).
11714 * If a property name is provided for `iteratee` the created `_.property`
11715 * style callback returns the property value of the given element.
11717 * If a value is also provided for `thisArg` the created `_.matchesProperty`
11718 * style callback returns `true` for elements that have a matching property
11719 * value, else `false`.
11721 * If an object is provided for `iteratee` the created `_.matches` style
11722 * callback returns `true` for elements that have the properties of the given
11723 * object, else `false`.
11728 * @param {Array|Object|string} collection The collection to iterate over.
11729 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11730 * @param {*} [thisArg] The `this` binding of `iteratee`.
11731 * @returns {*} Returns the minimum value.
11734 * _.min([4, 2, 8, 6]);
11741 * { 'user': 'barney', 'age': 36 },
11742 * { 'user': 'fred', 'age': 40 }
11745 * _.min(users, function(chr) {
11748 * // => { 'user': 'barney', 'age': 36 }
11750 * // using the `_.property` callback shorthand
11751 * _.min(users, 'age');
11752 * // => { 'user': 'barney', 'age': 36 }
11754 var min = createExtremum(lt, POSITIVE_INFINITY);
11757 * Calculates `n` rounded to `precision`.
11762 * @param {number} n The number to round.
11763 * @param {number} [precision=0] The precision to round to.
11764 * @returns {number} Returns the rounded number.
11770 * _.round(4.006, 2);
11773 * _.round(4060, -2);
11776 var round = createRound('round');
11779 * Gets the sum of the values in `collection`.
11784 * @param {Array|Object|string} collection The collection to iterate over.
11785 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11786 * @param {*} [thisArg] The `this` binding of `iteratee`.
11787 * @returns {number} Returns the sum.
11793 * _.sum({ 'a': 4, 'b': 6 });
11801 * _.sum(objects, function(object) {
11806 * // using the `_.property` callback shorthand
11807 * _.sum(objects, 'n');
11810 function sum(collection, iteratee, thisArg) {
11811 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
11812 iteratee = undefined;
11814 iteratee = getCallback(iteratee, thisArg, 3);
11815 return iteratee.length == 1
11816 ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
11817 : baseSum(collection, iteratee);
11820 /*------------------------------------------------------------------------*/
11822 // Ensure wrappers are instances of `baseLodash`.
11823 lodash.prototype = baseLodash.prototype;
11825 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
11826 LodashWrapper.prototype.constructor = LodashWrapper;
11828 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
11829 LazyWrapper.prototype.constructor = LazyWrapper;
11831 // Add functions to the `Map` cache.
11832 MapCache.prototype['delete'] = mapDelete;
11833 MapCache.prototype.get = mapGet;
11834 MapCache.prototype.has = mapHas;
11835 MapCache.prototype.set = mapSet;
11837 // Add functions to the `Set` cache.
11838 SetCache.prototype.push = cachePush;
11840 // Assign cache to `_.memoize`.
11841 memoize.Cache = MapCache;
11843 // Add functions that return wrapped values when chaining.
11844 lodash.after = after;
11846 lodash.assign = assign;
11848 lodash.before = before;
11849 lodash.bind = bind;
11850 lodash.bindAll = bindAll;
11851 lodash.bindKey = bindKey;
11852 lodash.callback = callback;
11853 lodash.chain = chain;
11854 lodash.chunk = chunk;
11855 lodash.compact = compact;
11856 lodash.constant = constant;
11857 lodash.countBy = countBy;
11858 lodash.create = create;
11859 lodash.curry = curry;
11860 lodash.curryRight = curryRight;
11861 lodash.debounce = debounce;
11862 lodash.defaults = defaults;
11863 lodash.defaultsDeep = defaultsDeep;
11864 lodash.defer = defer;
11865 lodash.delay = delay;
11866 lodash.difference = difference;
11867 lodash.drop = drop;
11868 lodash.dropRight = dropRight;
11869 lodash.dropRightWhile = dropRightWhile;
11870 lodash.dropWhile = dropWhile;
11871 lodash.fill = fill;
11872 lodash.filter = filter;
11873 lodash.flatten = flatten;
11874 lodash.flattenDeep = flattenDeep;
11875 lodash.flow = flow;
11876 lodash.flowRight = flowRight;
11877 lodash.forEach = forEach;
11878 lodash.forEachRight = forEachRight;
11879 lodash.forIn = forIn;
11880 lodash.forInRight = forInRight;
11881 lodash.forOwn = forOwn;
11882 lodash.forOwnRight = forOwnRight;
11883 lodash.functions = functions;
11884 lodash.groupBy = groupBy;
11885 lodash.indexBy = indexBy;
11886 lodash.initial = initial;
11887 lodash.intersection = intersection;
11888 lodash.invert = invert;
11889 lodash.invoke = invoke;
11890 lodash.keys = keys;
11891 lodash.keysIn = keysIn;
11893 lodash.mapKeys = mapKeys;
11894 lodash.mapValues = mapValues;
11895 lodash.matches = matches;
11896 lodash.matchesProperty = matchesProperty;
11897 lodash.memoize = memoize;
11898 lodash.merge = merge;
11899 lodash.method = method;
11900 lodash.methodOf = methodOf;
11901 lodash.mixin = mixin;
11902 lodash.modArgs = modArgs;
11903 lodash.negate = negate;
11904 lodash.omit = omit;
11905 lodash.once = once;
11906 lodash.pairs = pairs;
11907 lodash.partial = partial;
11908 lodash.partialRight = partialRight;
11909 lodash.partition = partition;
11910 lodash.pick = pick;
11911 lodash.pluck = pluck;
11912 lodash.property = property;
11913 lodash.propertyOf = propertyOf;
11914 lodash.pull = pull;
11915 lodash.pullAt = pullAt;
11916 lodash.range = range;
11917 lodash.rearg = rearg;
11918 lodash.reject = reject;
11919 lodash.remove = remove;
11920 lodash.rest = rest;
11921 lodash.restParam = restParam;
11923 lodash.shuffle = shuffle;
11924 lodash.slice = slice;
11925 lodash.sortBy = sortBy;
11926 lodash.sortByAll = sortByAll;
11927 lodash.sortByOrder = sortByOrder;
11928 lodash.spread = spread;
11929 lodash.take = take;
11930 lodash.takeRight = takeRight;
11931 lodash.takeRightWhile = takeRightWhile;
11932 lodash.takeWhile = takeWhile;
11934 lodash.throttle = throttle;
11935 lodash.thru = thru;
11936 lodash.times = times;
11937 lodash.toArray = toArray;
11938 lodash.toPlainObject = toPlainObject;
11939 lodash.transform = transform;
11940 lodash.union = union;
11941 lodash.uniq = uniq;
11942 lodash.unzip = unzip;
11943 lodash.unzipWith = unzipWith;
11944 lodash.values = values;
11945 lodash.valuesIn = valuesIn;
11946 lodash.where = where;
11947 lodash.without = without;
11948 lodash.wrap = wrap;
11951 lodash.zipObject = zipObject;
11952 lodash.zipWith = zipWith;
11955 lodash.backflow = flowRight;
11956 lodash.collect = map;
11957 lodash.compose = flowRight;
11958 lodash.each = forEach;
11959 lodash.eachRight = forEachRight;
11960 lodash.extend = assign;
11961 lodash.iteratee = callback;
11962 lodash.methods = functions;
11963 lodash.object = zipObject;
11964 lodash.select = filter;
11965 lodash.tail = rest;
11966 lodash.unique = uniq;
11968 // Add functions to `lodash.prototype`.
11969 mixin(lodash, lodash);
11971 /*------------------------------------------------------------------------*/
11973 // Add functions that return unwrapped values when chaining.
11975 lodash.attempt = attempt;
11976 lodash.camelCase = camelCase;
11977 lodash.capitalize = capitalize;
11978 lodash.ceil = ceil;
11979 lodash.clone = clone;
11980 lodash.cloneDeep = cloneDeep;
11981 lodash.deburr = deburr;
11982 lodash.endsWith = endsWith;
11983 lodash.escape = escape;
11984 lodash.escapeRegExp = escapeRegExp;
11985 lodash.every = every;
11986 lodash.find = find;
11987 lodash.findIndex = findIndex;
11988 lodash.findKey = findKey;
11989 lodash.findLast = findLast;
11990 lodash.findLastIndex = findLastIndex;
11991 lodash.findLastKey = findLastKey;
11992 lodash.findWhere = findWhere;
11993 lodash.first = first;
11994 lodash.floor = floor;
11999 lodash.identity = identity;
12000 lodash.includes = includes;
12001 lodash.indexOf = indexOf;
12002 lodash.inRange = inRange;
12003 lodash.isArguments = isArguments;
12004 lodash.isArray = isArray;
12005 lodash.isBoolean = isBoolean;
12006 lodash.isDate = isDate;
12007 lodash.isElement = isElement;
12008 lodash.isEmpty = isEmpty;
12009 lodash.isEqual = isEqual;
12010 lodash.isError = isError;
12011 lodash.isFinite = isFinite;
12012 lodash.isFunction = isFunction;
12013 lodash.isMatch = isMatch;
12014 lodash.isNaN = isNaN;
12015 lodash.isNative = isNative;
12016 lodash.isNull = isNull;
12017 lodash.isNumber = isNumber;
12018 lodash.isObject = isObject;
12019 lodash.isPlainObject = isPlainObject;
12020 lodash.isRegExp = isRegExp;
12021 lodash.isString = isString;
12022 lodash.isTypedArray = isTypedArray;
12023 lodash.isUndefined = isUndefined;
12024 lodash.kebabCase = kebabCase;
12025 lodash.last = last;
12026 lodash.lastIndexOf = lastIndexOf;
12031 lodash.noConflict = noConflict;
12032 lodash.noop = noop;
12035 lodash.padLeft = padLeft;
12036 lodash.padRight = padRight;
12037 lodash.parseInt = parseInt;
12038 lodash.random = random;
12039 lodash.reduce = reduce;
12040 lodash.reduceRight = reduceRight;
12041 lodash.repeat = repeat;
12042 lodash.result = result;
12043 lodash.round = round;
12044 lodash.runInContext = runInContext;
12045 lodash.size = size;
12046 lodash.snakeCase = snakeCase;
12047 lodash.some = some;
12048 lodash.sortedIndex = sortedIndex;
12049 lodash.sortedLastIndex = sortedLastIndex;
12050 lodash.startCase = startCase;
12051 lodash.startsWith = startsWith;
12053 lodash.template = template;
12054 lodash.trim = trim;
12055 lodash.trimLeft = trimLeft;
12056 lodash.trimRight = trimRight;
12057 lodash.trunc = trunc;
12058 lodash.unescape = unescape;
12059 lodash.uniqueId = uniqueId;
12060 lodash.words = words;
12063 lodash.all = every;
12065 lodash.contains = includes;
12066 lodash.eq = isEqual;
12067 lodash.detect = find;
12068 lodash.foldl = reduce;
12069 lodash.foldr = reduceRight;
12070 lodash.head = first;
12071 lodash.include = includes;
12072 lodash.inject = reduce;
12074 mixin(lodash, (function() {
12076 baseForOwn(lodash, function(func, methodName) {
12077 if (!lodash.prototype[methodName]) {
12078 source[methodName] = func;
12084 /*------------------------------------------------------------------------*/
12086 // Add functions capable of returning wrapped and unwrapped values when chaining.
12087 lodash.sample = sample;
12089 lodash.prototype.sample = function(n) {
12090 if (!this.__chain__ && n == null) {
12091 return sample(this.value());
12093 return this.thru(function(value) {
12094 return sample(value, n);
12098 /*------------------------------------------------------------------------*/
12101 * The semantic version number.
12107 lodash.VERSION = VERSION;
12109 // Assign default placeholders.
12110 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
12111 lodash[methodName].placeholder = lodash;
12114 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
12115 arrayEach(['drop', 'take'], function(methodName, index) {
12116 LazyWrapper.prototype[methodName] = function(n) {
12117 var filtered = this.__filtered__;
12118 if (filtered && !index) {
12119 return new LazyWrapper(this);
12121 n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
12123 var result = this.clone();
12125 result.__takeCount__ = nativeMin(result.__takeCount__, n);
12127 result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
12132 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
12133 return this.reverse()[methodName](n).reverse();
12137 // Add `LazyWrapper` methods that accept an `iteratee` value.
12138 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
12139 var type = index + 1,
12140 isFilter = type != LAZY_MAP_FLAG;
12142 LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
12143 var result = this.clone();
12144 result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
12145 result.__filtered__ = result.__filtered__ || isFilter;
12150 // Add `LazyWrapper` methods for `_.first` and `_.last`.
12151 arrayEach(['first', 'last'], function(methodName, index) {
12152 var takeName = 'take' + (index ? 'Right' : '');
12154 LazyWrapper.prototype[methodName] = function() {
12155 return this[takeName](1).value()[0];
12159 // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
12160 arrayEach(['initial', 'rest'], function(methodName, index) {
12161 var dropName = 'drop' + (index ? '' : 'Right');
12163 LazyWrapper.prototype[methodName] = function() {
12164 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
12168 // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
12169 arrayEach(['pluck', 'where'], function(methodName, index) {
12170 var operationName = index ? 'filter' : 'map',
12171 createCallback = index ? baseMatches : property;
12173 LazyWrapper.prototype[methodName] = function(value) {
12174 return this[operationName](createCallback(value));
12178 LazyWrapper.prototype.compact = function() {
12179 return this.filter(identity);
12182 LazyWrapper.prototype.reject = function(predicate, thisArg) {
12183 predicate = getCallback(predicate, thisArg, 1);
12184 return this.filter(function(value) {
12185 return !predicate(value);
12189 LazyWrapper.prototype.slice = function(start, end) {
12190 start = start == null ? 0 : (+start || 0);
12193 if (result.__filtered__ && (start > 0 || end < 0)) {
12194 return new LazyWrapper(result);
12197 result = result.takeRight(-start);
12198 } else if (start) {
12199 result = result.drop(start);
12201 if (end !== undefined) {
12203 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
12208 LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
12209 return this.reverse().takeWhile(predicate, thisArg).reverse();
12212 LazyWrapper.prototype.toArray = function() {
12213 return this.take(POSITIVE_INFINITY);
12216 // Add `LazyWrapper` methods to `lodash.prototype`.
12217 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12218 var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
12219 retUnwrapped = /^(?:first|last)$/.test(methodName),
12220 lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
12225 lodash.prototype[methodName] = function() {
12226 var args = retUnwrapped ? [1] : arguments,
12227 chainAll = this.__chain__,
12228 value = this.__wrapped__,
12229 isHybrid = !!this.__actions__.length,
12230 isLazy = value instanceof LazyWrapper,
12231 iteratee = args[0],
12232 useLazy = isLazy || isArray(value);
12234 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
12235 // Avoid lazy use if the iteratee has a "length" value other than `1`.
12236 isLazy = useLazy = false;
12238 var interceptor = function(value) {
12239 return (retUnwrapped && chainAll)
12240 ? lodashFunc(value, 1)[0]
12241 : lodashFunc.apply(undefined, arrayPush([value], args));
12244 var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
12245 onlyLazy = isLazy && !isHybrid;
12247 if (retUnwrapped && !chainAll) {
12249 value = value.clone();
12250 value.__actions__.push(action);
12251 return func.call(value);
12253 return lodashFunc.call(undefined, this.value())[0];
12255 if (!retUnwrapped && useLazy) {
12256 value = onlyLazy ? value : new LazyWrapper(this);
12257 var result = func.apply(value, args);
12258 result.__actions__.push(action);
12259 return new LodashWrapper(result, chainAll);
12261 return this.thru(interceptor);
12265 // Add `Array` and `String` methods to `lodash.prototype`.
12266 arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
12267 var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
12268 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
12269 retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
12271 lodash.prototype[methodName] = function() {
12272 var args = arguments;
12273 if (retUnwrapped && !this.__chain__) {
12274 return func.apply(this.value(), args);
12276 return this[chainName](function(value) {
12277 return func.apply(value, args);
12282 // Map minified function names to their real names.
12283 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12284 var lodashFunc = lodash[methodName];
12286 var key = (lodashFunc.name + ''),
12287 names = realNames[key] || (realNames[key] = []);
12289 names.push({ 'name': methodName, 'func': lodashFunc });
12293 realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
12295 // Add functions to the lazy wrapper.
12296 LazyWrapper.prototype.clone = lazyClone;
12297 LazyWrapper.prototype.reverse = lazyReverse;
12298 LazyWrapper.prototype.value = lazyValue;
12300 // Add chaining functions to the `lodash` wrapper.
12301 lodash.prototype.chain = wrapperChain;
12302 lodash.prototype.commit = wrapperCommit;
12303 lodash.prototype.concat = wrapperConcat;
12304 lodash.prototype.plant = wrapperPlant;
12305 lodash.prototype.reverse = wrapperReverse;
12306 lodash.prototype.toString = wrapperToString;
12307 lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
12309 // Add function aliases to the `lodash` wrapper.
12310 lodash.prototype.collect = lodash.prototype.map;
12311 lodash.prototype.head = lodash.prototype.first;
12312 lodash.prototype.select = lodash.prototype.filter;
12313 lodash.prototype.tail = lodash.prototype.rest;
12318 /*--------------------------------------------------------------------------*/
12321 var _ = runInContext();
12323 // Some AMD build optimizers like r.js check for condition patterns like the following:
12324 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
12325 // Expose lodash to the global object when an AMD loader is present to avoid
12326 // errors in cases where lodash is loaded by a script tag and not intended
12327 // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
12331 // Define as an anonymous module so, through path mapping, it can be
12332 // referenced as the "underscore" module.
12333 define(function() {
12337 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
12338 else if (freeExports && freeModule) {
12339 // Export for Node.js or RingoJS.
12340 if (moduleExports) {
12341 (freeModule.exports = _)._ = _;
12343 // Export for Rhino with CommonJS support.
12349 // Export for a browser or Rhino.