Created
September 11, 2017 14:39
-
-
Save AlexandrFadeev/fa9e3ef46cf54438f15dcd052d4dbbe6 to your computer and use it in GitHub Desktop.
pagramma algorithm in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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