Last active
July 21, 2016 21:24
-
-
Save MariaSzubski/6fea0fbb8612494fd6ad2aeb43973f7d to your computer and use it in GitHub Desktop.
Checks string for pangram #hackerrank #strings
This file contains hidden or 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
| /* | |
| Solution for HackerRank > Algorithms > Strings > Pangrams | |
| https://www.hackerrank.com/challenges/pangrams | |
| */ | |
| function main(input) { | |
| var alpha = 'abcdefghijklmnopqrstuvwxyz'; | |
| var i = 0, char, index; | |
| // Simplify string | |
| var simple_input = input.toLowerCase().replace(/\s+/g, ''); | |
| /* | |
| Test for each character in the alpha string. | |
| If the character doesn't exist, break the loop and return 'not panagram'. | |
| */ | |
| for (i=0; i < alpha.length; i++){ | |
| char = alpha.charAt(i); | |
| index = simple_input.indexOf(char); | |
| if (index == -1){ | |
| console.log('not pangram'); | |
| break; | |
| } else if (i == 25){ | |
| console.log('pangram'); | |
| } | |
| } | |
| } | |
| main('We promptly judged antique ivory buckles for the next prize '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment