Skip to content

Instantly share code, notes, and snippets.

@MariaSzubski
Last active July 21, 2016 21:24
Show Gist options
  • Select an option

  • Save MariaSzubski/6fea0fbb8612494fd6ad2aeb43973f7d to your computer and use it in GitHub Desktop.

Select an option

Save MariaSzubski/6fea0fbb8612494fd6ad2aeb43973f7d to your computer and use it in GitHub Desktop.
Checks string for pangram #hackerrank #strings
/*
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