![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Missing letter from strings in 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
Therefore, let’s write the code for this function −
Example
The code for this will be −
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
The output in the console will be −
i
Advertisements