acbrent25
9/4/2017 - 4:16 PM

Is pangram: Uses regular expression A pangram is a sentence that contains all the letters of the English alphabet at least once. For examp

Is pangram: Uses regular expression A pangram is a sentence that contains all the letters of the English alphabet at least once. For example: The quick brown fox jumps over the lazy dog.

Write a function that takes a string and determines whether the string is a pangram, without typing out the full alphabet anywhere in your code.

BONUS: Handle punctuation in the sentence

var test1 = "The quick brown fox jumps over the lazy dog.";

var isPangram = function(string) {

  // If the string contains less than 26 letters, it couldn't have all 26 letters of the alphabet
  if (string.length < 26) {
    return false;
  }
  else {

    // Holder for the unique letters found in the sentence
    var letterHolder = [];

    // Make the string lowercase, remove anything that isn't the letters a through z, then split them into an array
    var letters = string.toLowerCase().replace(/[^a-z]+/g, "").split("");

    // loop over the letters, if a letter is not found in the letterHolder array, push it in
    for (var i = 0; i < letters.length; i++) {
      if (letterHolder.indexOf(letters[i]) === -1) {
        letterHolder.push(letters[i]);
      }
    }

    // Check to see if letterHolder.length contains the 26 letters of the alphabet.
    if (letterHolder.length === 26) {
      return true;
    }
    else {
      return false;
    }
  }
};
<!DOCTYPE html>

<html lang="en-us">

  <head>

    <meta charset="UTF-8">

    <title>Pangram</title>

  </head>

  <body>

    <script src="app.js"></script>

  </body>

</html>