From f42f46c7d695416ebd4ce071724d6004b2e86a7e Mon Sep 17 00:00:00 2001 From: jdalton Date: Mon, 16 Feb 2015 23:39:23 -0800 Subject: [PATCH] Adjust doc examples for smaller screens. [ci skip] --- lodash.src.js | 501 +++++++++++++++++++++++++++++++------------------- 1 file changed, 314 insertions(+), 187 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 98c87ee33..454540d80 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -919,11 +919,15 @@ * var wrapped = _([1, 2, 3]); * * // returns an unwrapped value - * wrapped.reduce(function(sum, n) { return sum + n; }); + * wrapped.reduce(function(sum, n) { + * return sum + n; + * }); * // => 6 * * // returns a wrapped value - * var squares = wrapped.map(function(n) { return n * n; }); + * var squares = wrapped.map(function(n) { + * return n * n; + * }); * * _.isArray(squares); * // => false @@ -4250,7 +4254,7 @@ * @returns {Array} Returns the new array of filtered values. * @example * - * _.difference([1, 2, 3], [5, 2, 10]); + * _.difference([1, 2, 3], [4, 2]); * // => [1, 3] */ function difference() { @@ -4363,7 +4367,9 @@ * @returns {Array} Returns the slice of `array`. * @example * - * _.dropRightWhile([1, 2, 3], function(n) { return n > 1; }); + * _.dropRightWhile([1, 2, 3], function(n) { + * return n > 1; + * }); * // => [1] * * var users = [ @@ -4420,7 +4426,9 @@ * @returns {Array} Returns the slice of `array`. * @example * - * _.dropWhile([1, 2, 3], function(n) { return n < 3; }); + * _.dropWhile([1, 2, 3], function(n) { + * return n < 3; + * }); * // => [3] * * var users = [ @@ -4510,7 +4518,9 @@ * { 'user': 'pebbles', 'active': true } * ]; * - * _.findIndex(users, function(chr) { return chr.user == 'barney'; }); + * _.findIndex(users, function(chr) { + * return chr.user == 'barney'; + * }); * // => 0 * * // using the `_.matches` callback shorthand @@ -4569,7 +4579,9 @@ * { 'user': 'pebbles', 'active': false } * ]; * - * _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; }); + * _.findLastIndex(users, function(chr) { + * return chr.user == 'pebbles'; + * }); * // => 2 * * // using the `_.matches` callback shorthand @@ -4629,11 +4641,11 @@ * @returns {Array} Returns the new flattened array. * @example * - * _.flatten([1, [2], [3, [[4]]]]); - * // => [1, 2, 3, [[4]]]; + * _.flatten([1, [2, 3, [4]]]); + * // => [1, 2, 3, [4]]; * * // using `isDeep` - * _.flatten([1, [2], [3, [[4]]]], true); + * _.flatten([1, [2, 3, [4]]], true); * // => [1, 2, 3, 4]; */ function flatten(array, isDeep, guard) { @@ -4654,7 +4666,7 @@ * @returns {Array} Returns the new flattened array. * @example * - * _.flattenDeep([1, [2], [3, [[4]]]]); + * _.flattenDeep([1, [2, 3, [4]]]); * // => [1, 2, 3, 4]; */ function flattenDeep(array) { @@ -4683,15 +4695,15 @@ * @returns {number} Returns the index of the matched value, else `-1`. * @example * - * _.indexOf([1, 2, 3, 1, 2, 3], 2); - * // => 1 + * _.indexOf([1, 2, 1, 2], 2); + * // => 2 * * // using `fromIndex` - * _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); - * // => 4 + * _.indexOf([1, 2, 1, 2], 2, 2); + * // => 3 * * // performing a binary search - * _.indexOf([4, 4, 5, 5, 6, 6], 5, true); + * _.indexOf([1, 1, 2, 2], 2, true); * // => 2 */ function indexOf(array, value, fromIndex) { @@ -4742,9 +4754,8 @@ * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of shared values. * @example - * - * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); - * // => [1, 2] + * _.intersection([1, 2], [4, 2], [2, 1]); + * // => [2] */ function intersection() { var args = [], @@ -4820,15 +4831,15 @@ * @returns {number} Returns the index of the matched value, else `-1`. * @example * - * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); - * // => 4 + * _.lastIndexOf([1, 2, 1, 2], 2); + * // => 3 * * // using `fromIndex` - * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); + * _.lastIndexOf([1, 2, 1, 2], 2, 2); * // => 1 * * // performing a binary search - * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); + * _.lastIndexOf([1, 1, 2, 2], 2, true); * // => 3 */ function lastIndexOf(array, value, fromIndex) { @@ -4874,6 +4885,7 @@ * @example * * var array = [1, 2, 3, 1, 2, 3]; + * * _.pull(array, 2, 3); * console.log(array); * // => [1, 1] @@ -4915,7 +4927,7 @@ * @example * * var array = [5, 10, 15, 20]; - * var evens = _.pullAt(array, [1, 3]); + * var evens = _.pullAt(array, 1, 3); * * console.log(array); * // => [5, 15] @@ -4956,7 +4968,9 @@ * @example * * var array = [1, 2, 3, 4]; - * var evens = _.remove(array, function(n) { return n % 2 == 0; }); + * var evens = _.remove(array, function(n) { + * return n % 2 == 0; + * }); * * console.log(array); * // => [1, 3] @@ -5058,7 +5072,7 @@ * _.sortedIndex([30, 50], 40); * // => 1 * - * _.sortedIndex([4, 4, 5, 5, 6, 6], 5); + * _.sortedIndex([4, 4, 5, 5], 5); * // => 2 * * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; @@ -5097,7 +5111,7 @@ * into `array`. * @example * - * _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5); + * _.sortedLastIndex([4, 4, 5, 5], 5); * // => 4 */ function sortedLastIndex(array, value, iteratee, thisArg) { @@ -5204,7 +5218,9 @@ * @returns {Array} Returns the slice of `array`. * @example * - * _.takeRightWhile([1, 2, 3], function(n) { return n > 1; }); + * _.takeRightWhile([1, 2, 3], function(n) { + * return n > 1; + * }); * // => [2, 3] * * var users = [ @@ -5261,7 +5277,9 @@ * @returns {Array} Returns the slice of `array`. * @example * - * _.takeWhile([1, 2, 3], function(n) { return n < 3; }); + * _.takeWhile([1, 2, 3], function(n) { + * return n < 3; + * }); * // => [1, 2] * * var users = [ @@ -5309,8 +5327,8 @@ * @returns {Array} Returns the new array of combined values. * @example * - * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); - * // => [1, 2, 3, 5, 4] + * _.union([1, 2], [4, 2], [2, 1]); + * // => [1, 2, 4] */ function union() { return baseUniq(baseFlatten(arguments, false, true)); @@ -5359,7 +5377,9 @@ * // => [1, 2] * * // using an iteratee function - * _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); + * _.uniq([1, 2.5, 1.5, 2], function(n) { + * return this.floor(n); + * }, Math); * // => [1, 2.5] * * // using the `_.property` callback shorthand @@ -5432,8 +5452,8 @@ * @returns {Array} Returns the new array of filtered values. * @example * - * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); - * // => [2, 3, 4] + * _.without([1, 2, 1, 3], 1, 2); + * // => [3] */ function without(array) { return baseDifference(array, baseSlice(arguments, 1)); @@ -5451,11 +5471,8 @@ * @returns {Array} Returns the new array of values. * @example * - * _.xor([1, 2, 3], [5, 2, 1, 4]); - * // => [3, 5, 4] - * - * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); - * // => [1, 4, 5] + * _.xor([1, 2], [4, 2]); + * // => [1, 4] */ function xor() { var index = -1, @@ -5554,7 +5571,9 @@ * * var youngest = _.chain(users) * .sortBy('age') - * .map(function(chr) { return chr.user + ' is ' + chr.age; }) + * .map(function(chr) { + * return chr.user + ' is ' + chr.age; + * }) * .first() * .value(); * // => 'pebbles is 1' @@ -5581,7 +5600,9 @@ * @example * * _([1, 2, 3]) - * .tap(function(array) { array.pop(); }) + * .tap(function(array) { + * array.pop(); + * }) * .reverse() * .value(); * // => [2, 1] @@ -5605,7 +5626,9 @@ * * _([1, 2, 3]) * .last() - * .thru(function(value) { return [value]; }) + * .thru(function(value) { + * return [value]; + * }) * .value(); * // => [3] */ @@ -5794,8 +5817,8 @@ * @returns {Array} Returns the new array of picked elements. * @example * - * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); - * // => ['a', 'c', 'e'] + * _.at(['a', 'b', 'c'], [0, 2]); + * // => ['a', 'c'] * * _.at(['fred', 'barney', 'pebbles'], 0, 2); * // => ['fred', 'pebbles'] @@ -5808,57 +5831,6 @@ return baseAt(collection, baseFlatten(arguments, false, false, 1)); } - /** - * Checks if `value` is in `collection` using `SameValueZero` for equality - * comparisons. If `fromIndex` is negative, it is used as the offset from - * the end of `collection`. - * - * **Note:** `SameValueZero` comparisons are like strict equality comparisons, - * e.g. `===`, except that `NaN` matches `NaN`. See the - * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) - * for more details. - * - * @static - * @memberOf _ - * @alias contains, include - * @category Collection - * @param {Array|Object|string} collection The collection to search. - * @param {*} target The value to search for. - * @param {number} [fromIndex=0] The index to search from. - * @returns {boolean} Returns `true` if a matching element is found, else `false`. - * @example - * - * _.includes([1, 2, 3], 1); - * // => true - * - * _.includes([1, 2, 3], 1, 2); - * // => false - * - * _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); - * // => true - * - * _.includes('pebbles', 'eb'); - * // => true - */ - function includes(collection, target, fromIndex) { - var length = collection ? collection.length : 0; - if (!isLength(length)) { - collection = values(collection); - length = collection.length; - } - if (!length) { - return false; - } - if (typeof fromIndex == 'number') { - fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); - } else { - fromIndex = 0; - } - return (typeof collection == 'string' || !isArray(collection) && isString(collection)) - ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1) - : (getIndexOf(collection, target, fromIndex) > -1); - } - /** * Creates an object composed of keys generated from the results of running * each element of `collection` through `iteratee`. The corresponding value @@ -5887,10 +5859,14 @@ * @returns {Object} Returns the composed aggregate object. * @example * - * _.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); }); + * _.countBy([4.3, 6.1, 6.4], function(n) { + * return Math.floor(n); + * }); * // => { '4': 1, '6': 2 } * - * _.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math); + * _.countBy([4.3, 6.1, 6.4], function(n) { + * return this.floor(n); + * }, Math); * // => { '4': 1, '6': 2 } * * _.countBy(['one', 'two', 'three'], 'length'); @@ -5983,8 +5959,10 @@ * @returns {Array} Returns the new filtered array. * @example * - * var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; }); - * // => [2, 4] + * _.filter([4, 5, 6], function(n) { + * return n % 2 == 0; + * }); + * // => [4, 6] * * var users = [ * { 'user': 'barney', 'age': 36, 'active': true }, @@ -6042,7 +6020,9 @@ * { 'user': 'pebbles', 'age': 1, 'active': true } * ]; * - * _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); + * _.result(_.find(users, function(chr) { + * return chr.age < 40; + * }), 'user'); * // => 'barney' * * // using the `_.matches` callback shorthand @@ -6080,7 +6060,9 @@ * @returns {*} Returns the matched element, else `undefined`. * @example * - * _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; }); + * _.findLast([1, 2, 3, 4], function(n) { + * return n % 2 == 1; + * }); * // => 3 */ function findLast(collection, predicate, thisArg) { @@ -6141,10 +6123,14 @@ * @returns {Array|Object|string} Returns `collection`. * @example * - * _([1, 2, 3]).forEach(function(n) { console.log(n); }).value(); + * _([1, 2]).forEach(function(n) { + * console.log(n); + * }).value(); * // => logs each value from left to right and returns the array * - * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); }); + * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) { + * console.log(n, key); + * }); * // => logs each value-key pair and returns the object (iteration order is not guaranteed) */ function forEach(collection, iteratee, thisArg) { @@ -6167,7 +6153,9 @@ * @returns {Array|Object|string} Returns `collection`. * @example * - * _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(','); + * _([1, 2]).forEachRight(function(n) { + * console.log(n); + * }).join(','); * // => logs each value from right to left and returns the array */ function forEachRight(collection, iteratee, thisArg) { @@ -6204,10 +6192,14 @@ * @returns {Object} Returns the composed aggregate object. * @example * - * _.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); }); + * _.groupBy([4.2, 6.1, 6.4], function(n) { + * return Math.floor(n); + * }); * // => { '4': [4.2], '6': [6.1, 6.4] } * - * _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); + * _.groupBy([4.2, 6.1, 6.4], function(n) { + * return this.floor(n); + * }, Math); * // => { '4': [4.2], '6': [6.1, 6.4] } * * // using the `_.property` callback shorthand @@ -6222,6 +6214,57 @@ } }); + /** + * Checks if `value` is in `collection` using `SameValueZero` for equality + * comparisons. If `fromIndex` is negative, it is used as the offset from + * the end of `collection`. + * + * **Note:** `SameValueZero` comparisons are like strict equality comparisons, + * e.g. `===`, except that `NaN` matches `NaN`. See the + * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for more details. + * + * @static + * @memberOf _ + * @alias contains, include + * @category Collection + * @param {Array|Object|string} collection The collection to search. + * @param {*} target The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @returns {boolean} Returns `true` if a matching element is found, else `false`. + * @example + * + * _.includes([1, 2, 3], 1); + * // => true + * + * _.includes([1, 2, 3], 1, 2); + * // => false + * + * _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); + * // => true + * + * _.includes('pebbles', 'eb'); + * // => true + */ + function includes(collection, target, fromIndex) { + var length = collection ? collection.length : 0; + if (!isLength(length)) { + collection = values(collection); + length = collection.length; + } + if (!length) { + return false; + } + if (typeof fromIndex == 'number') { + fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); + } else { + fromIndex = 0; + } + return (typeof collection == 'string' || !isArray(collection) && isString(collection)) + ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1) + : (getIndexOf(collection, target, fromIndex) > -1); + } + /** * Creates an object composed of keys generated from the results of running * each element of `collection` through `iteratee`. The corresponding value @@ -6258,10 +6301,14 @@ * _.indexBy(keyData, 'dir'); * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); }); + * _.indexBy(keyData, function(object) { + * return String.fromCharCode(object.code); + * }); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * - * _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String); + * _.indexBy(keyData, function(object) { + * return this.fromCharCode(object.code); + * }, String); * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } */ var indexBy = createAggregator(function(result, value, key) { @@ -6331,11 +6378,15 @@ * @returns {Array} Returns the new mapped array. * @example * - * _.map([1, 2, 3], function(n) { return n * 3; }); - * // => [3, 6, 9] + * function timesThree(n) { + * return n * 3; + * } * - * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; }); - * // => [3, 6, 9] (iteration order is not guaranteed) + * _.map([1, 2], timesThree); + * // => [3, 6] + * + * _.map({ 'a': 1, 'b': 2 }, timesThree); + * // => [3, 6] (iteration order is not guaranteed) * * var users = [ * { 'user': 'barney' }, @@ -6390,7 +6441,9 @@ * { 'user': 'fred', 'age': 40 } * ]; * - * _.max(users, function(chr) { return chr.age; }); + * _.max(users, function(chr) { + * return chr.age; + * }); * // => { 'user': 'fred', 'age': 40 }; * * // using the `_.property` callback shorthand @@ -6437,7 +6490,9 @@ * { 'user': 'fred', 'age': 40 } * ]; * - * _.min(users, function(chr) { return chr.age; }); + * _.min(users, function(chr) { + * return chr.age; + * }); * // => { 'user': 'barney', 'age': 36 }; * * // using the `_.property` callback shorthand @@ -6473,10 +6528,14 @@ * @returns {Array} Returns the array of grouped elements. * @example * - * _.partition([1, 2, 3], function(n) { return n % 2; }); + * _.partition([1, 2, 3], function(n) { + * return n % 2; + * }); * // => [[1, 3], [2]] * - * _.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math); + * _.partition([1.2, 2.3, 3.4], function(n) { + * return this.floor(n) % 2; + * }, Math); * // => [[1, 3], [2]] * * var users = [ @@ -6485,7 +6544,9 @@ * { 'user': 'pebbles', 'age': 1, 'active': false } * ]; * - * var mapper = function(array) { return _.pluck(array, 'user'); }; + * var mapper = function(array) { + * return _.pluck(array, 'user'); + * }; * * // using the `_.matches` callback shorthand * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper); @@ -6555,14 +6616,16 @@ * @returns {*} Returns the accumulated value. * @example * - * var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; }); - * // => 6 + * _.reduce([1, 2], function(sum, n) { + * return sum + n; + * }); + * // => 3 * - * var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { + * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) { * result[key] = n * 3; * return result; * }, {}); - * // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed) + * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed) */ function reduce(collection, iteratee, accumulator, thisArg) { var func = isArray(collection) ? arrayReduce : baseReduce; @@ -6585,7 +6648,10 @@ * @example * * var array = [[0, 1], [2, 3], [4, 5]]; - * _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []); + * + * _.reduceRight(array, function(flattened, other) { + * return flattened.concat(other); + * }, []); * // => [4, 5, 2, 3, 0, 1] */ function reduceRight(collection, iteratee, accumulator, thisArg) { @@ -6618,7 +6684,9 @@ * @returns {Array} Returns the new filtered array. * @example * - * var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; }); + * _.reject([1, 2, 3, 4], function(n) { + * return n % 2 == 0; + * }); * // => [1, 3] * * var users = [ @@ -6718,12 +6786,12 @@ * @returns {number} Returns the size of `collection`. * @example * - * _.size([1, 2]); - * // => 2 - * - * _.size({ 'one': 1, 'two': 2, 'three': 3 }); + * _.size([1, 2, 3]); * // => 3 * + * _.size({ 'a': 1, 'b': 2 }); + * // => 2 + * * _.size('pebbles'); * // => 7 */ @@ -6818,10 +6886,14 @@ * @returns {Array} Returns the new sorted array. * @example * - * _.sortBy([1, 2, 3], function(n) { return Math.sin(n); }); + * _.sortBy([1, 2, 3], function(n) { + * return Math.sin(n); + * }); * // => [3, 1, 2] * - * _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math); + * _.sortBy([1, 2, 3], function(n) { + * return this.sin(n); + * }, Math); * // => [3, 1, 2] * * var users = [ @@ -6938,7 +7010,9 @@ * @category Date * @example * - * _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); + * _.defer(function(stamp) { + * console.log(_.now() - stamp); + * }, _.now()); * // => logs the number of milliseconds it took for the deferred function to be invoked */ var now = nativeNow || function() { @@ -7114,7 +7188,9 @@ * * var view = { * 'label': 'docs', - * 'onClick': function() { console.log('clicked ' + this.label); } + * 'onClick': function() { + * console.log('clicked ' + this.label); + * } * }; * * _.bindAll(view); @@ -7467,7 +7543,9 @@ * @returns {number} Returns the timer id. * @example * - * _.defer(function(text) { console.log(text); }, 'deferred'); + * _.defer(function(text) { + * console.log(text); + * }, 'deferred'); * // logs 'deferred' after one or more milliseconds */ function defer(func) { @@ -7487,7 +7565,9 @@ * @returns {number} Returns the timer id. * @example * - * _.delay(function(text) { console.log(text); }, 1000, 'later'); + * _.delay(function(text) { + * console.log(text); + * }, 1000, 'later'); * // => logs 'later' after one second */ function delay(func, wait) { @@ -7805,7 +7885,9 @@ * // => ['a', 'b', 'c'] * * var map = _.rearg(_.map, [1, 0]); - * map(function(n) { return n * 3; }, [1, 2, 3]); + * map(function(n) { + * return n * 3; + * }, [1, 2, 3]); * // => [3, 6, 9] */ function rearg(func) { @@ -7884,8 +7966,9 @@ * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); * * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes - * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }) - * jQuery('.interactive').on('click', throttled); + * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, { + * 'trailing': false + * })); * * // cancel a trailing throttled call * jQuery(window).on('popstate', throttled.cancel); @@ -7975,15 +8058,17 @@ * // => false * * // using a customizer callback - * var body = _.clone(document.body, function(value) { - * return _.isElement(value) ? value.cloneNode(false) : undefined; + * var el = _.clone(document.body, function(value) { + * if (_.isElement(value)) { + * return value.cloneNode(false); + * } * }); * - * body === document.body + * el === document.body * // => false - * body.nodeName + * el.nodeName * // => BODY - * body.childNodes.length; + * el.childNodes.length; * // => 0 */ function clone(value, isDeep, customizer, thisArg) { @@ -8030,14 +8115,16 @@ * * // using a customizer callback * var el = _.cloneDeep(document.body, function(value) { - * return _.isElement(value) ? value.cloneNode(true) : undefined; + * if (_.isElement(value)) { + * return value.cloneNode(true); + * } * }); * - * body === document.body + * el === document.body * // => false - * body.nodeName + * el.nodeName * // => BODY - * body.childNodes.length; + * el.childNodes.length; * // => 20 */ function cloneDeep(value, customizer, thisArg) { @@ -8055,7 +8142,7 @@ * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. * @example * - * (function() { return _.isArguments(arguments); })(); + * _.isArguments(function() { return arguments; }()); * // => true * * _.isArguments([1, 2, 3]); @@ -8087,7 +8174,7 @@ * _.isArray([1, 2, 3]); * // => true * - * (function() { return _.isArray(arguments); })(); + * _.isArray(function() { return arguments; }()); * // => false */ var isArray = nativeIsArray || function(value) { @@ -8237,7 +8324,9 @@ * var other = ['hi', 'goodbye']; * * _.isEqual(array, other, function(value, other) { - * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined; + * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) { + * return true; + * } * }); * // => true */ @@ -8655,7 +8744,9 @@ * @returns {Array} Returns the converted array. * @example * - * (function() { return _.toArray(arguments).slice(1); })(1, 2, 3); + * (function() { + * return _.toArray(arguments).slice(1); + * }(1, 2, 3)); * // => [2, 3] */ function toArray(value) { @@ -8754,7 +8845,9 @@ * Shape.call(this); * } * - * Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle }); + * Circle.prototype = _.create(Shape.prototype, { + * 'constructor': Circle + * }); * * var circle = new Circle; * circle instanceof Circle; @@ -8827,7 +8920,9 @@ * 'pebbles': { 'age': 1, 'active': true } * }; * - * _.findKey(users, function(chr) { return chr.age < 40; }); + * _.findKey(users, function(chr) { + * return chr.age < 40; + * }); * // => 'barney' (iteration order is not guaranteed) * * // using the `_.matches` callback shorthand @@ -8878,7 +8973,9 @@ * 'pebbles': { 'age': 1, 'active': true } * }; * - * _.findLastKey(users, function(chr) { return chr.age < 40; }); + * _.findLastKey(users, function(chr) { + * return chr.age < 40; + * }); * // => returns `pebbles` assuming `_.findKey` returns `barney` * * // using the `_.matches` callback shorthand @@ -8977,10 +9074,17 @@ * @returns {Object} Returns `object`. * @example * - * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) { + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwn(new Foo, function(value, key) { * console.log(key); * }); - * // => logs '0', '1', and 'length' (iteration order is not guaranteed) + * // => logs 'a' and 'b' (iteration order is not guaranteed) */ function forOwn(object, iteratee, thisArg) { if (typeof iteratee != 'function' || typeof thisArg != 'undefined') { @@ -9002,10 +9106,17 @@ * @returns {Object} Returns `object`. * @example * - * _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) { + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwnRight(new Foo, function(value, key) { * console.log(key); * }); - * // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length' + * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b' */ function forOwnRight(object, iteratee, thisArg) { iteratee = bindCallback(iteratee, thisArg, 3); @@ -9025,7 +9136,7 @@ * @example * * _.functions(_); - * // => ['all', 'any', 'bind', ...] + * // => ['after', 'ary', 'assign', ...] */ function functions(object) { return baseFunctions(object, keysIn(object)); @@ -9043,7 +9154,9 @@ * @returns {boolean} Returns `true` if `key` is a direct property, else `false`. * @example * - * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); + * var object = { 'a': 1, 'b': 2, 'c': 3 }; + * + * _.has(object, 'b'); * // => true */ function has(object, key) { @@ -9064,16 +9177,14 @@ * @returns {Object} Returns the new inverted object. * @example * - * _.invert({ 'first': 'fred', 'second': 'barney' }); - * // => { 'fred': 'first', 'barney': 'second' } + * var object = { 'a': 1, 'b': 2, 'c': 1 }; * - * // without `multiValue` - * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }); - * // => { 'fred': 'third', 'barney': 'second' } + * _.invert(object); + * // => { '1': 'c', '2': 'b' } * * // with `multiValue` - * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true); - * // => { 'fred': ['first', 'third'], 'barney': ['second'] } + * _.invert(object, true); + * // => { '1': ['a', 'c'], '2': ['b'] } */ function invert(object, multiValue, guard) { if (guard && isIterateeCall(object, multiValue, guard)) { @@ -9248,8 +9359,10 @@ * @returns {Object} Returns the new mapped object. * @example * - * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(n) { return n * 3; }); - * // => { 'a': 3, 'b': 6, 'c': 9 } + * _.mapValues({ 'a': 1, 'b': 2 }, function(n) { + * return n * 3; + * }); + * // => { 'a': 3, 'b': 6 } * * var users = { * 'fred': { 'user': 'fred', 'age': 40 }, @@ -9312,7 +9425,9 @@ * }; * * _.merge(object, other, function(a, b) { - * return _.isArray(a) ? a.concat(b) : undefined; + * if (_.isArray(a)) { + * return a.concat(b); + * } * }); * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] } */ @@ -9478,18 +9593,16 @@ * @returns {*} Returns the accumulated value. * @example * - * var squares = _.transform([1, 2, 3, 4, 5, 6], function(result, n) { - * n *= n; - * if (n % 2) { - * return result.push(n) < 3; - * } + * _.transform([2, 3, 4], function(result, n) { + * result.push(n *= n); + * return n % 2 == 0; * }); - * // => [1, 9, 25] + * // => [4, 9] * - * var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { + * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) { * result[key] = n * 3; * }); - * // => { 'a': 3, 'b': 6, 'c': 9 } + * // => { 'a': 3, 'b': 6 } */ function transform(object, iteratee, accumulator, thisArg) { var isArr = isArray(object) || isTypedArray(object); @@ -9832,7 +9945,7 @@ } /** - * Converts `string` to kebab case (a.k.a. spinal case). + * Converts `string` to kebab case. * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for * more details. * @@ -10431,13 +10544,21 @@ * _.trunc('hi-diddly-ho there, neighborino', 24); * // => 'hi-diddly-ho there, n...' * - * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' }); + * _.trunc('hi-diddly-ho there, neighborino', { + * 'length': 24, + * 'separator': ' ' + * }); * // => 'hi-diddly-ho there,...' * - * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ }); + * _.trunc('hi-diddly-ho there, neighborino', { + * 'length': 24, + * 'separator': /,? +/ + * }); * //=> 'hi-diddly-ho there...' * - * _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' }); + * _.trunc('hi-diddly-ho there, neighborino', { + * 'omission': ' [...]' + * }); * // => 'hi-diddly-ho there, neig [...]' */ function trunc(string, options, guard) { @@ -10609,7 +10730,9 @@ * return callback(func, thisArg); * } * return function(object) { - * return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3]; + * return match[2] == 'gt' + * ? object[match[1]] > match[3] + * : object[match[1]] < match[3]; * }; * }); * @@ -10884,11 +11007,11 @@ * @returns {Function} Returns the new function. * @example * - * var object = { 'user': 'fred', 'age': 40, 'status': 'busy' }; - * _.map(['user', 'status'], _.propertyOf(object)); - * // => ['fred', 'busy'] - * * var object = { 'a': 3, 'b': 1, 'c': 2 }; + * + * _.map(['a', 'c'], _.propertyOf(object)); + * // => [3, 2] + * * _.sortBy(['a', 'b', 'c'], _.propertyOf(object)); * // => ['b', 'c', 'a'] */ @@ -10974,10 +11097,14 @@ * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false)); * // => [3, 6, 4] * - * _.times(3, function(n) { mage.castSpell(n); }); + * _.times(3, function(n) { + * mage.castSpell(n); + * }); * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively * - * _.times(3, function(n) { this.cast(n); }, mage); + * _.times(3, function(n) { + * this.cast(n); + * }, mage); * // => also invokes `mage.castSpell(n)` three times */ function times(n, iteratee, thisArg) {