https://leetcode.com/problems/sort-array-by-increasing-frequency/



Runtime: 136 ms, faster than 29.17% of TypeScript online submissions for Sort Array by Increasing Frequency.

Memory Usage: 45.7 MB, less than 37.50% of TypeScript online submissions for Sort Array by Increasing Frequency.



```typescript
function frequencySort(nums: number[]): number[] {
    //8:17
    const theMap = new Map()
    for (const num of nums) {
        if (theMap.has(num)) {
            theMap.set(num, theMap.get(num) + 1)
        } else {
            theMap.set(num, 1)
        }
    }
    
    const keys = [ ...theMap.keys() ]
    keys.sort((a,b) => (theMap.get(a)-theMap.get(b)) || (b-a))
    
    let result = []
    for (const key of keys) {
        const subArray = []
        for(var i = 0; i< theMap.get(key); ++i){
          subArray.push(key);
        }
        result = result.concat(subArray)
    }
    return result
    //8:22
    //debug until 8:26, this is how you do two fieids sorting in js
};
```
