FCC-学习笔记 Missing letters

                                                              FCC-学习笔记  Missing letters

1>最近在学习和练习FCC的题目。这个真的比较的好,推荐给大家。

2>中文版的地址:https://www.freecodecamp.cn/;英文版的地址:https://www.freecodecamp.org

3>这次写关于一个JS的问题,名为Missing letters.

规则要求如下:

从传递进来的字母序列中找到缺失的字母并返回它。

如果所有字母都在序列中,返回 undefined

4>我写的代码实现如下:

function fearNotLetter(str) {
  var result;
  for(var i=0;i<str.length-1;i++){
    if(str[i+1].charCodeAt()-str[i].charCodeAt()>1){
      result=String.fromCharCode(str[i+1].charCodeAt()-1);
      break;
    }else if(str[i+1].charCodeAt()-str[i].charCodeAt()==1){
     result=undefined;
    }
  }
  return result;
}
//测试过程
fearNotLetter("abce");
fearNotLetter("abcdefghjklmno");
fearNotLetter("bcd");
fearNotLetter("yz");

  




  

5>写的不好还需要改进,期待大家的指出,共同进步!
原文地址:https://www.cnblogs.com/tudaogaoyang/p/8251365.html