SOURCE

function frequencySort_bak(nums: number[]): number[] {
    nums.sort((a, b)=>{return b - a});
    let total = [];
    let local = [];
    let end = [];
    let count = 1;
    let count_2 = 1;
    for(let i=0;i<nums.length;i++){
        if(nums[i]==nums[i+1]){
            count++;
            local.push(nums[i]);
        }else{
            local.push(nums[i]);
            total.push(local);
            local = []
            count;
            for(let j=0;j<nums.length;j++){
                if(i>0&&nums[i]==nums[i-1]){
                    if(count_2>count){
                        
                    }
                }else{
                    count_2++;
                }
            }
        }
      
        // local = [];
    }
    for(let i=0;i<total.length;i++){
        for(let j=0;j<total.length;j++){
            if(total[j].length-total[i].length>0){
                let temp = total[j];
                total[j]= total[i];
                total[i]= temp;
            }else if(total[j].length-total[i].length==0){
                if(total[j][0]-total[i][0]<0){
                    let temp = total[j];
                    total[j]= total[i];
                    total[i]= temp;
                }
            }
        }   
    }
    return total.flat(2)
};

function frequencySort(num: string): boolean {
    let map: Map<number, number> = new Map();
    for (const num of nums) {
        map.set(num, map.has(num) ? map.get(num) + 1 : 1);
    }
    const compareFn = (a: number, b: number): number => {
        return map.get(a) !== map.get(b) ? map.get(a) - map.get(b) : b - a;
    }
    return nums.sort(compareFn);
};

console.log(frequencySort([-1,1,-6,4,5,-6,1,4,1]))
console.log(frequencySort([1,1,2,2,2,3]))
console 命令行工具 X clear

                    
>
console