From 9ca16e393357b84e513b4c6008583968ef550729 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 16 Jul 2015 09:40:52 -0700 Subject: [PATCH] Rename `baseCompareAscending` to `compareAscending`. --- lodash.src.js | 70 +++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 171a5e78f..3f9dcc1f9 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -277,39 +277,6 @@ /*--------------------------------------------------------------------------*/ - /** - * The base implementation of `compareAscending` which compares values and - * sorts them in ascending order without guaranteeing a stable sort. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {number} Returns the sort order indicator for `value`. - */ - function baseCompareAscending(value, other) { - if (value !== other) { - var valIsNull = value === null, - valIsUndef = value === undefined, - valIsReflexive = value === value; - - var othIsNull = other === null, - othIsUndef = other === undefined, - othIsReflexive = other === other; - - if ((value > other && !othIsNull) || !valIsReflexive || - (valIsNull && !othIsUndef && othIsReflexive) || - (valIsUndef && othIsReflexive)) { - return 1; - } - if ((value < other && !valIsNull) || !othIsReflexive || - (othIsNull && !valIsUndef && valIsReflexive) || - (othIsUndef && valIsReflexive)) { - return -1; - } - } - return 0; - } - /** * The base implementation of `_.findIndex` and `_.findLastIndex` without * support for callback shorthands. @@ -427,16 +394,35 @@ } /** - * Used by `_.sortBy` to compare transformed elements of a collection and stable - * sort them in ascending order. + * Compares values to sort them in ascending order. * * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @returns {number} Returns the sort order indicator for `object`. + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {number} Returns the sort order indicator for `value`. */ - function compareAscending(object, other) { - return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index); + function compareAscending(value, other) { + if (value !== other) { + var valIsNull = value === null, + valIsUndef = value === undefined, + valIsReflexive = value === value; + + var othIsNull = other === null, + othIsUndef = other === undefined, + othIsReflexive = other === other; + + if ((value > other && !othIsNull) || !valIsReflexive || + (valIsNull && !othIsUndef && othIsReflexive) || + (valIsUndef && othIsReflexive)) { + return 1; + } + if ((value < other && !valIsNull) || !othIsReflexive || + (othIsNull && !valIsUndef && valIsReflexive) || + (othIsUndef && valIsReflexive)) { + return -1; + } + } + return 0; } /** @@ -461,7 +447,7 @@ ordersLength = orders.length; while (++index < length) { - var result = baseCompareAscending(objCriteria[index], othCriteria[index]); + var result = compareAscending(objCriteria[index], othCriteria[index]); if (result) { if (index >= ordersLength) { return result; @@ -4823,7 +4809,7 @@ indexes = baseFlatten(indexes); var result = baseAt(array, indexes); - basePullAt(array, indexes.sort(baseCompareAscending)); + basePullAt(array, indexes.sort(compareAscending)); return result; });