-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdetect-pangram.js
37 lines (31 loc) · 1.07 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
function isPangram(string) {
// create an object with every lower case letter as a property
const allLetters = {};
for (let i = 97; i <= 122; i++) {
allLetters[String.fromCharCode(i)] = true;
}
// iterate over the string
for (let i = 0; i < string.length; i++) {
const character = string[i].toLowerCase();
// delete / remove the lowercase letter from the above object
delete allLetters[character];
}
// if object has no properties return true
return Object.keys(allLetters).length === 0;
}
function isPangram(string) {
// create a Set from only letters a-z in the string
const allLetters = new Set(string.toLowerCase().match(/[a-z]/g));
// if length of Set is 26 return true!
return allLetters.size === 26;
}
// Daniel!
function isPangram(string) {
let newstr = string.toLowerCase().match(/[a-z]/g, "")
let set1 = new Set(newstr);
return set1.size === 26;
}
const input1 = 'The quick brown fox jumps over the lazy dog.';
console.log(isPangram(input1), true);
const input2 = 'This is not a pangram.';
console.log(isPangram(input2), false);