Missing letters

来源:互联网 发布:深圳青年旅舍 知乎 编辑:程序博客网 时间:2024/05/22 15:31

Find the missing letter in the passed letter range and return it.

If all letters are present in the range, return undefined.

判断字符串相邻字符是否连续,若连续返回undefined,否则返回缺失字符

function fearNotLetter(str) {  var arr = str.split('');  for (var i = 1; i < arr.length; i++) {    var curCode = arr[i].charCodeAt();    if (curCode !== arr[i - 1].charCodeAt() + 1) {      return String.fromCharCode(curCode - 1);    }  }  return undefined;}fearNotLetter("abce");
0 0
原创粉丝点击