TypeScript Count Factors
function countFactors(n: number): number {
  let count = 0;
  let i = 1;
  while (i * i < n) {
    if (n % i === 0) {
      count += 2;
    }
    i++;
  }
  if (i * i === n) {
    ++count;
  }

  return count;
}

This checks divisors in pairs up to the square root, which keeps the work much smaller than testing every number.