00001 var compareAscending = require('./_compareAscending');
00002
00017 function compareMultiple(object, other, orders) {
00018 var index = -1,
00019 objCriteria = object.criteria,
00020 othCriteria = other.criteria,
00021 length = objCriteria.length,
00022 ordersLength = orders.length;
00023
00024 while (++index < length) {
00025 var result = compareAscending(objCriteria[index], othCriteria[index]);
00026 if (result) {
00027 if (index >= ordersLength) {
00028 return result;
00029 }
00030 var order = orders[index];
00031 return result * (order == 'desc' ? -1 : 1);
00032 }
00033 }
00034
00035
00036
00037
00038
00039
00040
00041 return object.index - other.index;
00042 }
00043
00044 module.exports = compareMultiple;