diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index dc6982256..129d47f51 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -4109,7 +4109,7 @@ var index = -1, length = collection.length; - if (noaccum) { + if (noaccum && length) { accumulator = collection[++index]; } while (++index < length) { diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index a3c11b497..ed011aa03 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -23,7 +23,7 @@ for(t=t&&typeof r=="undefined"?t:ut(t,r,3);++e=e)return false;if(typeof n=="string"||!Xr(n)&&Rt(n))return qr?qr.call(n,t,r):-1r?Kr(0,e+r):r)||0,-1o&&(o=i)}}else t=null==t&&Rt(n)?e:v.createCallback(t,r,3),ft(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function zt(n,t,r,e){var u=3>arguments.length;if(t=v.createCallback(t,e,4),Xr(n)){var o=-1,a=n.length;for(u&&(r=n[++o]);++oo&&(o=i)}}else t=null==t&&Rt(n)?e:v.createCallback(t,r,3),ft(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function zt(n,t,r,e){var u=3>arguments.length;if(t=v.createCallback(t,e,4),Xr(n)){var o=-1,a=n.length;for(u&&a&&(r=n[++o]);++oarguments.length;return t=v.createCallback(t,e,4),Bt(n,function(n,e,o){r=u?(u=false,n):t(r,n,e,o)}),r}function Mt(n){var t=-1,r=n?n.length:0,e=ir(typeof r=="number"?r:0);return Ft(n,function(n){var r=st(0,++t);e[t]=e[r],e[r]=n}),e}function Vt(n,t,r){var e;if(t=v.createCallback(t,r,3),Xr(n)){r=-1;for(var u=n.length;++re?Kr(0,u+e):e||0}else if(e)return e=Jt(t,r),t[e]===r?e:-1;return n(t,r,e)}function Ht(n,t,r){if(typeof t!="number"&&null!=t){var e=0,u=-1,o=n?n.length:0;for(t=v.createCallback(t,r,3);++u>>1,r(n[e])r?0:r);++t`_.map` * `_.max` * `_.min` -* `_.pluck` +* `_.pluck` * `_.reduce` * `_.reduceRight` * `_.reject` @@ -1140,7 +1140,7 @@ _.isArray(squares.value()); ### `_.chain(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6884 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6885 "View in source") [Ⓣ][1] Creates a `lodash` object that wraps the given value with explicit method chaining enabled. @@ -1174,7 +1174,7 @@ var youngest = _.chain(characters) ### `_.tap(value, interceptor, [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6911 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6912 "View in source") [Ⓣ][1] This method invokes `interceptor` and returns `value`. The interceptor is bound to `thisArg` and invoked with one argument; *(value)*. The purpose of this method is to "tap into" a method chain in order to perform operations on intermediate results within the chain. @@ -1203,7 +1203,7 @@ _([1, 2, 3, 4]) ### `_.prototype.chain()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6941 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6942 "View in source") [Ⓣ][1] Enables explicit method chaining on the wrapper object. @@ -1237,7 +1237,7 @@ _(characters).chain() ### `_.prototype.toString()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6958 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6959 "View in source") [Ⓣ][1] Produces the `toString` result of the wrapped value. @@ -1258,7 +1258,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.valueOf()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6975 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6976 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -1858,14 +1858,14 @@ _.min(characters, 'age'); -### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4089 "View in source") [Ⓣ][1] +### `_.pluck(collection, prop)` +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L4089 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the collection. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `property` *(string)*: The name of the property to pluck. +2. `prop` *(string)*: The name of the property to pluck. #### Returns *(Array)*: Returns a new array of property values. @@ -4019,7 +4019,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.now` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6439 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6440 "View in source") [Ⓣ][1] *(unknown)*: Gets the number of milliseconds that have elapsed since the Unix epoch *(1 January `1970 00`:00:00 UTC)*. @@ -4154,9 +4154,9 @@ _.identity(object) === object; ### `_.match(props)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6293 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6294 "View in source") [Ⓣ][1] -Creates a "_.where" style function, which returns `true` for a given object if it has the equivalent property values of the `props` object, else `false`. +Creates a "_.where" style function, which performs a deep comparison between a given object and the `props` object, returning `true` if the given object has equivalent property values, else `false`. #### Arguments 1. `props` *(Object)*: The object of property values to match. @@ -4188,7 +4188,7 @@ _.find(characters, matchAge); ### `_.mixin([object=lodash], source, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6349 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6350 "View in source") [Ⓣ][1] Adds function properties of a source object to the destination object. If `object` is a function methods will be added to its prototype as well. @@ -4224,7 +4224,7 @@ _('fred').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6405 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6406 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -4244,7 +4244,7 @@ var lodash = _.noConflict(); ### `_.noop()` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6422 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6423 "View in source") [Ⓣ][1] A no-operation function. @@ -4263,7 +4263,7 @@ _.noop(object) === undefined; ### `_.parseInt(value, [radix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6463 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6464 "View in source") [Ⓣ][1] Converts the given value into an integer of the specified radix. If `radix` is `undefined` or `0` a `radix` of `10` is used unless the `value` is a hexadecimal, in which case a `radix` of `16` is used. @@ -4290,7 +4290,7 @@ _.parseInt('08'); ### `_.property(key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6492 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6493 "View in source") [Ⓣ][1] Creates a "_.pluck" style function, which returns the `key` value of a given object. @@ -4324,7 +4324,7 @@ _.sortBy(characters, getName); ### `_.random([min=0], [max=1], [floating=false])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6525 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6526 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is provided a number between `0` and the given number will be returned. If `floating` is truey or either `min` or `max` are floats a floating-point number will be returned instead of an integer. @@ -4359,7 +4359,7 @@ _.random(1.2, 5.2); ### `_.result(object, key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6583 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6584 "View in source") [Ⓣ][1] Resolves the value of property `key` on `object`. If `key` is a function it will be invoked with the `this` binding of `object` and its result returned, else the property value is returned. If `object` is falsey then `undefined` is returned. @@ -4412,7 +4412,7 @@ Create a new `lodash` function using the given context object. ### `_.template(text, data, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6677 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -4504,7 +4504,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.times(n, callback, [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6799 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6800 "View in source") [Ⓣ][1] Executes the callback `n` times, returning an array of the results of each callback execution. The callback is bound to `thisArg` and invoked with one argument; *(index)*. @@ -4536,7 +4536,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6829 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6830 "View in source") [Ⓣ][1] The inverse of `_.escape`; this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -4562,7 +4562,7 @@ _.unescape('Fred, Barney & Pebbles'); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6853 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L6854 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is provided the ID will be appended to it. @@ -4615,7 +4615,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7176 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/master/lodash.js#L7177 "View in source") [Ⓣ][1] *(string)*: The semantic version number. diff --git a/lodash.js b/lodash.js index f51586308..f893ccf3f 100644 --- a/lodash.js +++ b/lodash.js @@ -4126,7 +4126,7 @@ var index = -1, length = collection.length; - if (noaccum) { + if (noaccum && length) { accumulator = collection[++index]; } while (++index < length) { diff --git a/test/test.js b/test/test.js index a1719c0ae..116b4afae 100644 --- a/test/test.js +++ b/test/test.js @@ -6367,6 +6367,20 @@ var actual = func([], noop, undefined); strictEqual(actual, undefined); }); + + test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is provided (test in IE > 9 and modern browsers)', 2, function() { + var array = [], + object = { '0': 1, 'length': 0 }; + + if ('__proto__' in array) { + array.__proto__ = object; + strictEqual(_.reduce(array, noop), undefined); + } + else { + skipTest(); + } + strictEqual(_.reduce(object, noop), undefined); + }); }); /*--------------------------------------------------------------------------*/