Skip to content

Instantly share code, notes, and snippets.

@AlexandrFadeev
Created September 11, 2017 14:39
Show Gist options
  • Save AlexandrFadeev/fa9e3ef46cf54438f15dcd052d4dbbe6 to your computer and use it in GitHub Desktop.
Save AlexandrFadeev/fa9e3ef46cf54438f15dcd052d4dbbe6 to your computer and use it in GitHub Desktop.
pagramma algorithm in javascript
function isPangramma(string) {
/**
define constant that hold alphabet count. We take in considiration that the alphabet is 'english'.8
*/
const alphabetCount = 26;
/**
Create new string that trims whitespaces from passed to function string as a parameter
*/
var noSpacesString = string.replace(/ /g, '');
/**
Check if 'noSpacesString' string count is equal to 'alphabetCount' that mean the string is pangramma and we return 'true'
*/
if (noSpacesString.length == alphabetCount) {
return true;
} else {
/**
Create char array from 'noSpacesString'
*/
const charArray = noSpacesString.split('');
/**
Create new 'set' collection type and initialize with 'charArray'
*/
const charSet = new Set(charArray);
/**
Check the size of a set, is is equal to 'alphabetCount' then return 'true' (the string is an pangramma).
If this condition fails then return 'false'.
*/
return charSet.size == alphabetCount ? true : false;
}
}
const pangramma = isPangramma("abcd efghijklm nopaqrsss ttu vwxxxyqqz");
console.log(pangramma);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment