Pangram是一个函数,它获取一个输入并检查它是否有所有的字母,这是我使用的ASCII代码:
function pangram(x) {
var a;
for (var i = 97; i < 122; i++) {
a = "&#" + i + ";";
if (x.toLowerCase().includes(a) !== true) {
break;
}
}
if (i === 122) {
return true
} else {
return false
}
}
我认为问题是a = "&#" + i + ";" ;
,但我不知道为什么会有问题,它应该能工作.
发布于 2020-05-15 13:10:13
您需要使用charCodeAt()
,而不是手工制作。将if条件替换为:
if(x.toLowerCase().includes(String.fromCharCode(i))!==true)
发布于 2019-11-19 05:06:09
你已经接近答案了,但是代码有一些问题,
function pangram(x) {
var a;
for (var i = 97; i < 122; i++) {
a = String.fromCharCode(i);;
if (x.toLowerCase().includes(a) !== true) {
// if atleast one letter was not found, we exit the function and the loop
return false;
}
}
// if it comes here, that means all the letters were found
return true;
}
var isPangram = pangram("The quick brown fox jumps over the lazy dog");
console.log(isPangram);
https://stackoverflow.com/questions/58926446
复制相似问题