Remove odd string support from createExtremum.

This commit is contained in:
jdalton
2015-05-07 23:53:38 -07:00
parent a1b15df648
commit 004aaed783
2 changed files with 8 additions and 22 deletions

View File

@@ -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;
}
}

View File

@@ -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() {