mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Remove odd string support from createExtremum.
This commit is contained in:
@@ -3461,18 +3461,11 @@
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
}
|
||||
var callback = getCallback(),
|
||||
noIteratee = iteratee == null,
|
||||
isArr = isArray(collection);
|
||||
|
||||
iteratee = (noIteratee && callback === baseCallback && !isArr && isString(collection))
|
||||
? charAtCallback
|
||||
: callback(iteratee, thisArg, 3);
|
||||
|
||||
if (noIteratee || (isArr && iteratee.length == 1)) {
|
||||
collection = isArr ? collection : toIterable(collection);
|
||||
iteratee = getCallback(iteratee, thisArg, 3);
|
||||
if (iteratee.length == 1) {
|
||||
collection = toIterable(collection);
|
||||
var result = arrayExtremum(collection, iteratee, comparator, exValue);
|
||||
if (noIteratee || !(collection.length && result === exValue)) {
|
||||
if (!(collection.length && result === exValue)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
15
test/test.js
15
test/test.js
@@ -11076,26 +11076,19 @@
|
||||
strictEqual(actual, isMax ? 3 : 1);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should iterate a string', 2, function() {
|
||||
_.each(['abc', Object('abc')], function(value) {
|
||||
var actual = func(value);
|
||||
strictEqual(actual, isMax ? 'c' : 'a');
|
||||
});
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work with extremely large arrays', 1, function() {
|
||||
var array = _.range(0, 5e5);
|
||||
strictEqual(func(array), isMax ? 499999 : 0);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', 3, function() {
|
||||
test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', 2, function() {
|
||||
var arrays = [[2, 1], [5, 4], [7, 8]],
|
||||
objects = [{ 'a': 2, 'b': 1 }, { 'a': 5, 'b': 4 }, { 'a': 7, 'b': 8 }],
|
||||
expected = isMax ? [2, 5, 8] : [1, 4, 7];
|
||||
|
||||
deepEqual(_.map(arrays, func), expected);
|
||||
deepEqual(_.map(objects, func), expected);
|
||||
deepEqual(_.map('abc', func), ['a', 'b', 'c']);
|
||||
_.each([arrays, objects], function(values) {
|
||||
deepEqual(_.map(values, func), expected);
|
||||
});
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work when chaining on an array with only one value', 1, function() {
|
||||
|
||||
Reference in New Issue
Block a user