// first criteria: the edit distance if (score > a.score) { return 1; } if (score < a.score) { return -1; } // second criteria (if first criteria is equal): the popularity if (freq > a.freq) { return 1; } if (freq < a.freq) { return -1; } return 0;