Missing letters

function fearNotLetter(str) {
  //遍历字符串中的字符,用ASCII 判断是否有遗漏
  //找到遗漏的char,返回。结果只有一个
  //.reduce 两两比较,reduce 不能中途中断,还是for 吧
  //.charCodeAt 字符的ASCII 码
  for(let i= 0; i< str.length-1; i++) {
    if(str[i].charCodeAt()+1 !== str[i+1].charCodeAt())
      return String.fromCharCode(str[i].charCodeAt()+1)
  }
}

fearNotLetter("abce");

测试数据:

fearNotLetter("abce") should return "d".

fearNotLetter("abcdefghjklmno") should return "i".

fearNotLetter("stvwx") should return "u".

fearNotLetter("bcdf") should return "e".

fearNotLetter("abcdefghijklmnopqrstuvwxyz") should return undefined.

//别人家的孩子,这个边界处理的比我易读
function fearNotLetter(str) {
  for (let i = 1; i < str.length; ++i) {
    if (str.charCodeAt(i) - str.charCodeAt(i - 1) > 1) {
      return String.fromCharCode(str.charCodeAt(i - 1) + 1);
    }
  }
}