查找字符串中缺少的字母-JavaScript
我们有一个长度为m的字符串,其中包含英语字母的前m个字母,但是不知何故,该字符串中缺少一个元素。所以,现在字符串包含
m-1 letters
我们需要编写一个函数,该函数接受一个这样的字符串并返回字符串中缺少的元素
示例
以下是代码-
const str = "acdghfbekj";
const missingCharacter = str => {
//使功能更一致
const s = str.toLowerCase();
for(let i = 97; ; i++){
if(s.includes(String.fromCharCode(i))){
continue;
};
return String.fromCharCode(i);
};
return false;
};
console.log(missingCharacter(str));输出结果
以下是控制台中的输出-
i
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短