What is a method that can be used to increment letters?

前端 未结 14 2744
我在风中等你
我在风中等你 2020-11-27 04:19

Does anyone know of a Javascript library (e.g. underscore, jQuery, MooTools, etc.) that offers a method of incrementing a letter?

I would like to be able to do somet

14条回答
  •  粉色の甜心
    2020-11-27 04:44

    A just for laughs solution

    function nextLetter(str) {
      const Alphabet = [
        // lower case alphabet
        "a", "b", "c",
        "d", "e", "f",
        "g", "h", "i",
        "j", "k", "l",
        "m", "n", "o",
        "p", "q", "r",
        "s", "t", "u",
        "v", "w", "x",
        "y", "z",
        // upper case alphabet
        "A", "B", "C",
        "D", "E", "F",
        "G", "H", "I",
        "J", "K", "L",
        "M", "N", "O",
        "P", "Q", "R",
        "S", "T", "U",
        "V", "W", "X",
        "Y", "Z"
      ];
    
      const LetterArray = str.split("").map(letter => {
        if (Alphabet.includes(letter) === true) {
          return Alphabet[Alphabet.indexOf(letter) + 1];
        } else {
          return " ";
        }
      });
    
      const Assemble = () => LetterArray.join("").trim();
      return Assemble();
    }
    
    
    console.log(nextLetter("hello*3"));

提交回复
热议问题