Priority queues in JavaScript