diff --git a/dist/lodash.js b/dist/lodash.js index 5bf89cfae..59edf7e8d 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -1314,6 +1314,11 @@ (!b || (otherType != 'function' && otherType != 'object'))) { return false; } + // exit early for `null` and `undefined`, avoiding ES3's Function#call behavior + // http://es5.github.com/#x15.3.4.4 + if (a == null || b == null) { + return a === b; + } // compare [[Class]] names var className = toString.call(a), otherClass = toString.call(b); @@ -2032,18 +2037,25 @@ } /** - * Creates an object composed of keys returned from running each element of - * `collection` through a `callback`. The corresponding value of each key is - * the number of times the key was returned by `callback`. The `callback` is - * bound to `thisArg` and invoked with three arguments; (value, index|key, collection). - * The `callback` argument may also be the name of a property to count by (e.g. 'length'). + * Creates an object composed of keys returned from running each element of the + * `collection` through the given `callback`. The corresponding value of each key + * is the number of times the key was returned by the `callback`. The `callback` + * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to count by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example @@ -2073,12 +2085,21 @@ * `collection`. The `callback` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias all * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if all elements pass the callback check, * else `false`. @@ -2092,13 +2113,13 @@ * { 'name': 'larry', 'age': 50 } * ]; * - * // using callback "where" shorthand - * _.every(stooges, { 'age': 50 }); - * // => false - * - * // using callback "pluck" shorthand + * // using "_.pluck" callback shorthand * _.every(stooges, 'age'); * // => true + * + * // using "_.where" callback shorthand + * _.every(stooges, { 'age': 50 }); + * // => false */ function every(collection, callback, thisArg) { var result = true; @@ -2126,18 +2147,40 @@ * the `callback` returns truthy for. The `callback` is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias select * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that passed the callback check. * @example * * var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [2, 4, 6] + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.filter(food, 'organic'); + * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] + * + * // using "_.where" callback shorthand + * _.filter(food, { 'type': 'fruit' }); + * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] */ function filter(collection, callback, thisArg) { var result = []; @@ -2164,18 +2207,25 @@ } /** - * Examines each element in a `collection`, returning the first that the - * `callback` returns truthy for. The function returns as soon as it finds - * an acceptable element, and does not iterate over the entire `collection`. - * The `callback` is bound to `thisArg` and invoked with three arguments; - * (value, index|key, collection). + * Examines each element in a `collection`, returning the first that the `callback` + * returns truthy for. The `callback` is bound to `thisArg` and invoked with three + * arguments; (value, index|key, collection). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @alias detect * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the element that passed the callback check, * else `undefined`. @@ -2191,11 +2241,11 @@ * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } * ]; * - * // using callback "where" shorthand + * // using "_.where" callback shorthand * var veggie = _.find(food, { 'type': 'vegetable' }); * // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' } * - * // using callback "pluck" shorthand + * // using "_.pluck" callback shorthand * var healthy = _.find(food, 'organic'); * // => { 'name': 'banana', 'organic': true, 'type': 'fruit' } */ @@ -2251,18 +2301,25 @@ } /** - * Creates an object composed of keys returned from running each element of - * `collection` through a `callback`. The corresponding value of each key is an - * array of elements passed to `callback` that returned the key. The `callback` + * Creates an object composed of keys returned from running each element of the + * `collection` through the `callback`. The corresponding value of each key is + * an array of elements passed to `callback` that returned the key. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). - * The `callback` argument may also be the name of a property to group by (e.g. 'length'). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false` * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to group by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example @@ -2273,6 +2330,7 @@ * _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); * // => { '4': [4.2], '6': [6.1, 6.4] } * + * // using "_.pluck" callback shorthand * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ @@ -2324,15 +2382,24 @@ /** * Creates an array of values by running each element in the `collection` - * through a `callback`. The `callback` is bound to `thisArg` and invoked with + * through the `callback`. The `callback` is bound to `thisArg` and invoked with * three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias collect * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of the results of each `callback` execution. * @example @@ -2342,6 +2409,15 @@ * * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); * // => [3, 6, 9] (order is not guaranteed) + * + * var stooges = [ + * { 'name': 'moe', 'age': 40 }, + * { 'name': 'larry', 'age': 50 } + * ]; + * + * // using "_.pluck" callback shorthand + * _.map(stooges, 'name'); + * // => ['moe', 'larry'] */ function map(collection, callback, thisArg) { var index = -1, @@ -2367,11 +2443,20 @@ * criterion by which the value is ranked. The `callback` is bound to * `thisArg` and invoked with three arguments; (value, index, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the maximum value. * @example @@ -2386,6 +2471,10 @@ * * _.max(stooges, function(stooge) { return stooge.age; }); * // => { 'name': 'larry', 'age': 50 }; + * + * // using "_.pluck" callback shorthand + * _.max(stooges, 'age'); + * // => { 'name': 'larry', 'age': 50 }; */ function max(collection, callback, thisArg) { var computed = -Infinity, @@ -2423,11 +2512,20 @@ * criterion by which the value is ranked. The `callback` is bound to `thisArg` * and invoked with three arguments; (value, index, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the minimum value. * @example @@ -2442,6 +2540,10 @@ * * _.min(stooges, function(stooge) { return stooge.age; }); * // => { 'name': 'moe', 'age': 40 }; + * + * // using "_.pluck" callback shorthand + * _.min(stooges, 'age'); + * // => { 'name': 'moe', 'age': 40 }; */ function min(collection, callback, thisArg) { var computed = Infinity, @@ -2474,8 +2576,7 @@ } /** - * Retrieves the value of a specified property from all elements in - * the `collection`. + * Retrieves the value of a specified property from all elements in the `collection`. * * @static * @memberOf _ @@ -2583,11 +2684,20 @@ * The opposite of `_.filter`, this method returns the elements of a * `collection` that `callback` does **not** return truthy for. * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that did **not** pass the * callback check. @@ -2595,6 +2705,19 @@ * * var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [1, 3, 5] + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.reject(food, 'organic'); + * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] + * + * // using "_.where" callback shorthand + * _.reject(food, { 'type': 'fruit' }); + * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] */ function reject(collection, callback, thisArg) { callback = createCallback(callback, thisArg); @@ -2661,12 +2784,21 @@ * does not iterate over the entire `collection`. The `callback` is bound to * `thisArg` and invoked with three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias any * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if any element passes the callback check, * else `false`. @@ -2674,6 +2806,19 @@ * * _.some([null, 0, 'yes', false], Boolean); * // => true + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.some(food, 'organic'); + * // => true + * + * // using "_.where" callback shorthand + * _.some(food, { 'type': 'meat' }); + * // => false */ function some(collection, callback, thisArg) { var result; @@ -2698,16 +2843,24 @@ /** * Creates an array, stable sorted in ascending order by the results of - * running each element of `collection` through a `callback`. The `callback` + * running each element of `collection` through the `callback`. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). * The `callback` argument may also be the name of a property to sort by (e.g. 'length'). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to sort by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of sorted elements. * @example @@ -2718,6 +2871,7 @@ * _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); * // => [3, 1, 2] * + * // using "_.pluck" callback shorthand * _.sortBy(['banana', 'strawberry', 'apple'], 'length'); * // => ['apple', 'banana', 'strawberry'] */ @@ -2771,6 +2925,7 @@ * * @static * @memberOf _ + * @type Function * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Object} properties The object of property values to filter by. @@ -2785,9 +2940,7 @@ * _.where(stooges, { 'age': 40 }); * // => [{ 'name': 'moe', 'age': 40 }] */ - function where(collection, properties) { - return filter(collection, properties); - } + var where = filter; /*--------------------------------------------------------------------------*/ @@ -2857,13 +3010,21 @@ * the first elements the `callback` returns truthy for are returned. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias head, take * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n] The function called per element or - * the number of elements to return. + * @param {Function|Object|Number|String} [callback|n] The function called per + * element or the number of elements to return. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the first element(s) of `array`. * @example @@ -2878,6 +3039,25 @@ * return num < 3; * }); * // => [1, 2] + * + * var food = [ + * { 'name': 'banana', 'organic': true }, + * { 'name': 'beet', 'organic': false }, + * ]; + * + * // using "_.pluck" callback shorthand + * _.first(food, 'organic'); + * // => [{ 'name': 'banana', 'organic': true }] + * + * var food = [ + * { 'name': 'apple', 'type': 'fruit' }, + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.first(food, { 'type': 'fruit' }); + * // => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }] */ function first(array, callback, thisArg) { if (array) { @@ -2985,12 +3165,20 @@ * from the result. The `callback` is bound to `thisArg` and invoked with three * arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n=1] The function called per element or - * the number of elements to exclude. + * @param {Function|Object|Number|String} [callback|n=1] The function called per + * element or the number of elements to exclude. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a slice of `array`. * @example @@ -3005,6 +3193,25 @@ * return num > 1; * }); * // => [1] + * + * var food = [ + * { 'name': 'beet', 'organic': false }, + * { 'name': 'carrot', 'organic': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.initial(food, 'organic'); + * // => [{ 'name': 'beet', 'organic': false }] + * + * var food = [ + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' }, + * { 'name': 'carrot', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.initial(food, { 'type': 'vegetable' }); + * // => [{ 'name': 'banana', 'type': 'fruit' }] */ function initial(array, callback, thisArg) { if (!array) { @@ -3081,12 +3288,21 @@ * the last elements the `callback` returns truthy for are returned. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n] The function called per element or - * the number of elements to return. + * @param {Function|Object|Number|String} [callback|n] The function called per + * element or the number of elements to return. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the last element(s) of `array`. * @example @@ -3101,6 +3317,25 @@ * return num > 1; * }); * // => [2, 3] + * + * var food = [ + * { 'name': 'beet', 'organic': false }, + * { 'name': 'carrot', 'organic': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.last(food, 'organic'); + * // => [{ 'name': 'carrot', 'organic': true }] + * + * var food = [ + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' }, + * { 'name': 'carrot', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.last(food, { 'type': 'vegetable' }); + * // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }] */ function last(array, callback, thisArg) { if (array) { @@ -3245,13 +3480,21 @@ * truthy for are excluded from the result. The `callback` is bound to `thisArg` * and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias drop, tail * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n=1] The function called per element or - * the number of elements to exclude. + * @param {Function|Object|Number|String} [callback|n=1] The function called per + * element or the number of elements to exclude. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a slice of `array`. * @example @@ -3266,6 +3509,25 @@ * return num < 3; * }); * // => [3] + * + * var food = [ + * { 'name': 'banana', 'organic': true }, + * { 'name': 'beet', 'organic': false }, + * ]; + * + * // using "_.pluck" callback shorthand + * _.rest(food, 'organic'); + * // => [{ 'name': 'beet', 'organic': false }] + * + * var food = [ + * { 'name': 'apple', 'type': 'fruit' }, + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.rest(food, { 'type': 'fruit' }); + * // => [{ 'name': 'beet', 'type': 'vegetable' }] */ function rest(array, callback, thisArg) { if (typeof callback == 'function') { @@ -3288,16 +3550,23 @@ * should be inserted into `array` in order to maintain the sort order of the * sorted `array`. If `callback` is passed, it will be executed for `value` and * each element in `array` to compute their sort ranking. The `callback` is - * bound to `thisArg` and invoked with one argument; (value). The `callback` - * argument may also be the name of a property to order by. + * bound to `thisArg` and invoked with one argument; (value). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to iterate over. * @param {Mixed} value The value to evaluate. - * @param {Function|String} [callback=identity|property] The function called - * per iteration or property name to order by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Number} Returns the index at which the value should be inserted * into `array`. @@ -3306,6 +3575,7 @@ * _.sortedIndex([20, 30, 50], 40); * // => 2 * + * // using "_.pluck" callback shorthand * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * // => 2 * @@ -3366,13 +3636,22 @@ * element of `array` is passed through a callback` before uniqueness is computed. * The `callback` is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias unique * @category Arrays * @param {Array} array The array to process. * @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a duplicate-value-free array. * @example @@ -3388,6 +3667,10 @@ * * _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); * // => [1, 2, 3] + * + * // using "_.pluck" callback shorthand + * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { var index = -1, diff --git a/dist/lodash.min.js b/dist/lodash.min.js index c4336f9a5..519f2c761 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -4,36 +4,36 @@ * Build: `lodash strict modern -o ./dist/lodash.js` * Underscore.js 1.4.4 underscorejs.org/LICENSE */ -;(function(n,t){"use strict";function r(n){if(!n||typeof n!="object")return W;var t=n.valueOf,r=typeof t=="function"&&(r=_t(t))&&_t(r);if(r)n=n==r||_t(n)==r&&!h(n);else{var e=W;!n||typeof n!="object"||h(n)?n=e:(t=n.constructor,!w(t)||t instanceof t?(Yt(n,function(n,t){e=t}),n=e===W||bt.call(n,e)):n=e)}return n}function e(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof e?(this.__wrapped__=n,void 0):new e(n)}function u(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||et);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(nr?0:r);++er?kt(0,u+r):r)||0,typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):P(n,t,r)):Xt(n,function(n){return++eu&&(u=f)}}else t=!t&&A(n)?o:a(t,r),Xt(n,function(n,r,o){r=t(n,r,o),r>e&&(e=r,u=n)});return u}function D(n,t){return $(n,t+"")}function T(n,t,r,e){var u=3>arguments.length;if(t=a(t,e,4),nr(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof u!="number")var i=tr(n),u=i.length;return t=a(t,e,4),R(n,function(e,f,a){f=i?i[--u]:--u,r=o?(o=W,n[f]):t(r,n[f],f,a)}),r}function I(n,t,r){var e;if(t=a(t,r),nr(n)){r=-1;for(var u=n.length;++rr?kt(0,u+r):r||0)-1;else if(r)return e=K(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])P(f,p))&&((r||c)&&f.push(p),i.push(e))}return i}function V(n,t){return Kt||At&&2/g,vt=/($^)/,gt=/[&<>"']/g,ht=/['\n\r\t\u2028\u2029\\]/g,yt=Math.ceil,mt=Z.concat,dt=Math.floor,_t=lt.test(_t=Object.getPrototypeOf)&&_t,bt=nt.hasOwnProperty,wt=Z.push,jt=nt.propertyIsEnumerable,xt=nt.toString,At=lt.test(At=v.bind)&&At,Ot=lt.test(Ot=Array.isArray)&&Ot,Et=n.isFinite,St=n.isNaN,qt=lt.test(qt=Object.keys)&&qt,kt=Math.max,Nt=Math.min,Rt=Math.random,$t="[object Arguments]",Ft="[object Array]",Dt="[object Boolean]",Tt="[object Date]",Bt="[object Number]",It="[object Object]",Mt="[object RegExp]",zt="[object String]",Pt=!!n.attachEvent,Ct=At&&!/\n|true/.test(At+Pt),Kt=At&&!Ct,Ut=qt&&(Pt||Ct),Vt={"[object Function]":W}; -Vt[$t]=Vt[Ft]=Vt[Dt]=Vt[Tt]=Vt[Bt]=Vt[It]=Vt[Mt]=Vt[zt]=L;var Gt={};Gt[Ft]=Array,Gt[Dt]=Boolean,Gt[Tt]=Date,Gt[It]=Object,Gt[Bt]=Number,Gt[Mt]=RegExp,Gt[zt]=String;var Ht={"boolean":W,"function":L,object:L,number:W,string:W,undefined:W},Jt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};e.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:st,variable:"",imports:{_:e}};var Lt={a:"p,w,g",l:"var a=0,b=typeof g=='number'?2:arguments.length;while(++a":">",'"':""","'":"'"},er=_(rr),ur=c(Lt),or=c(Lt,{h:"if(u[i]==null)"+Lt.h});w(/x/)&&(w=function(n){return n instanceof Function||"[object Function]"==xt.call(n)}),e.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},e.assign=ur,e.at=function(n){for(var t=-1,r=mt.apply(Z,v(arguments,1)),e=r.length,u=Array(e);++tP(c,l)){f&&c.push(l);for(var s=r;--s;)if(!(e[s]||(e[s]=u(t[s],0,100)))(l))continue n; -a.push(l)}}return a},e.invert=_,e.invoke=function(n,t){var r=v(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0);return R(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},e.keys=tr,e.map=$,e.max=F,e.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return bt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},e.merge=O,e.min=function(n,t,r){var e=1/0,u=e;if(!t&&nr(n)){r=-1;for(var i=n.length;++rP(o,r,1))&&(u[r]=n)}),u},e.once=function(n){var t,r;return function(){return t?r:(t=L,r=n.apply(this,arguments),n=Q,r)}},e.pairs=function(n){for(var t=-1,r=tr(n),e=r.length,u=Array(e);++tr?kt(0,e+r):Nt(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},e.mixin=H,e.noConflict=function(){return n._=ut,this},e.random=function(n,t){return n==Q&&t==Q&&(t=1),n=+n||0,t==Q&&(t=n,n=0),n+dt(Rt()*((+t||0)-n+1))},e.reduce=T,e.reduceRight=B,e.result=function(n,r){var e=n?n[r]:t;return w(e)?n[r]():e},e.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:tr(n).length -},e.some=I,e.sortedIndex=K,e.template=function(n,r,u){var o=e.templateSettings;n||(n=""),u=or({},u,o);var i,f=or({},u.imports,o.imports),o=tr(f),f=E(f),a=0,c=u.interpolate||vt,p="__p+='";n.replace(RegExp((u.escape||vt).source+"|"+c.source+"|"+(c===st?pt:vt).source+"|"+(u.evaluate||vt).source+"|$","g"),function(t,r,e,u,o,f){return e||(e=u),p+=n.slice(a,f).replace(ht,l),r&&(p+="'+__e("+r+")+'"),o&&(i=L,p+="';"+o+";__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t}),p+="';\n",c=u=u.variable,c||(u="obj",p="with("+u+"){"+p+"}"),p=(i?p.replace(it,""):p).replace(ft,"$1").replace(at,"$1;"),p="function("+u+"){"+(c?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(c?"":",__d="+u+"."+u+"||"+u)+";")+p+"return __p}"; -try{var s=Function(o,"return "+p).apply(t,f)}catch(v){throw v.source=p,v}return r?s(r):(s.source=p,s)},e.unescape=function(n){return n==Q?"":(n+"").replace(ot,g)},e.uniqueId=function(n){var t=++tt;return(n==Q?"":n+"")+t},e.all=q,e.any=I,e.detect=N,e.foldl=T,e.foldr=B,e.include=S,e.inject=T,Zt(e,function(n,t){e.prototype[t]||(e.prototype[t]=function(){var t=[this.__wrapped__];return wt.apply(t,arguments),n.apply(e,t)})}),e.first=M,e.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t=="function"){var o=u; -for(t=a(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,e==Q||r)return n[u-1];return v(n,kt(0,u-e))}},e.take=M,e.head=M,Zt(e,function(n,t){e.prototype[t]||(e.prototype[t]=function(t,r){var u=n(this.__wrapped__,t,r);return t==Q||r&&typeof t!="function"?u:new e(u)})}),e.VERSION="1.0.0-rc.3",e.prototype.toString=function(){return this.__wrapped__+""},e.prototype.value=J,e.prototype.valueOf=J,Xt(["join","pop","shift"],function(n){var t=Z[n];e.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)} -}),Xt(["push","reverse","sort","unshift"],function(n){var t=Z[n];e.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Xt(["concat","slice","splice"],function(n){var t=Z[n];e.prototype[n]=function(){return new e(t.apply(this.__wrapped__,arguments))}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=e,define(function(){return e})):X?typeof module=="object"&&module&&module.exports==X?(module.exports=e)._=e:X._=e:n._=e})(this); \ No newline at end of file +;(function(n,t){"use strict";function r(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,void 0):new r(n)}function e(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||Z);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1; +if(nr?0:r);++er?Ot(0,u+r):r)||0,typeof u=="number"?o=-1<(x(n)?n.indexOf(t,r):z(n,t,r)):Jt(n,function(n){return++eo&&(o=a)}}else t=!t&&x(n)?u:f(t,r),Jt(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function F(n,t){return R(n,t+"")}function D(n,t,r,e){var u=3>arguments.length;if(t=f(t,e,4),Wt(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof u!="number")var i=Xt(n),u=i.length;return t=f(t,e,4),N(n,function(e,f,a){f=i?i[--u]:--u,r=o?(o=!1,n[f]):t(r,n[f],f,a)}),r}function B(n,t,r){var e;if(t=f(t,r),Wt(n)){r=-1;for(var u=n.length;++rr?Ot(0,u+r):r||0)-1;else if(r)return e=C(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])z(a,p))&&((r||c)&&a.push(p),i.push(e))}return i}function U(n,t){return Mt||bt&&2/g,ct=/($^)/,lt=/[&<>"']/g,pt=/['\n\r\t\u2028\u2029\\]/g,st=Math.ceil,vt=Q.concat,gt=Math.floor,ht=it.test(ht=Object.getPrototypeOf)&&ht,yt=W.hasOwnProperty,mt=Q.push,_t=W.propertyIsEnumerable,dt=W.toString,bt=it.test(bt=s.bind)&&bt,wt=it.test(wt=Array.isArray)&&wt,jt=n.isFinite,xt=n.isNaN,At=it.test(At=Object.keys)&&At,Ot=Math.max,Et=Math.min,St=Math.random,qt="[object Arguments]",kt="[object Array]",Nt="[object Boolean]",Rt="[object Date]",$t="[object Number]",Ft="[object Object]",Dt="[object RegExp]",Tt="[object String]",Bt=!!n.attachEvent,It=bt&&!/\n|true/.test(bt+Bt),Mt=bt&&!It,zt=At&&(Bt||It),Pt={"[object Function]":!1}; +Pt[qt]=Pt[kt]=Pt[Nt]=Pt[Rt]=Pt[$t]=Pt[Ft]=Pt[Dt]=Pt[Tt]=!0;var Ct={};Ct[kt]=Array,Ct[Nt]=Boolean,Ct[Rt]=Date,Ct[Ft]=Object,Ct[$t]=Number,Ct[Dt]=RegExp,Ct[Tt]=String;var Kt={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},Ut={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};r.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:at,variable:"",imports:{_:r}};var Vt={a:"p,w,g",l:"var a=0,b=typeof g=='number'?2:arguments.length;while(++a":">",'"':""","'":"'"},Zt=_(Yt),nr=a(Vt),tr=a(Vt,{h:"if(u[i]==null)"+Vt.h});b(/x/)&&(b=function(n){return n instanceof Function||"[object Function]"==dt.call(n)});var rr=function(n){if(!n||typeof n!="object")return!1;var t=n.valueOf,r=typeof t=="function"&&(r=ht(t))&&ht(r);if(r)n=n==r||ht(n)==r&&!g(n);else{var e=!1;!n||typeof n!="object"||g(n)?n=e:(t=n.constructor,!b(t)||t instanceof t?(Lt(n,function(n,t){e=t}),n=!1===e||yt.call(n,e)):n=e) +}return n};r.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},r.assign=nr,r.at=function(n){for(var t=-1,r=vt.apply(Q,s(arguments,1)),e=r.length,u=Array(e);++tz(c,l)){f&&c.push(l);for(var s=r;--s;)if(!(u[s]||(u[s]=e(t[s],0,100)))(l))continue n;a.push(l)}}return a},r.invert=_,r.invoke=function(n,t){var r=s(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0); +return N(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},r.keys=Xt,r.map=R,r.max=$,r.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return yt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},r.merge=A,r.min=function(n,t,r){var e=1/0,o=e;if(!t&&Wt(n)){r=-1;for(var i=n.length;++rz(o,r,1))&&(u[r]=n)}),u},r.once=function(n){var t,r;return function(){return t?r:(t=!0,r=n.apply(this,arguments),n=null,r)}},r.pairs=function(n){for(var t=-1,r=Xt(n),e=r.length,u=Array(e);++tr?Ot(0,e+r):Et(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},r.mixin=G,r.noConflict=function(){return n._=nt,this},r.random=function(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+gt(St()*((+t||0)-n+1))},r.reduce=D,r.reduceRight=T,r.result=function(n,r){var e=n?n[r]:t;return b(e)?n[r]():e},r.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Xt(n).length},r.some=B,r.sortedIndex=C,r.template=function(n,e,u){var o=r.templateSettings; +n||(n=""),u=tr({},u,o);var i,f=tr({},u.imports,o.imports),o=Xt(f),f=O(f),a=0,l=u.interpolate||ct,p="__p+='";n.replace(RegExp((u.escape||ct).source+"|"+l.source+"|"+(l===at?ft:ct).source+"|"+(u.evaluate||ct).source+"|$","g"),function(t,r,e,u,o,f){return e||(e=u),p+=n.slice(a,f).replace(pt,c),r&&(p+="'+__e("+r+")+'"),o&&(i=!0,p+="';"+o+";__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t}),p+="';\n",l=u=u.variable,l||(u="obj",p="with("+u+"){"+p+"}"),p=(i?p.replace(rt,""):p).replace(et,"$1").replace(ut,"$1;"),p="function("+u+"){"+(l?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(l?"":",__d="+u+"."+u+"||"+u)+";")+p+"return __p}"; +try{var s=Function(o,"return "+p).apply(t,f)}catch(v){throw v.source=p,v}return e?s(e):(s.source=p,s)},r.unescape=function(n){return null==n?"":(n+"").replace(tt,v)},r.uniqueId=function(n){var t=++X;return(null==n?"":n+"")+t},r.all=S,r.any=B,r.detect=k,r.foldl=D,r.foldr=T,r.include=E,r.inject=D,Qt(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(){var t=[this.__wrapped__];return mt.apply(t,arguments),n.apply(r,t)})}),r.first=I,r.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t=="function"){var o=u; +for(t=f(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n[u-1];return s(n,Ot(0,u-e))}},r.take=I,r.head=I,Qt(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(t,e){var u=n(this.__wrapped__,t,e);return null==t||e&&typeof t!="function"?u:new r(u)})}),r.VERSION="1.0.0-rc.3",r.prototype.toString=function(){return this.__wrapped__+""},r.prototype.value=H,r.prototype.valueOf=H,Jt(["join","pop","shift"],function(n){var t=Q[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments) +}}),Jt(["push","reverse","sort","unshift"],function(n){var t=Q[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),Jt(["concat","slice","splice"],function(n){var t=Q[n];r.prototype[n]=function(){return new r(t.apply(this.__wrapped__,arguments))}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=r,define(function(){return r})):J?typeof module=="object"&&module&&module.exports==J?(module.exports=r)._=r:J._=r:n._=r})(this); \ No newline at end of file diff --git a/dist/lodash.underscore.js b/dist/lodash.underscore.js index dfbfa2e4d..84665541a 100644 --- a/dist/lodash.underscore.js +++ b/dist/lodash.underscore.js @@ -1127,6 +1127,9 @@ (!b || (otherType != 'function' && otherType != 'object'))) { return false; } + if (a == null || b == null) { + return a === b; + } var className = toString.call(a), otherClass = toString.call(b); @@ -1585,18 +1588,25 @@ } /** - * Creates an object composed of keys returned from running each element of - * `collection` through a `callback`. The corresponding value of each key is - * the number of times the key was returned by `callback`. The `callback` is - * bound to `thisArg` and invoked with three arguments; (value, index|key, collection). - * The `callback` argument may also be the name of a property to count by (e.g. 'length'). + * Creates an object composed of keys returned from running each element of the + * `collection` through the given `callback`. The corresponding value of each key + * is the number of times the key was returned by the `callback`. The `callback` + * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to count by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example @@ -1626,12 +1636,21 @@ * `collection`. The `callback` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias all * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if all elements pass the callback check, * else `false`. @@ -1645,13 +1664,13 @@ * { 'name': 'larry', 'age': 50 } * ]; * - * // using callback "where" shorthand - * _.every(stooges, { 'age': 50 }); - * // => false - * - * // using callback "pluck" shorthand + * // using "_.pluck" callback shorthand * _.every(stooges, 'age'); * // => true + * + * // using "_.where" callback shorthand + * _.every(stooges, { 'age': 50 }); + * // => false */ function every(collection, callback, thisArg) { var result = true; @@ -1679,18 +1698,40 @@ * the `callback` returns truthy for. The `callback` is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias select * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that passed the callback check. * @example * * var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [2, 4, 6] + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.filter(food, 'organic'); + * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] + * + * // using "_.where" callback shorthand + * _.filter(food, { 'type': 'fruit' }); + * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] */ function filter(collection, callback, thisArg) { var result = []; @@ -1717,18 +1758,25 @@ } /** - * Examines each element in a `collection`, returning the first that the - * `callback` returns truthy for. The function returns as soon as it finds - * an acceptable element, and does not iterate over the entire `collection`. - * The `callback` is bound to `thisArg` and invoked with three arguments; - * (value, index|key, collection). + * Examines each element in a `collection`, returning the first that the `callback` + * returns truthy for. The `callback` is bound to `thisArg` and invoked with three + * arguments; (value, index|key, collection). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @alias detect * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the element that passed the callback check, * else `undefined`. @@ -1744,11 +1792,11 @@ * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } * ]; * - * // using callback "where" shorthand + * // using "_.where" callback shorthand * var veggie = _.find(food, { 'type': 'vegetable' }); * // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' } * - * // using callback "pluck" shorthand + * // using "_.pluck" callback shorthand * var healthy = _.find(food, 'organic'); * // => { 'name': 'banana', 'organic': true, 'type': 'fruit' } */ @@ -1807,18 +1855,25 @@ } /** - * Creates an object composed of keys returned from running each element of - * `collection` through a `callback`. The corresponding value of each key is an - * array of elements passed to `callback` that returned the key. The `callback` + * Creates an object composed of keys returned from running each element of the + * `collection` through the `callback`. The corresponding value of each key is + * an array of elements passed to `callback` that returned the key. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). - * The `callback` argument may also be the name of a property to group by (e.g. 'length'). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false` * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to group by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example @@ -1829,6 +1884,7 @@ * _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); * // => { '4': [4.2], '6': [6.1, 6.4] } * + * // using "_.pluck" callback shorthand * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ @@ -1880,15 +1936,24 @@ /** * Creates an array of values by running each element in the `collection` - * through a `callback`. The `callback` is bound to `thisArg` and invoked with + * through the `callback`. The `callback` is bound to `thisArg` and invoked with * three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias collect * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of the results of each `callback` execution. * @example @@ -1898,6 +1963,15 @@ * * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); * // => [3, 6, 9] (order is not guaranteed) + * + * var stooges = [ + * { 'name': 'moe', 'age': 40 }, + * { 'name': 'larry', 'age': 50 } + * ]; + * + * // using "_.pluck" callback shorthand + * _.map(stooges, 'name'); + * // => ['moe', 'larry'] */ function map(collection, callback, thisArg) { var index = -1, @@ -1923,11 +1997,20 @@ * criterion by which the value is ranked. The `callback` is bound to * `thisArg` and invoked with three arguments; (value, index, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the maximum value. * @example @@ -1942,6 +2025,10 @@ * * _.max(stooges, function(stooge) { return stooge.age; }); * // => { 'name': 'larry', 'age': 50 }; + * + * // using "_.pluck" callback shorthand + * _.max(stooges, 'age'); + * // => { 'name': 'larry', 'age': 50 }; */ function max(collection, callback, thisArg) { var computed = -Infinity, @@ -1977,11 +2064,20 @@ * criterion by which the value is ranked. The `callback` is bound to `thisArg` * and invoked with three arguments; (value, index, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the minimum value. * @example @@ -1996,6 +2092,10 @@ * * _.min(stooges, function(stooge) { return stooge.age; }); * // => { 'name': 'moe', 'age': 40 }; + * + * // using "_.pluck" callback shorthand + * _.min(stooges, 'age'); + * // => { 'name': 'moe', 'age': 40 }; */ function min(collection, callback, thisArg) { var computed = Infinity, @@ -2026,8 +2126,7 @@ } /** - * Retrieves the value of a specified property from all elements in - * the `collection`. + * Retrieves the value of a specified property from all elements in the `collection`. * * @static * @memberOf _ @@ -2135,11 +2234,20 @@ * The opposite of `_.filter`, this method returns the elements of a * `collection` that `callback` does **not** return truthy for. * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that did **not** pass the * callback check. @@ -2147,6 +2255,19 @@ * * var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [1, 3, 5] + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.reject(food, 'organic'); + * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] + * + * // using "_.where" callback shorthand + * _.reject(food, { 'type': 'fruit' }); + * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] */ function reject(collection, callback, thisArg) { callback = createCallback(callback, thisArg); @@ -2213,12 +2334,21 @@ * does not iterate over the entire `collection`. The `callback` is bound to * `thisArg` and invoked with three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias any * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if any element passes the callback check, * else `false`. @@ -2226,6 +2356,19 @@ * * _.some([null, 0, 'yes', false], Boolean); * // => true + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.some(food, 'organic'); + * // => true + * + * // using "_.where" callback shorthand + * _.some(food, { 'type': 'meat' }); + * // => false */ function some(collection, callback, thisArg) { var result; @@ -2250,16 +2393,24 @@ /** * Creates an array, stable sorted in ascending order by the results of - * running each element of `collection` through a `callback`. The `callback` + * running each element of `collection` through the `callback`. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). * The `callback` argument may also be the name of a property to sort by (e.g. 'length'). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to sort by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of sorted elements. * @example @@ -2270,6 +2421,7 @@ * _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); * // => [3, 1, 2] * + * // using "_.pluck" callback shorthand * _.sortBy(['banana', 'strawberry', 'apple'], 'length'); * // => ['apple', 'banana', 'strawberry'] */ @@ -2323,6 +2475,7 @@ * * @static * @memberOf _ + * @type Function * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Object} properties The object of property values to filter by. @@ -2410,13 +2563,21 @@ * the first elements the `callback` returns truthy for are returned. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias head, take * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n] The function called per element or - * the number of elements to return. + * @param {Function|Object|Number|String} [callback|n] The function called per + * element or the number of elements to return. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the first element(s) of `array`. * @example @@ -2431,6 +2592,25 @@ * return num < 3; * }); * // => [1, 2] + * + * var food = [ + * { 'name': 'banana', 'organic': true }, + * { 'name': 'beet', 'organic': false }, + * ]; + * + * // using "_.pluck" callback shorthand + * _.first(food, 'organic'); + * // => [{ 'name': 'banana', 'organic': true }] + * + * var food = [ + * { 'name': 'apple', 'type': 'fruit' }, + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.first(food, { 'type': 'fruit' }); + * // => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }] */ function first(array, callback, thisArg) { if (array) { @@ -2538,12 +2718,20 @@ * from the result. The `callback` is bound to `thisArg` and invoked with three * arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n=1] The function called per element or - * the number of elements to exclude. + * @param {Function|Object|Number|String} [callback|n=1] The function called per + * element or the number of elements to exclude. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a slice of `array`. * @example @@ -2558,6 +2746,25 @@ * return num > 1; * }); * // => [1] + * + * var food = [ + * { 'name': 'beet', 'organic': false }, + * { 'name': 'carrot', 'organic': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.initial(food, 'organic'); + * // => [{ 'name': 'beet', 'organic': false }] + * + * var food = [ + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' }, + * { 'name': 'carrot', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.initial(food, { 'type': 'vegetable' }); + * // => [{ 'name': 'banana', 'type': 'fruit' }] */ function initial(array, callback, thisArg) { if (!array) { @@ -2622,12 +2829,21 @@ * the last elements the `callback` returns truthy for are returned. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n] The function called per element or - * the number of elements to return. + * @param {Function|Object|Number|String} [callback|n] The function called per + * element or the number of elements to return. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the last element(s) of `array`. * @example @@ -2642,6 +2858,25 @@ * return num > 1; * }); * // => [2, 3] + * + * var food = [ + * { 'name': 'beet', 'organic': false }, + * { 'name': 'carrot', 'organic': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.last(food, 'organic'); + * // => [{ 'name': 'carrot', 'organic': true }] + * + * var food = [ + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' }, + * { 'name': 'carrot', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.last(food, { 'type': 'vegetable' }); + * // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }] */ function last(array, callback, thisArg) { if (array) { @@ -2786,13 +3021,21 @@ * truthy for are excluded from the result. The `callback` is bound to `thisArg` * and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias drop, tail * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n=1] The function called per element or - * the number of elements to exclude. + * @param {Function|Object|Number|String} [callback|n=1] The function called per + * element or the number of elements to exclude. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a slice of `array`. * @example @@ -2807,6 +3050,25 @@ * return num < 3; * }); * // => [3] + * + * var food = [ + * { 'name': 'banana', 'organic': true }, + * { 'name': 'beet', 'organic': false }, + * ]; + * + * // using "_.pluck" callback shorthand + * _.rest(food, 'organic'); + * // => [{ 'name': 'beet', 'organic': false }] + * + * var food = [ + * { 'name': 'apple', 'type': 'fruit' }, + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.rest(food, { 'type': 'fruit' }); + * // => [{ 'name': 'beet', 'type': 'vegetable' }] */ function rest(array, callback, thisArg) { if (typeof callback == 'function') { @@ -2829,16 +3091,23 @@ * should be inserted into `array` in order to maintain the sort order of the * sorted `array`. If `callback` is passed, it will be executed for `value` and * each element in `array` to compute their sort ranking. The `callback` is - * bound to `thisArg` and invoked with one argument; (value). The `callback` - * argument may also be the name of a property to order by. + * bound to `thisArg` and invoked with one argument; (value). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to iterate over. * @param {Mixed} value The value to evaluate. - * @param {Function|String} [callback=identity|property] The function called - * per iteration or property name to order by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Number} Returns the index at which the value should be inserted * into `array`. @@ -2847,6 +3116,7 @@ * _.sortedIndex([20, 30, 50], 40); * // => 2 * + * // using "_.pluck" callback shorthand * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * // => 2 * @@ -2907,13 +3177,22 @@ * element of `array` is passed through a callback` before uniqueness is computed. * The `callback` is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias unique * @category Arrays * @param {Array} array The array to process. * @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a duplicate-value-free array. * @example @@ -2929,6 +3208,10 @@ * * _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); * // => [1, 2, 3] + * + * // using "_.pluck" callback shorthand + * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { var index = -1, diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 059e6f140..4d543054c 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -8,14 +8,15 @@ }return rr?0:r);++eo&&(o=f)}}else t=a(t,r),e(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n) -});return o}function q(n,t){return R(n,t+"")}function B(n,t,r,u){var o=3>arguments.length;if(t=a(t,u,4),Bt(n)){var i=-1,f=n.length;for(o&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var i=Dt(n),u=i.length;return t=a(t,e,4),F(n,function(e,a,f){a=i?i[--u]:--u,r=o?(o=L,n[a]):t(r,n[a],a,f)}),r}function M(n,t,r){var u;if(t=a(t,r),Bt(n)){r=-1;for(var o=n.length;++rr?mt(0,u+r):r||0)-1;else if(r)return e=U(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])C(f,c))&&(r&&f.push(c),i.push(e))}return i}function W(n,t){return kt||vt&&2"']/g,it=/['\n\r\t\u2028\u2029\\]/g,at=Math.ceil,ft=Y.concat,ct=Math.floor,lt=X.hasOwnProperty,pt=Y.push,st=X.toString,vt=et.test(vt=p.bind)&&vt,ht=et.test(ht=Array.isArray)&&ht,gt=n.isFinite,yt=n.isNaN,_t=et.test(_t=Object.keys)&&_t,mt=Math.max,dt=Math.min,bt=Math.random,jt="[object Arguments]",wt="[object Array]",xt="[object Boolean]",At="[object Date]",Et="[object Number]",Ot="[object Object]",St="[object RegExp]",Nt="[object String]",X=!!n.attachEvent,X=vt&&!/\n|true/.test(vt+X),kt=vt&&!X,Ft=(Ft={0:1,length:1},Y.splice.call(Ft,0,1),Ft[0]),Rt=arguments.constructor==Object,Tt={"boolean":L,"function":J,object:J,number:L,string:L,undefined:L},qt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"}; +return J}function b(n,t,e,u){if(n===t)return 0!==n||1/n==1/t;var o=typeof n,i=typeof t;if(n===n&&(!n||"function"!=o&&"object"!=o)&&(!t||"function"!=i&&"object"!=i))return L;if(n==K||t==K)return n===t;if(i=st.call(n),o=st.call(t),i!=o)return L;switch(i){case xt:case At:return+n==+t;case Et:return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case St:case Nt:return n==t+""}if(o=i==wt,!o){if(n.__wrapped__||t.__wrapped__)return b(n.__wrapped__||n,t.__wrapped__||t,e,u);if(i!=Ot)return L;var i=n.constructor,a=t.constructor; +if(i!=a&&(!j(i)||!(i instanceof i&&j(a)&&a instanceof a)))return L}for(e||(e=[]),u||(u=[]),i=e.length;i--;)if(e[i]==n)return u[i]==t;var f=J,c=0;if(e.push(n),u.push(t),o){if(c=t.length,f=c==n.length)for(;c--&&(f=b(n[c],t[c],e,u)););return f}return r(t,function(t,r,o){return lt.call(o,r)?(c++,!(f=lt.call(n,r)&&b(n[r],t,e,u))&&nt):void 0}),f&&r(n,function(n,t,r){return lt.call(r,t)?!(f=-1<--c)&&nt:void 0}),f}function j(n){return typeof n=="function"}function w(n){return n?Tt[typeof n]:L}function x(n){return typeof n=="number"||st.call(n)==Et +}function A(n){return typeof n=="string"||st.call(n)==Nt}function E(n){for(var t=-1,r=Dt(n),e=r.length,u=Array(e);++to&&(o=f)}}else t=a(t,r),e(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function q(n,t){return R(n,t+"")}function B(n,t,r,u){var o=3>arguments.length;if(t=a(t,u,4),Bt(n)){var i=-1,f=n.length;for(o&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var i=Dt(n),u=i.length;return t=a(t,e,4),F(n,function(e,a,f){a=i?i[--u]:--u,r=o?(o=L,n[a]):t(r,n[a],a,f) +}),r}function M(n,t,r){var u;if(t=a(t,r),Bt(n)){r=-1;for(var o=n.length;++rr?mt(0,u+r):r||0)-1;else if(r)return e=U(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])C(f,c))&&(r&&f.push(c),i.push(e))}return i}function W(n,t){return kt||vt&&2"']/g,it=/['\n\r\t\u2028\u2029\\]/g,at=Math.ceil,ft=Y.concat,ct=Math.floor,lt=X.hasOwnProperty,pt=Y.push,st=X.toString,vt=et.test(vt=p.bind)&&vt,ht=et.test(ht=Array.isArray)&&ht,gt=n.isFinite,yt=n.isNaN,_t=et.test(_t=Object.keys)&&_t,mt=Math.max,dt=Math.min,bt=Math.random,jt="[object Arguments]",wt="[object Array]",xt="[object Boolean]",At="[object Date]",Et="[object Number]",Ot="[object Object]",St="[object RegExp]",Nt="[object String]",X=!!n.attachEvent,X=vt&&!/\n|true/.test(vt+X),kt=vt&&!X,Ft=(Ft={0:1,length:1},Y.splice.call(Ft,0,1),Ft[0]),Rt=arguments.constructor==Object,Tt={"boolean":L,"function":J,object:J,number:L,string:L,undefined:L},qt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"}; u.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},v(arguments)||(v=function(n){return n?lt.call(n,"callee"):L});var Bt=ht||function(n){return Rt&&n instanceof Array||st.call(n)==wt},Dt=_t?function(n){return w(n)?_t(n):[]}:h,Mt={"&":"&","<":"<",">":">",'"':""","'":"'"},$t=m(Mt);j(/x/)&&(j=function(n){return n instanceof Function||"[object Function]"==st.call(n)}),u.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0 }},u.bind=W,u.bindAll=function(n){for(var t=ft.apply(Y,arguments),r=1C(e,o,r)&&u.push(o)}return u},u.filter=N,u.flatten=z,u.forEach=F,u.functions=_,u.groupBy=function(n,t,r){var e={}; diff --git a/doc/README.md b/doc/README.md index a7bc9e0d0..d134d62e4 100644 --- a/doc/README.md +++ b/doc/README.md @@ -20,7 +20,7 @@ * [`_.object`](#_objectkeys--values) * [`_.range`](#_rangestart0-end--step1) * [`_.rest`](#_restarray--callbackn1-thisarg) -* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentityproperty-thisarg) +* [`_.sortedIndex`](#_sortedindexarray-value--callbackidentity-thisarg) * [`_.tail`](#_restarray--callbackn1-thisarg) * [`_.take`](#_firstarray--callbackn-thisarg) * [`_.union`](#_unionarray1-array2-) @@ -52,7 +52,7 @@ * [`_.at`](#_atcollection--index1-index2-) * [`_.collect`](#_mapcollection--callbackidentity-thisarg) * [`_.contains`](#_containscollection-target--fromindex0) -* [`_.countBy`](#_countbycollection-callbackproperty--thisarg) +* [`_.countBy`](#_countbycollection--callbackidentity-thisarg) * [`_.detect`](#_findcollection--callbackidentity-thisarg) * [`_.each`](#_foreachcollection--callbackidentity-thisarg) * [`_.every`](#_everycollection--callbackidentity-thisarg) @@ -61,13 +61,13 @@ * [`_.foldl`](#_reducecollection--callbackidentity-accumulator-thisarg) * [`_.foldr`](#_reducerightcollection--callbackidentity-accumulator-thisarg) * [`_.forEach`](#_foreachcollection--callbackidentity-thisarg) -* [`_.groupBy`](#_groupbycollection-callbackproperty--thisarg) +* [`_.groupBy`](#_groupbycollection--callbackidentity-thisarg) * [`_.include`](#_containscollection-target--fromindex0) * [`_.inject`](#_reducecollection--callbackidentity-accumulator-thisarg) * [`_.invoke`](#_invokecollection-methodname--arg1-arg2-) * [`_.map`](#_mapcollection--callbackidentity-thisarg) -* [`_.max`](#_maxcollection--callback-thisarg) -* [`_.min`](#_mincollection--callback-thisarg) +* [`_.max`](#_maxcollection--callbackidentity-thisarg) +* [`_.min`](#_mincollection--callbackidentity-thisarg) * [`_.pluck`](#_pluckcollection-property) * [`_.reduce`](#_reducecollection--callbackidentity-accumulator-thisarg) * [`_.reduceRight`](#_reducerightcollection--callbackidentity-accumulator-thisarg) @@ -76,7 +76,7 @@ * [`_.shuffle`](#_shufflecollection) * [`_.size`](#_sizecollection) * [`_.some`](#_somecollection--callbackidentity-thisarg) -* [`_.sortBy`](#_sortbycollection-callbackproperty--thisarg) +* [`_.sortBy`](#_sortbycollection--callbackidentity-thisarg) * [`_.toArray`](#_toarraycollection) * [`_.where`](#_wherecollection-properties) @@ -197,7 +197,7 @@ ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2962 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3115 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -221,7 +221,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2992 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3145 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -246,16 +246,20 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.first(array [, callback|n, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3036 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3216 "View in source") [Ⓣ][1] Gets the first element of the `array`. If a number `n` is passed, the first `n` elements of the `array` are returned. If a `callback` function is passed, the first elements the `callback` returns truthy for are returned. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Aliases *head, take* #### Arguments 1. `array` *(Array)*: The array to query. -2. `[callback|n]` *(Function|Number)*: The function called per element or the number of elements to return. +2. `[callback|n]` *(Function|Object|Number|String)*: The function called per element or the number of elements to return. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -273,6 +277,25 @@ _.first([1, 2, 3], function(num) { return num < 3; }); // => [1, 2] + +var food = [ + { 'name': 'banana', 'organic': true }, + { 'name': 'beet', 'organic': false }, +]; + +// using "_.pluck" callback shorthand +_.first(food, 'organic'); +// => [{ 'name': 'banana', 'organic': true }] + +var food = [ + { 'name': 'apple', 'type': 'fruit' }, + { 'name': 'banana', 'type': 'fruit' }, + { 'name': 'beet', 'type': 'vegetable' } +]; + +// using "_.where" callback shorthand +_.first(food, { 'type': 'fruit' }); +// => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }] ``` * * * @@ -283,7 +306,7 @@ _.first([1, 2, 3], function(num) { ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3075 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3255 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -311,7 +334,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3117 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3297 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `fromIndex` will run a faster binary search. @@ -343,13 +366,17 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, callback|n=1, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3370 "View in source") [Ⓣ][1] Gets all but the last element of `array`. If a number `n` is passed, the last `n` elements are excluded from the result. If a `callback` function is passed, the last elements the `callback` returns truthy for are excluded from the result. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Arguments 1. `array` *(Array)*: The array to query. -2. `[callback|n=1]` *(Function|Number)*: The function called per element or the number of elements to exclude. +2. `[callback|n=1]` *(Function|Object|Number|String)*: The function called per element or the number of elements to exclude. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -367,6 +394,25 @@ _.initial([1, 2, 3], function(num) { return num > 1; }); // => [1] + +var food = [ + { 'name': 'beet', 'organic': false }, + { 'name': 'carrot', 'organic': true } +]; + +// using "_.pluck" callback shorthand +_.initial(food, 'organic'); +// => [{ 'name': 'beet', 'organic': false }] + +var food = [ + { 'name': 'banana', 'type': 'fruit' }, + { 'name': 'beet', 'type': 'vegetable' }, + { 'name': 'carrot', 'type': 'vegetable' } +]; + +// using "_.where" callback shorthand +_.initial(food, { 'type': 'vegetable' }); +// => [{ 'name': 'banana', 'type': 'fruit' }] ``` * * * @@ -377,7 +423,7 @@ _.initial([1, 2, 3], function(num) { ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3197 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3404 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -401,13 +447,17 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.last(array [, callback|n, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3259 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3494 "View in source") [Ⓣ][1] Gets the last element of the `array`. If a number `n` is passed, the last `n` elements of the `array` are returned. If a `callback` function is passed, the last elements the `callback` returns truthy for are returned. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. + If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Arguments 1. `array` *(Array)*: The array to query. -2. `[callback|n]` *(Function|Number)*: The function called per element or the number of elements to return. +2. `[callback|n]` *(Function|Object|Number|String)*: The function called per element or the number of elements to return. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -425,6 +475,25 @@ _.last([1, 2, 3], function(num) { return num > 1; }); // => [2, 3] + +var food = [ + { 'name': 'beet', 'organic': false }, + { 'name': 'carrot', 'organic': true } +]; + +// using "_.pluck" callback shorthand +_.last(food, 'organic'); +// => [{ 'name': 'carrot', 'organic': true }] + +var food = [ + { 'name': 'banana', 'type': 'fruit' }, + { 'name': 'beet', 'type': 'vegetable' }, + { 'name': 'carrot', 'type': 'vegetable' } +]; + +// using "_.where" callback shorthand +_.last(food, { 'type': 'vegetable' }); +// => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }] ``` * * * @@ -435,7 +504,7 @@ _.last([1, 2, 3], function(num) { ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3300 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3535 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection. @@ -464,7 +533,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3330 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3565 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -489,7 +558,7 @@ _.object(['moe', 'larry'], [30, 40]); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3609 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `end`. @@ -527,16 +596,20 @@ _.range(0); ### `_.rest(array [, callback|n=1, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3424 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3686 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. If a number `n` is passed, the first `n` values are excluded from the result. If a `callback` function is passed, the first elements the `callback` returns truthy for are excluded from the result. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Aliases *drop, tail* #### Arguments 1. `array` *(Array)*: The array to query. -2. `[callback|n=1]` *(Function|Number)*: The function called per element or the number of elements to exclude. +2. `[callback|n=1]` *(Function|Object|Number|String)*: The function called per element or the number of elements to exclude. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -554,6 +627,25 @@ _.rest([1, 2, 3], function(num) { return num < 3; }); // => [3] + +var food = [ + { 'name': 'banana', 'organic': true }, + { 'name': 'beet', 'organic': false }, +]; + +// using "_.pluck" callback shorthand +_.rest(food, 'organic'); +// => [{ 'name': 'beet', 'organic': false }] + +var food = [ + { 'name': 'apple', 'type': 'fruit' }, + { 'name': 'banana', 'type': 'fruit' }, + { 'name': 'beet', 'type': 'vegetable' } +]; + +// using "_.where" callback shorthand +_.rest(food, { 'type': 'fruit' }); +// => [{ 'name': 'beet', 'type': 'vegetable' }] ``` * * * @@ -563,15 +655,19 @@ _.rest([1, 2, 3], function(num) { -### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3480 "View in source") [Ⓣ][1] +### `_.sortedIndex(array, value [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3750 "View in source") [Ⓣ][1] -Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. The `callback` argument may also be the name of a property to order by. +Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. + +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to iterate over. 2. `value` *(Mixed)*: The value to evaluate. -3. `[callback=identity|property]` *(Function|String)*: The function called per iteration or property name to order by. +3. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -582,6 +678,7 @@ Uses a binary search to determine the smallest index at which the `value` should _.sortedIndex([20, 30, 50], 40); // => 2 +// using "_.pluck" callback shorthand _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); // => 2 @@ -608,7 +705,7 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3512 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3782 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -632,17 +729,21 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3829 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Aliases *unique* #### Arguments 1. `array` *(Array)*: The array to process. 2. `[isSorted=false]` *(Boolean)*: A flag to indicate that the `array` is already sorted. -3. `[callback=identity]` *(Function)*: The function called per iteration. +3. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -661,6 +762,10 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); }); _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); // => [1, 2, 3] + +// using "_.pluck" callback shorthand +_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); +// => [{ 'x': 1 }, { 'x': 2 }] ``` * * * @@ -671,7 +776,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3605 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3888 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -696,7 +801,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3919 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -756,7 +861,7 @@ The wrapper functions `first` and `last` return wrapped values when `n` is passe ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4534 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4817 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -786,7 +891,7 @@ _([1, 2, 3, 4]) ### `_.prototype.toString()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4551 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4834 "View in source") [Ⓣ][1] Produces the `toString` result of the wrapped value. @@ -807,7 +912,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.valueOf()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4568 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4851 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -838,7 +943,7 @@ _([1, 2, 3]).valueOf(); ### `_.at(collection [, index1, index2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2121 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2126 "View in source") [Ⓣ][1] Creates an array of elements from the specified index(es), or keys, of the `collection`. Indexes may be specified as individual arguments or as arrays of indexes. @@ -866,7 +971,7 @@ _.at(['moe', 'larry', 'curly'], 0, 2); ### `_.contains(collection, target [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2168 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection. @@ -903,14 +1008,18 @@ _.contains('curly', 'ur'); -### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2210 "View in source") [Ⓣ][1] +### `_.countBy(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2222 "View in source") [Ⓣ][1] -Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. +Creates an object composed of keys returned from running each element of the `collection` through the given `callback`. The corresponding value of each key is the number of times the key was returned by the `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to count by. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -936,16 +1045,20 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2253 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2274 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Aliases *all* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -961,13 +1074,13 @@ var stooges = [ { 'name': 'larry', 'age': 50 } ]; -// using callback "where" shorthand -_.every(stooges, { 'age': 50 }); -// => false - -// using callback "pluck" shorthand +// using "_.pluck" callback shorthand _.every(stooges, 'age'); // => true + +// using "_.where" callback shorthand +_.every(stooges, { 'age': 50 }); +// => false ``` * * * @@ -978,16 +1091,20 @@ _.every(stooges, 'age'); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2292 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2335 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Aliases *select* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -997,6 +1114,19 @@ Examines each element in a `collection`, returning an array of all elements the ```js var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); // => [2, 4, 6] + +var food = [ + { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } +]; + +// using "_.pluck" callback shorthand +_.filter(food, 'organic'); +// => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] + +// using "_.where" callback shorthand +_.filter(food, { 'type': 'fruit' }); +// => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] ``` * * * @@ -1007,16 +1137,20 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2352 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2402 "View in source") [Ⓣ][1] -Examines each element in a `collection`, returning the first that the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +Examines each element in a `collection`, returning the first that the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. #### Aliases *detect* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1034,11 +1168,11 @@ var food = [ { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } ]; -// using callback "where" shorthand +// using "_.where" callback shorthand var veggie = _.find(food, { 'type': 'vegetable' }); // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' } -// using callback "pluck" shorthand +// using "_.pluck" callback shorthand var healthy = _.find(food, 'organic'); // => { 'name': 'banana', 'organic': true, 'type': 'fruit' } ``` @@ -1051,7 +1185,7 @@ var healthy = _.find(food, 'organic'); ### `_.forEach(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2387 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2437 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -1082,14 +1216,18 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); -### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2429 "View in source") [Ⓣ][1] +### `_.groupBy(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2487 "View in source") [Ⓣ][1] -Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to group by *(e.g. 'length')*. +Creates an object composed of keys returned from running each element of the `collection` through the `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false` #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to group by. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1103,6 +1241,7 @@ _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); // => { '4': [4.2], '6': [6.1, 6.4] } +// using "_.pluck" callback shorthand _.groupBy(['one', 'two', 'three'], 'length'); // => { '3': ['one', 'two'], '5': ['three'] } ``` @@ -1115,7 +1254,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2462 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2520 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function, it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1144,16 +1283,20 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2496 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2572 "View in source") [Ⓣ][1] -Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +Creates an array of values by running each element in the `collection` through the `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. + +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. #### Aliases *collect* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1166,6 +1309,15 @@ _.map([1, 2, 3], function(num) { return num * 3; }); _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); // => [3, 6, 9] (order is not guaranteed) + +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 } +]; + +// using "_.pluck" callback shorthand +_.map(stooges, 'name'); +// => ['moe', 'larry'] ``` * * * @@ -1175,14 +1327,18 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); -### `_.max(collection [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2540 "View in source") [Ⓣ][1] +### `_.max(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2629 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1200,6 +1356,10 @@ var stooges = [ _.max(stooges, function(stooge) { return stooge.age; }); // => { 'name': 'larry', 'age': 50 }; + +// using "_.pluck" callback shorthand +_.max(stooges, 'age'); +// => { 'name': 'larry', 'age': 50 }; ``` * * * @@ -1209,14 +1369,18 @@ _.max(stooges, function(stooge) { return stooge.age; }); -### `_.min(collection [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2596 "View in source") [Ⓣ][1] +### `_.min(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2698 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1234,6 +1398,10 @@ var stooges = [ _.min(stooges, function(stooge) { return stooge.age; }); // => { 'name': 'moe', 'age': 40 }; + +// using "_.pluck" callback shorthand +_.min(stooges, 'age'); +// => { 'name': 'moe', 'age': 40 }; ``` * * * @@ -1244,7 +1412,7 @@ _.min(stooges, function(stooge) { return stooge.age; }); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2646 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2747 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1274,7 +1442,7 @@ _.pluck(stooges, 'name'); ### `_.reduce(collection [, callback=identity, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2670 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2771 "View in source") [Ⓣ][1] Reduces a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with four arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1304,7 +1472,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection [, callback=identity, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2713 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2814 "View in source") [Ⓣ][1] This method is similar to `_.reduce`, except that it iterates over a `collection` from right to left. @@ -1335,13 +1503,17 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2751 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2874 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the elements of a `collection` that `callback` does **not** return truthy for. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1351,6 +1523,19 @@ The opposite of `_.filter`, this method returns the elements of a `collection` t ```js var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); // => [1, 3, 5] + +var food = [ + { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } +]; + +// using "_.pluck" callback shorthand +_.reject(food, 'organic'); +// => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] + +// using "_.where" callback shorthand +_.reject(food, { 'type': 'fruit' }); +// => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] ``` * * * @@ -1361,7 +1546,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.shuffle(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2772 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2895 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -1385,7 +1570,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2805 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2928 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -1415,16 +1600,20 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2830 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2975 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. + #### Aliases *any* #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `[callback=identity]` *(Function)*: The function called per iteration. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1434,6 +1623,19 @@ Checks if the `callback` returns a truthy value for **any** element of a `collec ```js _.some([null, 0, 'yes', false], Boolean); // => true + +var food = [ + { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } +]; + +// using "_.pluck" callback shorthand +_.some(food, 'organic'); +// => true + +// using "_.where" callback shorthand +_.some(food, { 'type': 'meat' }); +// => false ``` * * * @@ -1443,14 +1645,18 @@ _.some([null, 0, 'yes', false], Boolean); -### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2876 "View in source") [Ⓣ][1] +### `_.sortBy(collection [, callback=identity, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3030 "View in source") [Ⓣ][1] -Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. +Creates an array, stable sorted in ascending order by the results of running each element of `collection` through the `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. + +If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element. + +If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. -2. `callback|property` *(Function|String)*: The function called per iteration or property name to sort by. +2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a string or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -1464,6 +1670,7 @@ _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); // => [3, 1, 2] +// using "_.pluck" callback shorthand _.sortBy(['banana', 'strawberry', 'apple'], 'length'); // => ['apple', 'banana', 'strawberry'] ``` @@ -1476,7 +1683,7 @@ _.sortBy(['banana', 'strawberry', 'apple'], 'length'); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2911 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3065 "View in source") [Ⓣ][1] Converts the `collection` to an array. @@ -1500,7 +1707,7 @@ Converts the `collection` to an array. ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2942 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3097 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that have the given `properties`. When checking `properties`, this method performs a deep comparison between values to determine if they are equivalent to each other. @@ -1537,7 +1744,7 @@ _.where(stooges, { 'age': 40 }); ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3669 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3952 "View in source") [Ⓣ][1] Creates a function that is restricted to executing `func` only after it is called `n` times. The `func` is executed with the `this` binding of the created function. @@ -1565,7 +1772,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3702 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3985 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. @@ -1596,7 +1803,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3733 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4016 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. Method names may be specified as individual arguments or as arrays of method names. If no method names are provided, all the function properties of `object` will be bound. @@ -1627,7 +1834,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.bindKey(object, key [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3779 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4062 "View in source") [Ⓣ][1] Creates a function that, when called, invokes the method at `object[key]` and prepends any additional `bindKey` arguments to those passed to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern. @@ -1668,7 +1875,7 @@ func(); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3802 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4085 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. Each function is executed with the `this` binding of the composed function. @@ -1695,7 +1902,7 @@ welcome('moe'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3835 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4118 "View in source") [Ⓣ][1] Creates a function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -1721,7 +1928,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3899 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4182 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -1746,7 +1953,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3879 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4162 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -1773,7 +1980,7 @@ _.delay(log, 1000, 'logged later'); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3923 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4206 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. The `func` is executed with the `this` binding of the memoized function. @@ -1799,7 +2006,7 @@ var fibonacci = _.memoize(function(n) { ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3950 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4233 "View in source") [Ⓣ][1] Creates a function that is restricted to execute `func` once. Repeat calls to the function will return the value of the first call. The `func` is executed with the `this` binding of the created function. @@ -1825,7 +2032,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3985 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4268 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `_.bind`, except it does **not** alter the `this` binding. @@ -1852,7 +2059,7 @@ hi('moe'); ### `_.partialRight(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4018 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4301 "View in source") [Ⓣ][1] This method is similar to `_.partial`, except that `partial` arguments are appended to those passed to the new function. @@ -1891,7 +2098,7 @@ options.imports ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4040 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4323 "View in source") [Ⓣ][1] Creates a function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -1916,7 +2123,7 @@ jQuery(window).on('scroll', throttled); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4093 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4376 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the function are appended to those passed to the `wrapper` function. The `wrapper` is executed with the `this` binding of the created function. @@ -2440,7 +2647,7 @@ _.isEqual(words, otherWords, function(a, b) { ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1605 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1610 "View in source") [Ⓣ][1] Checks if `value` is, or can be coerced to, a finite number. @@ -2478,7 +2685,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1622 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1627 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -2502,7 +2709,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1685 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1690 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. @@ -2537,7 +2744,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1707 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1712 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -2564,7 +2771,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1724 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1729 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -2588,7 +2795,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1652 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1657 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -2618,7 +2825,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1752 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1757 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. @@ -2653,7 +2860,7 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1777 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1782 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -2677,7 +2884,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1794 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1799 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -2701,7 +2908,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1811 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1816 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -2749,7 +2956,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.merge(object [, source1, source2, ..., callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1871 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1876 "View in source") [Ⓣ][1] Recursively merges own enumerable properties of the source object(s), that don't resolve to `undefined`, into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. If a `callback` function is passed, it will be executed to produce the merged values of the destination and source properties. If `callback` returns `undefined`, merging will be handled by the method instead. The `callback` is bound to `thisArg` and invoked with two arguments; *(objectValue, sourceValue)*. @@ -2805,7 +3012,7 @@ _.merge(food, otherFood, function(a, b) { ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1977 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1982 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If a `callback` function is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2836,7 +3043,7 @@ _.omit({ 'name': 'moe', 'age': 40 }, function(value) { ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2011 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2016 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -2860,7 +3067,7 @@ _.pairs({ 'moe': 30, 'larry': 40 }); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2049 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2054 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2891,7 +3098,7 @@ _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2086 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2091 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2922,7 +3129,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4117 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4400 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -2946,7 +3153,7 @@ _.escape('Moe, Larry & Curly'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4135 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4418 "View in source") [Ⓣ][1] This function returns the first argument passed to it. @@ -2971,7 +3178,7 @@ moe === _.identity(moe); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4161 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4444 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -3001,7 +3208,7 @@ _('moe').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4185 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4468 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -3021,7 +3228,7 @@ var lodash = _.noConflict(); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4208 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4491 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -3049,7 +3256,7 @@ _.random(5); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4246 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4529 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function, it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -3084,7 +3291,7 @@ _.result(object, 'stuff'); ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4334 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4617 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -3168,7 +3375,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4460 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4743 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -3200,7 +3407,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4486 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4769 "View in source") [Ⓣ][1] The opposite of `_.escape`, this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -3224,7 +3431,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4789 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is passed, the ID will be appended to it. @@ -3277,7 +3484,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4736 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L5019 "View in source") [Ⓣ][1] *(String)*: The semantic version number. diff --git a/lodash.js b/lodash.js index 0e963bbe4..292cc0b60 100644 --- a/lodash.js +++ b/lodash.js @@ -2187,18 +2187,25 @@ } /** - * Creates an object composed of keys returned from running each element of - * `collection` through a `callback`. The corresponding value of each key is - * the number of times the key was returned by `callback`. The `callback` is - * bound to `thisArg` and invoked with three arguments; (value, index|key, collection). - * The `callback` argument may also be the name of a property to count by (e.g. 'length'). + * Creates an object composed of keys returned from running each element of the + * `collection` through the given `callback`. The corresponding value of each key + * is the number of times the key was returned by the `callback`. The `callback` + * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to count by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example @@ -2228,12 +2235,21 @@ * `collection`. The `callback` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias all * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if all elements pass the callback check, * else `false`. @@ -2247,13 +2263,13 @@ * { 'name': 'larry', 'age': 50 } * ]; * - * // using callback "where" shorthand - * _.every(stooges, { 'age': 50 }); - * // => false - * - * // using callback "pluck" shorthand + * // using "_.pluck" callback shorthand * _.every(stooges, 'age'); * // => true + * + * // using "_.where" callback shorthand + * _.every(stooges, { 'age': 50 }); + * // => false */ function every(collection, callback, thisArg) { var result = true; @@ -2281,18 +2297,40 @@ * the `callback` returns truthy for. The `callback` is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias select * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that passed the callback check. * @example * * var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [2, 4, 6] + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.filter(food, 'organic'); + * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] + * + * // using "_.where" callback shorthand + * _.filter(food, { 'type': 'fruit' }); + * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] */ function filter(collection, callback, thisArg) { var result = []; @@ -2319,18 +2357,25 @@ } /** - * Examines each element in a `collection`, returning the first that the - * `callback` returns truthy for. The function returns as soon as it finds - * an acceptable element, and does not iterate over the entire `collection`. - * The `callback` is bound to `thisArg` and invoked with three arguments; - * (value, index|key, collection). + * Examines each element in a `collection`, returning the first that the `callback` + * returns truthy for. The `callback` is bound to `thisArg` and invoked with three + * arguments; (value, index|key, collection). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @alias detect * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the element that passed the callback check, * else `undefined`. @@ -2346,11 +2391,11 @@ * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } * ]; * - * // using callback "where" shorthand + * // using "_.where" callback shorthand * var veggie = _.find(food, { 'type': 'vegetable' }); * // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' } * - * // using callback "pluck" shorthand + * // using "_.pluck" callback shorthand * var healthy = _.find(food, 'organic'); * // => { 'name': 'banana', 'organic': true, 'type': 'fruit' } */ @@ -2406,18 +2451,25 @@ } /** - * Creates an object composed of keys returned from running each element of - * `collection` through a `callback`. The corresponding value of each key is an - * array of elements passed to `callback` that returned the key. The `callback` + * Creates an object composed of keys returned from running each element of the + * `collection` through the `callback`. The corresponding value of each key is + * an array of elements passed to `callback` that returned the key. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). - * The `callback` argument may also be the name of a property to group by (e.g. 'length'). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false` * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to group by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Object} Returns the composed aggregate object. * @example @@ -2428,6 +2480,7 @@ * _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); * // => { '4': [4.2], '6': [6.1, 6.4] } * + * // using "_.pluck" callback shorthand * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ @@ -2479,15 +2532,24 @@ /** * Creates an array of values by running each element in the `collection` - * through a `callback`. The `callback` is bound to `thisArg` and invoked with + * through the `callback`. The `callback` is bound to `thisArg` and invoked with * three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias collect * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of the results of each `callback` execution. * @example @@ -2497,6 +2559,15 @@ * * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); * // => [3, 6, 9] (order is not guaranteed) + * + * var stooges = [ + * { 'name': 'moe', 'age': 40 }, + * { 'name': 'larry', 'age': 50 } + * ]; + * + * // using "_.pluck" callback shorthand + * _.map(stooges, 'name'); + * // => ['moe', 'larry'] */ function map(collection, callback, thisArg) { var index = -1, @@ -2522,11 +2593,20 @@ * criterion by which the value is ranked. The `callback` is bound to * `thisArg` and invoked with three arguments; (value, index, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the maximum value. * @example @@ -2541,6 +2621,10 @@ * * _.max(stooges, function(stooge) { return stooge.age; }); * // => { 'name': 'larry', 'age': 50 }; + * + * // using "_.pluck" callback shorthand + * _.max(stooges, 'age'); + * // => { 'name': 'larry', 'age': 50 }; */ function max(collection, callback, thisArg) { var computed = -Infinity, @@ -2578,11 +2662,20 @@ * criterion by which the value is ranked. The `callback` is bound to `thisArg` * and invoked with three arguments; (value, index, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the minimum value. * @example @@ -2597,6 +2690,10 @@ * * _.min(stooges, function(stooge) { return stooge.age; }); * // => { 'name': 'moe', 'age': 40 }; + * + * // using "_.pluck" callback shorthand + * _.min(stooges, 'age'); + * // => { 'name': 'moe', 'age': 40 }; */ function min(collection, callback, thisArg) { var computed = Infinity, @@ -2629,8 +2726,7 @@ } /** - * Retrieves the value of a specified property from all elements in - * the `collection`. + * Retrieves the value of a specified property from all elements in the `collection`. * * @static * @memberOf _ @@ -2740,11 +2836,20 @@ * The opposite of `_.filter`, this method returns the elements of a * `collection` that `callback` does **not** return truthy for. * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of elements that did **not** pass the * callback check. @@ -2752,6 +2857,19 @@ * * var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); * // => [1, 3, 5] + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.reject(food, 'organic'); + * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }] + * + * // using "_.where" callback shorthand + * _.reject(food, { 'type': 'fruit' }); + * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }] */ function reject(collection, callback, thisArg) { callback = createCallback(callback, thisArg); @@ -2818,12 +2936,21 @@ * does not iterate over the entire `collection`. The `callback` is bound to * `thisArg` and invoked with three arguments; (value, index|key, collection). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias any * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Boolean} Returns `true` if any element passes the callback check, * else `false`. @@ -2831,6 +2958,19 @@ * * _.some([null, 0, 'yes', false], Boolean); * // => true + * + * var food = [ + * { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + * ]; + * + * // using "_.pluck" callback shorthand + * _.some(food, 'organic'); + * // => true + * + * // using "_.where" callback shorthand + * _.some(food, { 'type': 'meat' }); + * // => false */ function some(collection, callback, thisArg) { var result; @@ -2855,16 +2995,24 @@ /** * Creates an array, stable sorted in ascending order by the results of - * running each element of `collection` through a `callback`. The `callback` + * running each element of `collection` through the `callback`. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection). * The `callback` argument may also be the name of a property to sort by (e.g. 'length'). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. - * @param {Function|String} callback|property The function called per iteration - * or property name to sort by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a new array of sorted elements. * @example @@ -2875,6 +3023,7 @@ * _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); * // => [3, 1, 2] * + * // using "_.pluck" callback shorthand * _.sortBy(['banana', 'strawberry', 'apple'], 'length'); * // => ['apple', 'banana', 'strawberry'] */ @@ -2930,6 +3079,7 @@ * * @static * @memberOf _ + * @type Function * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Object} properties The object of property values to filter by. @@ -3014,13 +3164,21 @@ * the first elements the `callback` returns truthy for are returned. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias head, take * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n] The function called per element or - * the number of elements to return. + * @param {Function|Object|Number|String} [callback|n] The function called per + * element or the number of elements to return. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the first element(s) of `array`. * @example @@ -3035,6 +3193,25 @@ * return num < 3; * }); * // => [1, 2] + * + * var food = [ + * { 'name': 'banana', 'organic': true }, + * { 'name': 'beet', 'organic': false }, + * ]; + * + * // using "_.pluck" callback shorthand + * _.first(food, 'organic'); + * // => [{ 'name': 'banana', 'organic': true }] + * + * var food = [ + * { 'name': 'apple', 'type': 'fruit' }, + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.first(food, { 'type': 'fruit' }); + * // => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }] */ function first(array, callback, thisArg) { if (array) { @@ -3142,12 +3319,20 @@ * from the result. The `callback` is bound to `thisArg` and invoked with three * arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n=1] The function called per element or - * the number of elements to exclude. + * @param {Function|Object|Number|String} [callback|n=1] The function called per + * element or the number of elements to exclude. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a slice of `array`. * @example @@ -3162,6 +3347,25 @@ * return num > 1; * }); * // => [1] + * + * var food = [ + * { 'name': 'beet', 'organic': false }, + * { 'name': 'carrot', 'organic': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.initial(food, 'organic'); + * // => [{ 'name': 'beet', 'organic': false }] + * + * var food = [ + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' }, + * { 'name': 'carrot', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.initial(food, { 'type': 'vegetable' }); + * // => [{ 'name': 'banana', 'type': 'fruit' }] */ function initial(array, callback, thisArg) { if (!array) { @@ -3238,12 +3442,21 @@ * the last elements the `callback` returns truthy for are returned. The `callback` * is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n] The function called per element or - * the number of elements to return. + * @param {Function|Object|Number|String} [callback|n] The function called per + * element or the number of elements to return. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the last element(s) of `array`. * @example @@ -3258,6 +3471,25 @@ * return num > 1; * }); * // => [2, 3] + * + * var food = [ + * { 'name': 'beet', 'organic': false }, + * { 'name': 'carrot', 'organic': true } + * ]; + * + * // using "_.pluck" callback shorthand + * _.last(food, 'organic'); + * // => [{ 'name': 'carrot', 'organic': true }] + * + * var food = [ + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' }, + * { 'name': 'carrot', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.last(food, { 'type': 'vegetable' }); + * // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }] */ function last(array, callback, thisArg) { if (array) { @@ -3402,13 +3634,21 @@ * truthy for are excluded from the result. The `callback` is bound to `thisArg` * and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias drop, tail * @category Arrays * @param {Array} array The array to query. - * @param {Function|Number} [callback|n=1] The function called per element or - * the number of elements to exclude. + * @param {Function|Object|Number|String} [callback|n=1] The function called per + * element or the number of elements to exclude. If a string or object is passed, + * it will be used to create a "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a slice of `array`. * @example @@ -3423,6 +3663,25 @@ * return num < 3; * }); * // => [3] + * + * var food = [ + * { 'name': 'banana', 'organic': true }, + * { 'name': 'beet', 'organic': false }, + * ]; + * + * // using "_.pluck" callback shorthand + * _.rest(food, 'organic'); + * // => [{ 'name': 'beet', 'organic': false }] + * + * var food = [ + * { 'name': 'apple', 'type': 'fruit' }, + * { 'name': 'banana', 'type': 'fruit' }, + * { 'name': 'beet', 'type': 'vegetable' } + * ]; + * + * // using "_.where" callback shorthand + * _.rest(food, { 'type': 'fruit' }); + * // => [{ 'name': 'beet', 'type': 'vegetable' }] */ function rest(array, callback, thisArg) { if (typeof callback == 'function') { @@ -3445,16 +3704,23 @@ * should be inserted into `array` in order to maintain the sort order of the * sorted `array`. If `callback` is passed, it will be executed for `value` and * each element in `array` to compute their sort ranking. The `callback` is - * bound to `thisArg` and invoked with one argument; (value). The `callback` - * argument may also be the name of a property to order by. + * bound to `thisArg` and invoked with one argument; (value). + * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. * * @static * @memberOf _ * @category Arrays * @param {Array} array The array to iterate over. * @param {Mixed} value The value to evaluate. - * @param {Function|String} [callback=identity|property] The function called - * per iteration or property name to order by. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Number} Returns the index at which the value should be inserted * into `array`. @@ -3463,6 +3729,7 @@ * _.sortedIndex([20, 30, 50], 40); * // => 2 * + * // using "_.pluck" callback shorthand * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * // => 2 * @@ -3523,13 +3790,22 @@ * element of `array` is passed through a callback` before uniqueness is computed. * The `callback` is bound to `thisArg` and invoked with three arguments; (value, index, array). * + * If a property name is passed for `callback`, the created "_.pluck" style + * callback will return the property value of the given element. + * + * If an object is passed for `callback`, the created "_.where" style callback + * will return `true` for elements that have the propeties of the given object, + * else `false`. + * * @static * @memberOf _ * @alias unique * @category Arrays * @param {Array} array The array to process. * @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted. - * @param {Function} [callback=identity] The function called per iteration. + * @param {Function|Object|String} [callback=identity] The function called per + * iteration. If a string or object is passed, it will be used to create a + * "_.pluck" or "_.where" style callback, respectively. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Array} Returns a duplicate-value-free array. * @example @@ -3545,6 +3821,10 @@ * * _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); * // => [1, 2, 3] + * + * // using "_.pluck" callback shorthand + * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] */ function uniq(array, isSorted, callback, thisArg) { var index = -1, diff --git a/lodash.min.js b/lodash.min.js index 7c7e231bc..c014ae40e 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -3,39 +3,39 @@ * Lo-Dash 1.0.0-rc.3 lodash.com/license * Underscore.js 1.4.4 underscorejs.org/LICENSE */ -;(function(n,t){function r(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,void 0):new r(n)}function e(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||ut);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(nu;u++)e+="i='"+t.k[u]+"';if(","constructor"==t.k[u]&&(e+="!(f&&f.prototype===m)&&"),e+="h.call(m,i)){"+t.h+"}"}return(t.b||t.i)&&(e+="}"),e+=t.c+";return u",r("e,h,j,k,l,q,o,t","return function("+n+"){"+e+"}")(f,wt,h,cr,A,tr,Nt,Ot)}function c(n){return"\\"+rr[n]}function l(n){return pr[n]}function p(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function s(){}function v(n,t,r){t||(t=0),typeof r=="undefined"&&(r=n?n.length:0);var e=-1;r=r-t||0;for(var u=Array(0>r?0:r);++er?Rt(0,u+r):r)||0,typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):ir(n,function(n){return++eo&&(o=a)}}else t=!t&&A(n)?u:f(t,r),ir(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function I(n,t){return F(n,t+"")}function T(n,t,r,e){var u=3>arguments.length;if(t=f(t,e,4),cr(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof o!="number")var a=lr(n),o=a.length;else Wt&&A(n)&&(u=n.split(""));return t=f(t,e,4),$(n,function(n,e,f){e=a?a[--o]:--o,r=i?(i=!1,u[e]):t(r,u[e],e,f)}),r}function M(n,t,r){var e;if(t=f(t,r),cr(n)){r=-1;for(var u=n.length;++rr?Rt(0,u+r):r||0)-1;else if(r)return e=L(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])C(a,p))&&((r||c)&&a.push(p),i.push(e))}return i}function V(n,t){return Ut||St&&2/g,gt=/($^)/,ht=/[&<>"']/g,yt=/['\n\r\t\u2028\u2029\\]/g,mt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),_t=Math.ceil,dt=nt.concat,bt=Math.floor,jt=pt.test(jt=Object.getPrototypeOf)&&jt,wt=tt.hasOwnProperty,xt=nt.push,Ot=tt.propertyIsEnumerable,At=tt.toString,St=pt.test(St=v.bind)&&St,Et=pt.test(Et=Array.isArray)&&Et,kt=n.isFinite,qt=n.isNaN,Nt=pt.test(Nt=Object.keys)&&Nt,Rt=Math.max,$t=Math.min,Ft=Math.random,Dt="[object Arguments]",It="[object Array]",Tt="[object Boolean]",Bt="[object Date]",Mt="[object Number]",Pt="[object Object]",zt="[object RegExp]",Ct="[object String]",Kt=!!n.attachEvent,Lt=St&&!/\n|true/.test(St+Kt),Ut=St&&!Lt,Vt=Nt&&(Kt||Lt),Gt=(Gt={0:1,length:1},nt.splice.call(Gt,0,1),Gt[0]),Ht=!0; -(function(){function n(){this.x=1}var t=[];n.prototype={valueOf:1,y:1};for(var r in new n)t.push(r);for(r in arguments)Ht=!r;X=!/valueOf/.test(t),Y=Ot.call(n,"prototype"),Z="x"!=t[0]})(1);var Jt=arguments.constructor==Object,Qt=!h(arguments),Wt="xx"!="x"[0]+Object("x")[0];try{var Xt=At.call(document)==Pt&&!1}catch(Yt){}var Zt={"[object Function]":!1};Zt[Dt]=Zt[It]=Zt[Tt]=Zt[Bt]=Zt[Mt]=Zt[Pt]=Zt[zt]=Zt[Ct]=!0;var nr={};nr[It]=Array,nr[Tt]=Boolean,nr[Bt]=Date,nr[Pt]=Object,nr[Mt]=Number,nr[zt]=RegExp,nr[Ct]=String; -var tr={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},rr={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};r.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:vt,variable:"",imports:{_:r}};var er={a:"p,w,g",l:"var a=0,b=typeof g=='number'?2:arguments.length;while(++a":">",'"':""","'":"'"},sr=b(pr),vr=a(er),gr=a(er,{h:"if(u[i]==null)"+er.h});w(/x/)&&(w=function(n){return n instanceof Function||"[object Function]"==At.call(n)});var hr=jt?function(n){if(!n||typeof n!="object")return!1; -var t=n.valueOf,r=typeof t=="function"&&(r=jt(t))&&jt(r);return r?n==r||jt(n)==r&&!h(n):y(n)}:y;r.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},r.assign=vr,r.at=function(n){var t=-1,r=dt.apply(nt,v(arguments,1)),e=r.length,u=Array(e);for(Wt&&A(n)&&(n=n.split(""));++tC(c,l)){f&&c.push(l);for(var s=r;--s;)if(!(u[s]||(u[s]=e(t[s],0,100)))(l))continue n;a.push(l)}}return a},r.invert=b,r.invoke=function(n,t){var r=v(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0); -return $(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},r.keys=lr,r.map=F,r.max=D,r.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return wt.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},r.merge=S,r.min=function(n,t,r){var e=1/0,o=e;if(!t&&cr(n)){r=-1;for(var i=n.length;++rC(o,r,1))&&(u[r]=n)}),u},r.once=function(n){var t,r;return function(){return t?r:(t=!0,r=n.apply(this,arguments),n=null,r)}},r.pairs=function(n){for(var t=-1,r=lr(n),e=r.length,u=Array(e);++tr?Rt(0,e+r):$t(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},r.mixin=H,r.noConflict=function(){return n._=ot,this},r.random=function(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+bt(Ft()*((+t||0)-n+1))},r.reduce=T,r.reduceRight=B,r.result=function(n,r){var e=n?n[r]:t;return w(e)?n[r]():e},r.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:lr(n).length -},r.some=M,r.sortedIndex=L,r.template=function(n,e,u){var o=r.templateSettings;n||(n=""),u=gr({},u,o);var i,f=gr({},u.imports,o.imports),o=lr(f),f=E(f),a=0,l=u.interpolate||gt,p="__p+='";n.replace(RegExp((u.escape||gt).source+"|"+l.source+"|"+(l===vt?st:gt).source+"|"+(u.evaluate||gt).source+"|$","g"),function(t,r,e,u,o,f){return e||(e=u),p+=n.slice(a,f).replace(yt,c),r&&(p+="'+__e("+r+")+'"),o&&(i=!0,p+="';"+o+";__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t}),p+="';\n",l=u=u.variable,l||(u="obj",p="with("+u+"){"+p+"}"),p=(i?p.replace(ft,""):p).replace(at,"$1").replace(ct,"$1;"),p="function("+u+"){"+(l?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(l?"":",__d="+u+"."+u+"||"+u)+";")+p+"return __p}"; -try{var s=Function(o,"return "+p).apply(t,f)}catch(v){throw v.source=p,v}return e?s(e):(s.source=p,s)},r.unescape=function(n){return null==n?"":(n+"").replace(it,g)},r.uniqueId=function(n){var t=++rt;return(null==n?"":n+"")+t},r.all=q,r.any=M,r.detect=R,r.foldl=T,r.foldr=B,r.include=k,r.inject=T,ar(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(){var t=[this.__wrapped__];return xt.apply(t,arguments),n.apply(r,t)})}),r.first=P,r.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t=="function"){var o=u; -for(t=f(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n[u-1];return v(n,Rt(0,u-e))}},r.take=P,r.head=P,ar(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(t,e){var u=n(this.__wrapped__,t,e);return null==t||e&&typeof t!="function"?u:new r(u)})}),r.VERSION="1.0.0-rc.3",r.prototype.toString=function(){return this.__wrapped__+""},r.prototype.value=J,r.prototype.valueOf=J,ir(["join","pop","shift"],function(n){var t=nt[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments) -}}),ir(["push","reverse","sort","unshift"],function(n){var t=nt[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ir(["concat","slice","splice"],function(n){var t=nt[n];r.prototype[n]=function(){return new r(t.apply(this.__wrapped__,arguments))}}),Gt&&ir(["pop","shift","splice"],function(n){var t=nt[n],e="splice"==n;r.prototype[n]=function(){var n=this.__wrapped__,u=t.apply(n,arguments);return 0===n.length&&delete n[0],e?new r(u):u}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=r,define(function(){return r -})):Q?typeof module=="object"&&module&&module.exports==Q?(module.exports=r)._=r:Q._=r:n._=r})(this); \ No newline at end of file +;(function(n,t){function r(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,void 0):new r(n)}function e(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||ft);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(ne;e++)r+="i='"+t.k[e]+"';if(","constructor"==t.k[e]&&(r+="!(f&&f.prototype===m)&&"),r+="h.call(m,i)){"+t.h+"}"; +return(t.b||t.i)&&(r+="}"),r+=t.c+";return u",Function("e,h,j,k,l,q,o,t","return function("+n+"){"+r+"}")(f,At,h,sr,A,ur,Ft,Et)}function c(n){return"\\"+or[n]}function l(n){return gr[n]}function p(n){return typeof n.toString!="function"&&typeof(n+"")=="string"}function s(){}function v(n,t,r){t||(t=0),typeof r=="undefined"&&(r=n?n.length:0);var e=-1;r=r-t||0;for(var u=Array(0>r?0:r);++er?Dt(0,u+r):r)||0,typeof u=="number"?o=-1<(A(n)?n.indexOf(t,r):C(n,t,r)):cr(n,function(n){return++eo&&(o=a)}}else t=!t&&A(n)?u:f(t,r),cr(n,function(n,r,u){r=t(n,r,u),r>e&&(e=r,o=n)});return o}function I(n,t){return F(n,t+"")}function T(n,t,r,e){var u=3>arguments.length;if(t=f(t,e,4),sr(n)){var o=-1,i=n.length;for(u&&(r=n[++o]);++oarguments.length;if(typeof o!="number")var a=vr(n),o=a.length;else Zt&&A(n)&&(u=n.split(""));return t=f(t,e,4),$(n,function(n,e,f){e=a?a[--o]:--o,r=i?(i=X,u[e]):t(r,u[e],e,f)}),r}function M(n,t,r){var e;if(t=f(t,r),sr(n)){r=-1;for(var u=n.length;++rr?Dt(0,u+r):r||0)-1;else if(r)return e=L(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])C(a,p))&&((r||c)&&a.push(p),i.push(e))}return i}function V(n,t){return Ht||qt&&2/g,mt=/($^)/,_t=/[&<>"']/g,dt=/['\n\r\t\u2028\u2029\\]/g,bt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),jt=Math.ceil,wt=et.concat,xt=Math.floor,Ot=gt.test(Ot=Object.getPrototypeOf)&&Ot,At=ut.hasOwnProperty,St=et.push,Et=ut.propertyIsEnumerable,kt=ut.toString,qt=gt.test(qt=v.bind)&&qt,Nt=gt.test(Nt=Array.isArray)&&Nt,Rt=n.isFinite,$t=n.isNaN,Ft=gt.test(Ft=Object.keys)&&Ft,Dt=Math.max,It=Math.min,Tt=Math.random,Bt="[object Arguments]",Mt="[object Array]",Pt="[object Boolean]",zt="[object Date]",Ct="[object Number]",Kt="[object Object]",Lt="[object RegExp]",Ut="[object String]",Vt=!!n.attachEvent,Gt=qt&&!/\n|true/.test(qt+Vt),Ht=qt&&!Gt,Jt=Ft&&(Vt||Gt),Qt=(Qt={0:1,length:1},et.splice.call(Qt,0,1),Qt[0]),Wt=Q; +(function(){function n(){this.x=1}var t=[];n.prototype={valueOf:1,y:1};for(var r in new n)t.push(r);for(r in arguments)Wt=!r;nt=!/valueOf/.test(t),tt=Et.call(n,"prototype"),rt="x"!=t[0]})(1);var Xt=arguments.constructor==Object,Yt=!h(arguments),Zt="xx"!="x"[0]+Object("x")[0];try{var nr=kt.call(document)==Kt&&!({toString:0}+"")}catch(tr){}var rr={"[object Function]":X};rr[Bt]=rr[Mt]=rr[Pt]=rr[zt]=rr[Ct]=rr[Kt]=rr[Lt]=rr[Ut]=Q;var er={};er[Mt]=Array,er[Pt]=Boolean,er[zt]=Date,er[Kt]=Object,er[Ct]=Number,er[Lt]=RegExp,er[Ut]=String; +var ur={"boolean":X,"function":Q,object:Q,number:X,string:X,undefined:X},or={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};r.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:yt,variable:"",imports:{_:r}};var ir={a:"p,w,g",l:"var a=0,b=typeof g=='number'?2:arguments.length;while(++a":">",'"':""","'":"'"},hr=b(gr),yr=a(ir),mr=a(ir,{h:"if(u[i]==null)"+ir.h});w(/x/)&&(w=function(n){return n instanceof Function||"[object Function]"==kt.call(n)});var _r=Ot?function(n){if(!n||typeof n!="object")return X; +var t=n.valueOf,r=typeof t=="function"&&(r=Ot(t))&&Ot(r);return r?n==r||Ot(n)==r&&!h(n):y(n)}:y,dr=N;r.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},r.assign=yr,r.at=function(n){var t=-1,r=wt.apply(et,v(arguments,1)),e=r.length,u=Array(e);for(Zt&&A(n)&&(n=n.split(""));++tC(c,l)){f&&c.push(l);for(var s=r;--s;)if(!(u[s]||(u[s]=e(t[s],0,100)))(l))continue n;a.push(l)}}return a},r.invert=b,r.invoke=function(n,t){var r=v(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0); +return $(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},r.keys=vr,r.map=F,r.max=D,r.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return At.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},r.merge=S,r.min=function(n,t,r){var e=1/0,o=e;if(!t&&sr(n)){r=-1;for(var i=n.length;++rC(o,r,1))&&(u[r]=n)}),u},r.once=function(n){var t,r;return function(){return t?r:(t=Q,r=n.apply(this,arguments),n=W,r)}},r.pairs=function(n){for(var t=-1,r=vr(n),e=r.length,u=Array(e);++tr?Dt(0,e+r):It(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},r.mixin=H,r.noConflict=function(){return n._=at,this},r.random=function(n,t){return n==W&&t==W&&(t=1),n=+n||0,t==W&&(t=n,n=0),n+xt(Tt()*((+t||0)-n+1))},r.reduce=T,r.reduceRight=B,r.result=function(n,r){var e=n?n[r]:t;return w(e)?n[r]():e},r.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:vr(n).length},r.some=M,r.sortedIndex=L,r.template=function(n,e,u){var o=r.templateSettings; +n||(n=""),u=mr({},u,o);var i,f=mr({},u.imports,o.imports),o=vr(f),f=E(f),a=0,l=u.interpolate||mt,p="__p+='";n.replace(RegExp((u.escape||mt).source+"|"+l.source+"|"+(l===yt?ht:mt).source+"|"+(u.evaluate||mt).source+"|$","g"),function(t,r,e,u,o,f){return e||(e=u),p+=n.slice(a,f).replace(dt,c),r&&(p+="'+__e("+r+")+'"),o&&(i=Q,p+="';"+o+";__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),a=f+t.length,t}),p+="';\n",l=u=u.variable,l||(u="obj",p="with("+u+"){"+p+"}"),p=(i?p.replace(lt,""):p).replace(pt,"$1").replace(st,"$1;"),p="function("+u+"){"+(l?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(l?"":",__d="+u+"."+u+"||"+u)+";")+p+"return __p}"; +try{var s=Function(o,"return "+p).apply(t,f)}catch(v){throw v.source=p,v}return e?s(e):(s.source=p,s)},r.unescape=function(n){return n==W?"":(n+"").replace(ct,g)},r.uniqueId=function(n){var t=++ot;return(n==W?"":n+"")+t},r.all=q,r.any=M,r.detect=R,r.foldl=T,r.foldr=B,r.include=k,r.inject=T,pr(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(){var t=[this.__wrapped__];return St.apply(t,arguments),n.apply(r,t)})}),r.first=P,r.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t=="function"){var o=u; +for(t=f(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,e==W||r)return n[u-1];return v(n,Dt(0,u-e))}},r.take=P,r.head=P,pr(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(t,e){var u=n(this.__wrapped__,t,e);return t==W||e&&typeof t!="function"?u:new r(u)})}),r.VERSION="1.0.0-rc.3",r.prototype.toString=function(){return this.__wrapped__+""},r.prototype.value=J,r.prototype.valueOf=J,cr(["join","pop","shift"],function(n){var t=et[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments) +}}),cr(["push","reverse","sort","unshift"],function(n){var t=et[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),cr(["concat","slice","splice"],function(n){var t=et[n];r.prototype[n]=function(){return new r(t.apply(this.__wrapped__,arguments))}}),Qt&&cr(["pop","shift","splice"],function(n){var t=et[n],e="splice"==n;r.prototype[n]=function(){var n=this.__wrapped__,u=t.apply(n,arguments);return 0===n.length&&delete n[0],e?new r(u):u}}),typeof define=="function"&&typeof define.amd=="object"&&define.amd?(n._=r,define(function(){return r +})):Y?typeof module=="object"&&module&&module.exports==Y?(module.exports=r)._=r:Y._=r:n._=r})(this); \ No newline at end of file