-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_pangram.js
44 lines (30 loc) · 1.15 KB
/
detect_pangram.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
A pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence "The quick brown fox jumps over the lazy dog" is a pangram, because it uses the letters A-Z at least once (case is irrelevant).
Given a string, detect whether or not it is a pangram. Return True if it is, False if not. Ignore numbers and punctuation.
*/
// 26 letters
const ALPHABET_LETTERS = 26;
const isPangram = phrase => {
let letter;
const lettersFound = [];
const letters = phrase.trim().split("");
for (let i = 0; i < letters.length; i++) {
letter = letters[i];
if (letter.match(/[a-z]/i)) {
letter = letter.toLowerCase();
if (lettersFound.indexOf(letter) === -1) {
lettersFound.push(letter);
}
}
}
console.log('lettersFound', lettersFound);
return lettersFound.length === ALPHABET_LETTERS;
}
/*
THE BEST
string = string.toLowerCase();
return "abcdefghijklmnopqrstuvwxyz".split("").every(function(x){
return string.indexOf(x) !== -1;
});
*/
console.log(isPangram("The quick brown fox jumps over the lazy dog."));