• Why does this not work on checkIO?

Question related to mission The Most Wanted Letter

 
function mostWanted(text: string): string {

  let dict = {};

  // create an object with the count

  for (const letter of text.toLowerCase()) {
    if (letter.match(/[a-z]/i)) {
      dict[letter] ? (dict[letter] += 1) : (dict[letter] = 1);
    }
  }

  // Sort the object by Value AND Key
  const sortedObj = Object.entries(dict).sort(function (a, b) {

    //rename the key and value(count) for easier read
    const keyA = a[0];
    const keyB = b[0];
    const countA = a[1];
    const countB = b[1];

    if (countB > countA) {
      return 1;
    }
    if (keyB < keyA && countB >= countA) {
      return 1;
    }
  });


console.log(sortedObj)
  return sortedObj[0][0];
}

From: https://js.checkio.org/mission/the-most-wanted-letter/solve/

HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36