- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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