Find missing letter in list of alphabets

前端 未结 16 1540
逝去的感伤
逝去的感伤 2021-01-01 05:15

I am trying to solve the following issue:

Find the missing letter in the passed letter range and return it. If all letters are present in the range, return undefine

16条回答
  •  隐瞒了意图╮
    2021-01-01 05:33

    I just did this challenge. I am a beginner to Javascript so this was my approach, very simple, sometimes you don't have to use the methods they provide but they also help. I hope you can understand it.

    function fearNotLetter(str) {
    
    var alphabet= "abcdefghijlmnopqrstuvwxyz";
    var piece =alphabet.slice(0, str.length+1);
    
    
    
    
    for(var i=0; i < piece.length; i++ ){
    if(str.charCodeAt(0) != 97){
    
    return undefined;
    }
    
    else if(str.indexOf(piece[i])===-1){
      return piece[i];
    }
    }// for loop
    
    }
    
    fearNotLetter("abce");// It will return d
    fearNotLetter("xy");//It will return undefined
    fearNotLetter("bce");//It will return undefined
    

提交回复
热议问题