Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Finding missing letter in a string - JavaScript
We have a string of length m that contains first m letters of the English alphabets, but somehow, one element went missing from the string. So, now the string contains,
m-1 letters
We are required to write a function that takes in one such string and returns the missing element from the string
Example
Following is the code −
const str = "acdghfbekj";
const missingCharacter = str => {
// to make the function more consistent
const s = str.toLowerCase();
for(let i = 97; ; i++){
if(s.includes(String.fromCharCode(i))){
continue;
};
return String.fromCharCode(i);
};
return false;
};
console.log(missingCharacter(str));
Output
Following is the output in the console −
i
Advertisements
