sort files
@param  {object} a first element
@param  {object} b second element
559617
function sortFiles (a, b) {
  if (a.type === b.type) {
    if (a.file === b.file) {
      var ai = a.start || a.mtime || a.index
      var bi = b.start || b.mtime || b.index
      if (sort === 'desc') {
        return parseFloat(bi) - parseFloat(ai)
      } else {
        return parseFloat(ai) - parseFloat(bi)
      }
    } else {
      var ai = a.mtime || a.index
      var bi = b.mtime || b.index
      if (sort === 'desc') {
        return parseFloat(bi) - parseFloat(ai)
      } else {
        return parseFloat(ai) - parseFloat(bi)
      }
    }
  } else {
    var order = [1, 2, 0]
    return order[b.type] - order[a.type]
  }
}
694137
function fileSort(a, b) {
  return Number(b.stat && b.stat.isDirectory()) - Number(a.stat && a.stat.isDirectory()) ||
    String(a.name).toLocaleLowerCase().localeCompare(String(b.name).toLocaleLowerCase());
}
737832
function compSort(p1, p2) {
    if (p1[0] > p2[0]) {
      return -1;
    } else if (p1[0] < p2[0]) {
      return 1;
    } else if (p1[1] > p2[1]) {
      return -1;
    } else if (p1[1] < p2[1]) {
      return 1;
    } else {
      return 0;
    }
  }
203393
function byPriority(a, b) {
      var diff = b.priority - a.priority;
      if (diff !== 0) return diff;
      if (a.name !== b.name) return (a.name < b.name) ? -1 : 1;
      return a.index - b.index;
    }
61447
function(arr) {
  arr = arr.sort((a, b) => {
    if (a.index > b.index) {
      return 1;
    }
    if (a.index === b.index) {
      return 0;
    }
    return -1;
  });
  //return ts objects
  return arr.map((o) => o.ts);
}
651620
function sortByIdentifiersCount(a, b) {
  if (a.count === b.count) {
    return stringCompare(a.value, b.value)
  }

  return b.count - a.count
}
423708
function compareFilesWithIndices(index1, index2) {
                return entries[index1]._name.toLocaleLowerCase().localeCompare(entries[index2]._name.toLocaleLowerCase());
            }
545478
function one(_, results) {
      /* istanbul ignore else - always given. */
      if (results) {
        files = files.concat(results)
      }

      actual++

      if (actual === expected) {
        next(null, files)
      }
    }
1192834
function compareIndex(nodeA, nodeB) {
  var indexA = nodeA && nodeA.sortIndex;
  var indexB = nodeB && nodeB.sortIndex;
  if (!indexA && !indexB) {
    return 0;
  }
  else if (Boolean(indexA) !== Boolean(indexB)) {
    return indexA ? +1 : indexB ? -1 : 0;
  }
  else {
    return indexA - indexB;
  }
}
703654
public static Array<FileHandle> sortFiles (FileHandle[] files, Comparator<FileHandle> comparator) {
		return sortFiles(files, comparator, false);
	}
500862
function sortByDate(a, b) {
    return new Date(a.added).getTime() - new Date(b.added).getTime();
  }
574239
public static void deleteFirst(@NonNull File[] files, @NonNull Comparator<File> sortedBy, int numFiles) {
    Arrays.sort(files, sortedBy);
    int size = Math.min(files.length, numFiles);
    for (int i = 0; i < size; i++) {
      if (!files[i].delete()) {
        Log.w(LOG_TAG, "Failed to delete file: " + files[i]);
      }
    }
  }
672980
function sortFn(a, b) {
    var apct = getWeightedPercent(a);
    var bpct = getWeightedPercent(b);
    var diff = apct - bpct;

    if (diff === 0) {
      return ascending(a.id(), b.id()); // make sure sort doesn't have don't-care comparisons
    } else {
      return diff;
    }
  }
456931
function(data, type) {
			var defsorter = { name: true, perm: true, date: true,  size: true, kind: true },
				sorterChk = !self.sorters._checked,
				l         = data.length,
				setSorter = function(file) {
					var f = file || {},
						sorters = [];
					$.each(self.sortRules, function(key) {
						if (defsorter[key] || typeof f[key] !== 'undefined' || (key === 'mode' && typeof f.perm !== 'undefined')) {
							sorters.push(key);
						}
					});
					self.sorters = self.arrayFlip(sorters, true);
					self.sorters._checked = true;
				},
				keeps = ['sizeInfo'],
				changedParents = {},
				f, i, keepProp, parents;

			for (i = 0; i < l; i++) {
				f = Object.assign({}, data[i]);
				if (f.name && f.hash && f.mime) {
					if (sorterChk && f.phash === cwd) {
						setSorter(f);
						sorterChk = false;
					}
					
					if (f.phash && (type === 'add' || type === 'change')) {
						if (parents = self.parents(f.phash)) {
							$.each(parents, function() {
								changedParents[this] = true;
							});
						}
					}
					
					if (files[f.hash]) {
						$.each(keeps, function() {
							if(files[f.hash][this] && ! f[this]) {
								f[this] = files[f.hash][this];
							}
						});
						if (f.sizeInfo && !f.size) {
							f.size = f.sizeInfo.size;
						}
						deleteCache(files[f.hash], true);
					}
					files[f.hash] = f;
					if (f.mime === 'directory' && !ownFiles[f.hash]) {
						ownFiles[f.hash] = {};
					}
					if (f.phash) {
						if (!ownFiles[f.phash]) {
							ownFiles[f.phash] = {};
						}
						ownFiles[f.phash][f.hash] = true;
					}
				} 
			}
			// delete sizeInfo cache
			$.each(Object.keys(changedParents), function() {
				var target = files[this];
				if (target && target.sizeInfo) {
					delete target.sizeInfo;
				}
			});
			
			// for empty folder
			sorterChk && setSorter();
		}
1157899
protected static function sortFileList(array $a, array $b)
  {
    if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b))
    {
      return 0;

      throw new Exception("invalid parameter", 0x602);
    }
    
    if($a["type"] != $b["type"])
    {
      return ($a["type"] < $b["type"]) ? -1 : 1;
    }

    return strcmp(strtolower($a["src"]), strtolower($b["src"]));
  }
774759
function compareAscending(a, b) {
  var ai = a.idx,
      bi = b.idx;

  a = a.criteria;
  b = b.criteria;

  // ensure a stable sort in V8 and other engines
  // http://code.google.com/p/v8/issues/detail?id=90
  if (a !== b) {
    if (a > b || typeof a === 'undefined') {
      return 1;
    }
    /*istanbul ignore next*/
    if (a < b || typeof b === 'undefined') {
      return -1;
    }
  }

  /*istanbul ignore next*/
  return ai < bi ? -1 : 1;
}
799786
function mongoCompare(a, b) {
  // TODO:  maybe faster to write this as a switch off of "typeof a/b" ?

  if (a === undefined) {
    if (b === undefined) {
      return 0;
    }

    return -1;
  } else if (b === undefined) {
    return 1;
  }

  if (a === null) {
    if (b === null) {
      return 0;
    }

    return -1;
  } else if (b === null) {
    return 1;
  }

  if (_.isNumber(a)) {
    if (_.isNumber(b)) {
      return a - b;
    }

    return -1;
  } else if (_.isNumber(b)) {
    return 1;
  }

  if (_.isString(a)) {
    if (_.isString(b)) {
      return a.localeCompare(b);
    }

    return -1;
  } else if (_.isString(b)) {
    return 1;
  }

  if (_.isObject(a) && !_.isDate(a)) {
    if (_.isObject(b) && !_.isDate(b)) {
      if (_.isEmpty(a)) {
        return _.isEmpty(b) ? 0 : -1;
      } else if (_.isEmpty(b)) {
        return 1;
      }

      for (const key of _.union(_.keys(a), _.keys(b)).sort()) {
        const av = a[key],
          bv = b[key];

        if (av === undefined) {
          return 1;
        } else if (bv === undefined) {
          return -1;
        }

        const v = mongoCompare(av, bv);

        if (v) {
          return v;
        }
      }

      return 0;
    }

    return -1;
  } else if (_.isObject(b) && !_.isDate(b)) {
    return 1;
  }

  if (_.isDate(a)) {
    if (_.isDate(b)) {
      return a.valueOf() - b.valueOf();
    }

    return -1;
  } else if (_.isDate(b)) {
    return 1;
  }

  // TODO:  what other cases are not being handled?
  if (a < b) {
    return -1;
  } else if (a > b) {
    return 1;
  }

  return 0;
}