Ensure _.min and _.max can be used as the callback of _.map. [closes #379]

This commit is contained in:
John-David Dalton
2013-10-29 09:32:40 -07:00
parent 3fa2e7e12e
commit ac8f8d0dd6
8 changed files with 156 additions and 100 deletions

31
dist/lodash.compat.js vendored
View File

@@ -2900,6 +2900,7 @@
if (!isObject(object)) {
return object;
}
// allows working with `_.reduce` and `_.reduceRight` without using
// their `index` and `collection` arguments
if (typeof args[2] != 'number') {
@@ -3779,7 +3780,12 @@
var computed = -Infinity,
result = computed;
if (!callback && isArray(collection)) {
// allows working with functions like `_.map` without using
// their `index` argument as a callback
if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
callback = null;
}
if (callback == null && isArray(collection)) {
var index = -1,
length = collection.length;
@@ -3790,7 +3796,7 @@
}
}
} else {
callback = (!callback && isString(collection))
callback = (callback == null && isString(collection))
? charAtCallback
: lodash.createCallback(callback, thisArg, 3);
@@ -3849,7 +3855,12 @@
var computed = Infinity,
result = computed;
if (!callback && isArray(collection)) {
// allows working with functions like `_.map` without using
// their `index` argument as a callback
if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
callback = null;
}
if (callback == null && isArray(collection)) {
var index = -1,
length = collection.length;
@@ -3860,7 +3871,7 @@
}
}
} else {
callback = (!callback && isString(collection))
callback = (callback == null && isString(collection))
? charAtCallback
: lodash.createCallback(callback, thisArg, 3);
@@ -4034,8 +4045,8 @@
* @category Collections
* @param {Array|Object|string} collection The collection to sample.
* @param {number} [n] The number of elements to sample.
* @param- {Object} [guard] Allows working with functions, like `_.map`,
* without using their `key` and `object` arguments as sources.
* @param- {Object} [guard] Allows working with functions like `_.map`
* without using their `index` arguments as `n`.
* @returns {Array} Returns the random sample(s) of `collection`.
* @example
*
@@ -4577,7 +4588,7 @@
// juggle arguments
if (typeof isShallow != 'boolean' && isShallow != null) {
thisArg = callback;
callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : null;
callback = (typeof isShallow != 'function' && thisArg && thisArg[isShallow] === array) ? null : isShallow;
isShallow = false;
}
if (callback != null) {
@@ -4931,7 +4942,7 @@
end = start;
start = 0;
}
// use `Array(length)` so engines, like Chakra and V8, avoid slower modes
// use `Array(length)` so engines like Chakra and V8 avoid slower modes
// http://youtu.be/XAqIpGU8ZZk#t=17m25s
var index = -1,
length = nativeMax(0, ceil((end - start) / (step || 1))),
@@ -5192,7 +5203,7 @@
// juggle arguments
if (typeof isSorted != 'boolean' && isSorted != null) {
thisArg = callback;
callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : null;
callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted;
isSorted = false;
}
if (callback != null) {
@@ -6842,7 +6853,7 @@
// expose Lo-Dash
var _ = runInContext();
// some AMD build optimizers, like r.js, check for condition patterns like the following:
// some AMD build optimizers like r.js check for condition patterns like the following:
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
// Expose Lo-Dash to the global object even when an AMD loader is present in
// case Lo-Dash was injected by a third-party script and not intended to be