Easy to understand 2 order queue solution for javascript
NotesSeems like all the JavasScript solution out there is using outdated syntax. We need to use an external library unlike python. This is an answer that'll act
# Notes
Seems like all the JavasScript solution out there is using outdated syntax. We need to use an external library unlike python. This is an answer that'll actually pass.

# Approach
Maintain a max queue for buy orders (since we always want the highest price) and min queue for sell orders (since we always want the lowest price). As orders comes in

If it's a sell order
1. We compare the sell order to the buy order with the highest price
2. If the highest priced buy order has a higher price than the sell order, we execute however buy orders are available.
3. We continue the process until there are no more buy orders that meet the requirement (buyer price >= sell price).
4. Out of while loop, if there are still remaining sell orders, we add it to the queue.

If it's a buy order

- Same logic for buy order but instead of finding the highest price in seller queue, we are finding the lowest price in seller queue and see if the seller order is less than or equal to the buy order.

At the end we add up all the amounts in both queues and return

# Complexity
- Time complexity:
O(nlogn)

- Space complexity:
O(n)

# Code
```javascript []
/**
 * @param {number[][]} orders
 * @return {number}
 */
var getNumberOfBacklogOrders = function(orders) {
    const buyQueue = new MaxPriorityQueue((order) => order[0]);
    const sellQueue = new MinPriorityQueue((order) => order[0]);

    for (let order of orders) {
        let [price, amount, type] = order;
        if(type) {
            //sell
            while(!buyQueue.isEmpty() && (buyQueue.front()[0] >= price) && (amount > 0)) {
                let [buyPrice, buyAmount, buyType] = buyQueue.front();
                const minAmount = Math.min(buyAmount, amount);
                amount = amount - minAmount;
                buyQueue.front()[1] = buyAmount - minAmount;
                if(buyAmount === 0) {
                    buyQueue.dequeue();
                }
            }

            if(amount) {
                sellQueue.enqueue([price, amount, type]);
            }
        } else {
            //buy
            while(!sellQueue.isEmpty() && (sellQueue.front()[0] <= price) && (amount > 0)) {
                let [sellPrice, sellAmount, sellType] = sellQueue.front();
                const minAmount = Math.min(sellAmount, amount);
                amount = amount - minAmount;
                sellQueue.front()[1] = sellAmount - minAmount;
                if(sellAmount === 0) {
                    sellQueue.dequeue();
                }
            }

            if(amount) {
                buyQueue.enqueue([price, amount, type]);
            }
        }
    }
    let ans = 0;
    const mod = 1e9 + 7;
    for(let buyOrder of buyQueue) {
        ans = (ans + buyOrder[1])%mod
    }
    for(let sellOrder of sellQueue) {
        ans = (ans + sellOrder[1])%mod;
    }
    return ans;
};
```
['JavaScript']