Rename baseCompareAscending to compareAscending.

This commit is contained in:
John-David Dalton
2015-07-16 09:40:52 -07:00
parent 76ab41a742
commit 9ca16e3933

View File

@@ -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 * The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for callback shorthands. * support for callback shorthands.
@@ -427,16 +394,35 @@
} }
/** /**
* Used by `_.sortBy` to compare transformed elements of a collection and stable * Compares values to sort them in ascending order.
* sort them in ascending order.
* *
* @private * @private
* @param {Object} object The object to compare. * @param {*} value The value to compare.
* @param {Object} other The other object to compare. * @param {*} other The other value to compare.
* @returns {number} Returns the sort order indicator for `object`. * @returns {number} Returns the sort order indicator for `value`.
*/ */
function compareAscending(object, other) { function compareAscending(value, other) {
return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index); 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; ordersLength = orders.length;
while (++index < length) { while (++index < length) {
var result = baseCompareAscending(objCriteria[index], othCriteria[index]); var result = compareAscending(objCriteria[index], othCriteria[index]);
if (result) { if (result) {
if (index >= ordersLength) { if (index >= ordersLength) {
return result; return result;
@@ -4823,7 +4809,7 @@
indexes = baseFlatten(indexes); indexes = baseFlatten(indexes);
var result = baseAt(array, indexes); var result = baseAt(array, indexes);
basePullAt(array, indexes.sort(baseCompareAscending)); basePullAt(array, indexes.sort(compareAscending));
return result; return result;
}); });