From 1423dcb619477920067a34a950f4106beeb9832f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 20 Aug 2014 01:24:33 -0700 Subject: [PATCH] `_.sortBy` should not error on nullish elements when sorting by multiple properties. --- lodash.js | 2 +- test/test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 9957c7bcd..a22315ea8 100644 --- a/lodash.js +++ b/lodash.js @@ -5656,7 +5656,7 @@ criteria = Array(length); while (length--) { - criteria[length] = value[iteratee[length]]; + criteria[length] = value == null ? undefined : value[iteratee[length]]; } } else { criteria = iteratee(value, key, collection); diff --git a/test/test.js b/test/test.js index 51af1b1a2..1b5339bd0 100644 --- a/test/test.js +++ b/test/test.js @@ -9755,6 +9755,11 @@ deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]); }); + test('should not error on nullish elements when sorting by multiple properties', 1, function() { + var actual = _.sortBy(objects.concat(undefined), ['a', 'b']); + deepEqual(actual, [objects[2], objects[0], objects[3], objects[1], undefined]); + }); + test('should perform a stable sort when sorting by multiple properties (test in IE > 8, Opera, and V8)', 1, function() { var actual = _.sortBy(stableOrder, ['a', 'c']); deepEqual(actual, stableOrder);