From a46ef8d1a6b78c1fdaef978434c25c5c51489883 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 6 Jun 2013 09:07:14 -0700 Subject: [PATCH] When chaining, _.max and _.min should resolve the correct value when passed an array containing only one value. [closes #292] Former-commit-id: 79c71c1851a73c23919a28aadd56490ded91166c --- lodash.js | 10 +++++----- test/test.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index bf345287b..dd05e0e4c 100644 --- a/lodash.js +++ b/lodash.js @@ -217,7 +217,7 @@ typeCache = cache[type] || (cache[type] = {}); if (type == 'object') { - if ((typeCache[key] || (typeCache[key] = [])).push(value) === this.array.length) { + if ((typeCache[key] || (typeCache[key] = [])).push(value) == this.array.length) { cache[type] = false; } } else { @@ -3661,7 +3661,7 @@ seen = concat.apply(arrayProto, nativeSlice.call(arguments, 1)), result = []; - var isLarge = length >= largeArraySize && indexOf == basicIndexOf; + var isLarge = length >= largeArraySize && indexOf === basicIndexOf; if (isLarge) { var cache = createCache(seen); @@ -3994,7 +3994,7 @@ while (++argsIndex < argsLength) { var value = argsIndex ? args[argsIndex] : seen; - caches[argsIndex] = indexOf == basicIndexOf && (value && value.length) >= largeArraySize && createCache(value); + caches[argsIndex] = indexOf === basicIndexOf && (value && value.length) >= largeArraySize && createCache(value); } outer: while (++index < length) { @@ -4394,7 +4394,7 @@ length = array ? array.length : 0, result = []; - var isLarge = !isSorted && length >= largeArraySize && indexOf == basicIndexOf, + var isLarge = !isSorted && length >= largeArraySize && indexOf === basicIndexOf, seen = (callback || isLarge) ? getArray() : result; if (isLarge) { @@ -5196,7 +5196,7 @@ push.apply(args, arguments); var result = func.apply(lodash, args); - return (value && typeof value == 'object' && value == result) + return (value && typeof value == 'object' && value === result) ? this : new lodashWrapper(result); }; diff --git a/test/test.js b/test/test.js index f61a5fea0..2dc8116ec 100644 --- a/test/test.js +++ b/test/test.js @@ -2004,6 +2004,17 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.max and lodash.min chaining'); + + _.each(['max', 'min'], function(methodName) { + test('lodash.' + methodName + ' should resolve the correct value when passed an array containing only one value', function() { + var actual = _([40])[methodName]().value(); + strictEqual(actual, 40); + }); + }); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.memoize'); (function() {