SOURCE

// console.log(580+'0'-10)
// console.log(1<2<3, 2<3<1)
// console.log({}==!{})

//
// function isPrime(num){
//     // 不是数字或者数字小于2
//     if(typeof num !== "number" || !Number.isInteger(num)){      // Number.isInterget 判断是否为整数
//         return false;
//     }

//     //2是质数
//     if(num == 2){
//         return true; 
//     }else if(num % 2 == 0){  //排除偶数
//         return false;
//     }
//     //依次判断是否能被奇数整除,最大循环为数值的开方
//     var squareRoot = Math.sqrt(num);
//     //因为2已经验证过,所以从3开始;且已经排除偶数,所以每次加2
//     for(var i = 3; i <= squareRoot; i += 2) {
//       if (num % i === 0) {
//          return false;
//       }
//     }
//     return true;
// }
// console.log(isPrime(-1))

function minDeletions(s) {

  let charFrequency = new Map(), used = new Set(), res = 0;
  //Iterate through all the characters & store the char along with frequency in map
  for(const char of s){
      //If the character is already present in map, increment the frequency
      if(charFrequency.has(char)){
          charFrequency.set(char, charFrequency.get(char)+1);
          }
      //If the character is not present, add it to map with frequency set to 1
      else
          charFrequency.set(char, 1);
  }
  //Now iterate through the Map created in above steps
  for(let [char, freq] of charFrequency.entries()){
      //Check if the frequency is already present for any other character, decrement the frequency till it reaches either a frequency which is not used already or 0 (because if frequency reaches 0 the character is no more present) 
      //Meanwhile increment the 'res', so we will get to know the count of deletions required
      while(used.has(freq) && freq > 0){
          freq--;
          res++;
      }
      //Add the frequency to the set 'used', so for the next characters we can check the already used frequency
      used.add(freq);
  }
  return res;
};

s = [1,2,3,4,5,2,2]
console.log(minDeletions(s));
console 命令行工具 X clear

                    
>
console