PriorityQueue custom comparator broken

249
Dec 11, 2021

Please fix custom comparator from Priority Queue class. I was trying to solve the fourth contest problem today and ran into this error: There is a serious shortcoming of JS in solving contest problems or PQ problems in general.

image

I took this directly from the documentation on GitHub:

https://github.com/datastructures-js/priority-queue

// empty queue with comparator
const employeesQueue = new PriorityQueue({
  compare: (e1, e2) => {
    if (e1.salary > e2.salary) return -1; // do not swap
    if (e1.salary < e2.salary) return 1; // swap

    // salaries are the same, compare rank
    return e1.rank < e2.rank ? 1 : -1;
  }
});
Comments (1)