Algorithm : Find a sentence is an pangram.

A pangram is a sentence that uses every letter in alphabet at least once. There is a quite popular programming problem to find a given sentence is a pangram or not.
This is an another solution for that problem with JavaScript. Feel free to add a comment if you have any questions or a better, optimized solution.

function isPangram(sentence) {
 var found = [], result = true ; 
 for (var i = 0; i < 26; i++) { 
  found.push(false); 
 } 
 for (var i = 0; i < sentence.length; i++) { 
  var code = sentence.charCodeAt(i); 
  if ('A'.charCodeAt(0) <= code && code <= 'Z'.charCodeAt(0)) { 
   code += 'a'.charCodeAt(0) - 'A'.charCodeAt(0); 
  } 
  if ('a'.charCodeAt(0) <= code && code <= 'z'.charCodeAt(0)) { 
   found[code - 'a'.charCodeAt(0)] = true; 
  } 
 } 
 for (var i = 0; i < 26; i++) { 
  if (!found[i]) { 
   result = false; 
  } 
 } 
 return result; 
}

7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. After I initially commented I seem to have clicked on the -Notify me when new comments are
    added- checkbox and now every time a comment is added I receive 4 emails with the exact same comment.
    There has to be an easy method you are able to remove me from that service? Kudos!
    Click here to more info.



    ReplyDelete
  3. It's Really A Great Post. Looking For Some More Stuff. oracle training in chennai

    ReplyDelete
  4. In the wake of going over a modest bunch of the blog articles on your site, I really appreciate your procedure of composing a blog. I bookmarked it to my bookmark site page list and will return sooner rather than later. Kindly look at my site also and let me understand your opinion. best interiors

    ReplyDelete
  5. Reach to the best Data Science Training institute in Chennai for skyrocketing your career, Infycle Technologies. It is the best Software Training & Placement institute in and around Chennai, that also gives the best placement training for personality tests, interview preparation, and mock interviews for leveling up the candidate's grades to a professional level.

    ReplyDelete