一、题目
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.
这道题要我们实现的是,判断字符串中是否包含·a-z
至少一次(不区分大小写),是的话返回true
,否则返回false
二、例子
var string = "The quick brown fox jumps over the lazy dog."
isPangram(string) // true
var string = "This is not a pangram."
isPangram(string) // false
三、题解一
// 题解一:
function isPangram(string){
for(let i = 65; i <= 90; i++){
if(string.toUpperCase().indexOf(String.fromCharCode(i)) == -1){
return false;
}
}
return true;
}
四、题解二
// 题解二:(Best Practices)
function isPangram(string){
string = string.toLowerCase();
return "abcdefghijklmnopqrstuvwxyz".split("").every(function(x){
return string.indexOf(x) !== -1;
});
}