FCC-學習筆記 Missing lettersapp
1>最近在學習和練習FCC的題目。這個真的比較的好,推薦給你們。學習
2>中文版的地址:https://www.freecodecamp.cn/;英文版的地址:https://www.freecodecamp.org測試
3>此次寫關於一個JS的問題,名爲Missing letters.code
規則要求以下:blog
從傳遞進來的字母序列中找到缺失的字母並返回它。io
若是全部字母都在序列中,返回 undefinedfunction
4>我寫的代碼實現以下:class
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>寫的很差還須要改進,期待你們的指出,共同進步!