How to use Set and Range of ASCII Values In Javascript
In this approach, we utilize a set to keep track of characters present in the input string. We iterate through the input string and add each character to the set. Then, we iterate through a range of ASCII values representing lowercase alphabets (97 to 122), checking if each character exists in the set. If not found, it is considered missing and added to the output string.
Example:
function findMissingChars(inputStr) {
let missingChars = '';
const charSet = new Set(inputStr.toLowerCase());
// Iterate through ASCII range of lowercase alphabets
for (let ascii = 97; ascii <= 122; ascii++) {
const char = String.fromCharCode(ascii);
if (!charSet.has(char)) {
missingChars += char;
}
}
return missingChars;
}
const inputStr = "welcome to w3wiki";
console.log(findMissingChars(inputStr)); // Output: abdhijnpquvxyz
Output
abdhijnpquvxyz
JavaScript Program to Find Missing Characters to Make a String Pangram
We have given an input string and we need to find all the characters that are missing from the input string. We have to print all the output in the alphabetic order using JavaScript language. Below we have added the examples for better understanding.
Examples:
Input : welcome to w3wiki
Output : abdhijnpquvxyz
Input : The quick brown fox jumps
Output : adglvyz
Table of Content
- Using Set
- Using includes() Method
- Using indexOf() Method
- Using a Map
- Using Set and Range of ASCII Values