
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine a Pangram String in JavaScript
Pangram strings:
A pangram is a string that contains every letter of the English alphabet.
We are required to write a JavaScript function that takes in a string as the first and the only argument and determines whether that string is a pangram or not. For the purpose of this problem, we will take only lowercase alphabets into consideration.
Example
The code for this will be −
const str = 'We promptly judged antique ivory buckles for the next prize'; const isPangram = (str = '') => { str = str.toLowerCase(); const { length } = str; const alphabets = 'abcdefghijklmnopqrstuvwxyz'; const alphaArr = alphabets.split(''); for(let i = 0; i < length; i++){ const el = str[i]; const index = alphaArr.indexOf(el); if(index !== -1){ alphaArr.splice(index, 1); }; }; return !alphaArr.length; }; console.log(isPangram(str));
Output
And the output in the console will be −
true
Advertisements