1
var FoodRatings = function (foods, cuisines, ratings) {2
(this.heaps = {}), (this.foods = {});4
for (let i = 0; i < n; i++) {8
if (!this.heaps[cuisine])9
this.heaps[cuisine] = new PriorityQueue((a, b) => {11
return a[1] === b[1] ? a[0].localeCompare(b[0]) : b[1] - a[1];13
this.heaps[cuisine].add([food, rating]);14
this.foods[food] = { cuisine, rating };18
FoodRatings.prototype.changeRating = function (food, newRating) {19
this.foods[food].rating = newRating;20
let { cuisine } = this.foods[food];21
this.heaps[cuisine].add([food, newRating]);24
FoodRatings.prototype.highestRated = function (cuisine) {25
let heap = this.heaps[cuisine];26
while (this.foods[heap.top()[0]].rating !== heap.top()[1]) {33
constructor(comparator = (a, b) => a - b) {35
this.comparator = comparator;40
this.values.push(val);41
let idx = this.size - 1,42
parentIdx = Math.floor((idx - 1) / 2);45
this.comparator(this.values[parentIdx], this.values[idx]) > 047
[this.values[parentIdx], this.values[idx]] = [49
this.values[parentIdx],52
parentIdx = Math.floor((idx - 1) / 2);56
if (this.size === 0) return -1;58
if (this.size === 0) return this.values.pop();59
let removedVal = this.values[0];60
this.values[0] = this.values.pop();62
while (idx < this.size && idx < Math.floor(this.size / 2)) {63
let leftIdx = idx * 2 + 1,64
rightIdx = idx * 2 + 2;65
if (rightIdx === this.size) {66
if (this.comparator(this.values[leftIdx], this.values[idx]) > 0) break;67
[this.values[leftIdx], this.values[idx]] = [73
this.comparator(this.values[leftIdx], this.values[idx]) < 0 ||74
this.comparator(this.values[rightIdx], this.values[idx]) < 076
if (this.comparator(this.values[leftIdx], this.values[rightIdx]) <= 0) {77
[this.values[leftIdx], this.values[idx]] = [83
[this.values[rightIdx], this.values[idx]] = [85
this.values[rightIdx],96
return this.values[0];99
return this.size === 0;