From 9e99a57615736d16351794426ec704931b163a11 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 18 Dec 2015 23:12:14 -0600 Subject: [PATCH] Make "asc" the default order of `_.orderBy`. --- lodash.js | 16 ++++++++-------- test/test.js | 9 +++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index efdbd0494..25d234ace 100644 --- a/lodash.js +++ b/lodash.js @@ -999,9 +999,9 @@ * Used by `_.orderBy` to compare multiple properties of a value to another * and stable sort them. * - * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise, - * a value is sorted in ascending order if its corresponding order is "asc", and - * descending if "desc". + * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, + * specify an order of "desc" for descending or "asc" for ascending sort order + * of corresponding values. * * @private * @param {Object} object The object to compare. @@ -1023,7 +1023,7 @@ return result; } var order = orders[index]; - return result * (order === 'asc' ? 1 : -1); + return result * (order === 'desc' ? -1 : 1); } } // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications @@ -7640,10 +7640,10 @@ } /** - * This method is like `_.sortBy` except that it allows specifying the - * sort orders of the iteratees to sort by. If `orders` is unspecified, all - * values are sorted in ascending order. Otherwise, a value is sorted in - * ascending order if its corresponding order is "asc", and descending if "desc". + * This method is like `_.sortBy` except that it allows specifying the sort + * orders of the iteratees to sort by. If `orders` is unspecified, all values + * are sorted in ascending order. Otherwise, specify an order of "desc" for + * descending or "asc" for ascending sort order of corresponding values. * * @static * @memberOf _ diff --git a/test/test.js b/test/test.js index c169c2b01..062bee68a 100644 --- a/test/test.js +++ b/test/test.js @@ -13536,8 +13536,13 @@ QUnit.test('should sort a property in ascending order when its order is not specified', function(assert) { assert.expect(1); - var actual = _.orderBy(objects, ['a', 'b'], ['desc']); - assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]); + var expected = lodashStable.map(falsey, lodashStable.constant([objects[3], objects[1], objects[2], objects[0]])); + + var actual = lodashStable.map(falsey, function(order, index) { + return _.orderBy(objects, ['a', 'b'], index ? ['desc', order] : ['desc']); + }); + + assert.deepEqual(actual, expected); }); }());