Find missing letter in list of alphabets

前端 未结 16 1705
逝去的感伤
逝去的感伤 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:40

    Another function that may help:

    var alphabet = "abcdefgheijklmnopqrstuvwxyz";
    function fearNotLetter(a) {
      function letterIndex(text, index) {
        var letter = text.charAt(0);
        if (alphabet.indexOf(letter) !== index) { return alphabet.charAt(index); } else { return letterIndex(text.substring(1), index + 1) }
      }
      if (alphabet.indexOf(a) === -1) {
        return letterIndex(a, alphabet.indexOf(a.charAt(0)));
      }
      return undefined;
    }
    fearNotLetter("abc"); //Undefined
    fearNotLetter("abce"); //d
    fearNotLetter("fgi"); //h
    

提交回复
热议问题