Pangrams HackerRank solutions in JavaScript
A pangram is a string that contains every letter of the alphabet. Given a sentence determine whether it is a pangram in the English alphabet. Ignore case. Return either pangram
or not pangram
as appropriate.
Example
The string contains all letters in the English alphabet, so return pangram
.
Function Description
Complete the function pangrams in the editor below. It should return the string pangram
if the input string is a pangram. Otherwise, it should return not pangram
.
pangrams has the following parameter(s):
- string s: a string to test
Returns
- string: either
pangram
ornot pangram
Input Format
A single line with string .
Constraints
Each character of ,
Sample Input
Sample Input 0
We promptly judged antique ivory buckles for the next prize
Sample Output 0
pangram
Sample Explanation 0
All of the letters of the alphabet are present in the string.
Sample Input 1
We promptly judged antique ivory buckles for the prize
Sample Output 1
not pangram
Sample Explanation 0
The string lacks an x
.
solutions
function pangrams(s) {
// Write your code here
let letters = ‘abcdefghijklmnopqrstuvwxyz’;
let pangram = ‘’;
let s1 = s.replace(/\s/g,’’);
//convert all the letters to lowercase
let s2 = s1.toLowerCase();
//split the letters into a separate letter
let s3 = s2.split(‘’);
//create a new array without repetitioon of elements
let s4 = […new Set(s3)];
//sort the array
s4.sort();
//convert the array back to a sentence of words
let s5 = s4.join(‘’);
if(s5 === letters){
pangram = “pangram”;
}
else{
pangram = “not pangram”;
}
return pangram;
}