artdaq_node_server  v1_00_08
 All Classes Namespaces Files Variables Pages
_compareMultiple.js
1 var compareAscending = require('./_compareAscending');
2 
17 function compareMultiple(object, other, orders) {
18  var index = -1,
19  objCriteria = object.criteria,
20  othCriteria = other.criteria,
21  length = objCriteria.length,
22  ordersLength = orders.length;
23 
24  while (++index < length) {
25  var result = compareAscending(objCriteria[index], othCriteria[index]);
26  if (result) {
27  if (index >= ordersLength) {
28  return result;
29  }
30  var order = orders[index];
31  return result * (order == 'desc' ? -1 : 1);
32  }
33  }
34  // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
35  // that causes it, under certain circumstances, to provide the same value for
36  // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
37  // for more details.
38  //
39  // This also ensures a stable sort in V8 and other engines.
40  // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
41  return object.index - other.index;
42 }
43 
44 module.exports = compareMultiple;