-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge-6.js
33 lines (22 loc) · 933 Bytes
/
challenge-6.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
// 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.
const letters={};
function isPangram(string){
//...
for(let i=97;i<=122;i++){
letters[String.fromCharCode(i)]=0;
}
string.split('').forEach(l=>{
l=l.toLowerCase();
if(letters[l] !== undefined){
letters[l]++;
}
})
return Object.values(letters).every(v=>v>0)
}
isPangram("The quick brown fox jumps over the lazy dog.")
// #Method2
function isPangram(string){
string = string.toLowerCase();
return "abcdefghijklmnopqrstuvwxyz".split('').every(x=>string.indexOf(x) !== -1)
}