From 004aaed7830509c8b002e9c340383675f6d088d6 Mon Sep 17 00:00:00 2001 From: jdalton Date: Thu, 7 May 2015 23:53:38 -0700 Subject: [PATCH] Remove odd string support from `createExtremum`. --- lodash.src.js | 15 ++++----------- test/test.js | 15 ++++----------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 5799da8ef..b62e11d33 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -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; } } diff --git a/test/test.js b/test/test.js index 3802fb859..0c44d211b 100644 --- a/test/test.js +++ b/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() {