How to find missing alphabet characters from a string in JavaScript

1 Answer

0 votes
function getMissingAlphabetChars(input) {
  // Track which letters appear
  const present = new Set();

  // Normalize: lowercase + keep only a–z
  for (const ch of input.toLowerCase()) {
    if (ch >= 'a' && ch <= 'z') {
      present.add(ch);
    }
  }

  // Collect missing letters
  const missing = [];
  for (let code = 97; code <= 122; code++) { // 'a'..'z'
    const letter = String.fromCharCode(code);
    if (!present.has(letter)) {
      missing.push(letter);
    }
  }

  return missing;
}

const missing = getMissingAlphabetChars("JavaScript Programming");
console.log(missing);



/*
run:

[
  'b', 'd', 'e', 'f',
  'h', 'k', 'l', 'q',
  'u', 'w', 'x', 'y',
  'z'
]

*/

 



answered Mar 7 by avibootz
...