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:

JavaScript
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

Similar Reads

Using Set

In this approach, we use the Set in JavaScript to create the characters from the input string and remove the duplicate, and then go through the alphabet characters. Each alphabet letter is been checked if it is present in the Set. If it is not present then we add it to the output variable and printing it....

Using includes() Method

In this approach, we are using the includes() method. Here we have used the for loop to go through the each character of the letter variable. For every letter, we are checking if the character is present in the inputStr variable using the includes() method. If the character is not present, then it is added in the output variable and printed....

Using indexOf() Method

In this apporach, we are using the indexOf() method. Here, we have used the for loop to go through the chacter-by-character of the letters string. Every character, we check if the letters variable cgacater exists in the input string using indexOf() method. If the chactaer is found then it is been ignored, if it is not found then the character is added in the output string....

Using a Map

Using a Map to find missing characters for a pangram involves initializing a map for all alphabet letters, updating it with characters from the string, and then collecting keys from the map with zero occurrences....

Using Set and Range of ASCII Values

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....