牛客题霸--NC89 字符串变形

[编程题]字符串变形
https://www.nowcoder.com/questionTerminal/c3120c1c1bc44ad986259c0cf0f0b80e

function trans(s, n){
    return s.split(" ").map(e=>sbFunction(e)).reverse().join(" ")
}

function sbFunction( word ){
	let _word = "";
    for( let i=0;i<word.length;i++ ){
        switch( word[i] ){
            case 'A':_word += "a";break;
            case 'B':_word += "b";break;
            case 'C':_word += "c";break;
            case 'D':_word += "d";break;
            case 'E':_word += "e";break;
            case 'F':_word += "f";break;
            case 'G':_word += "g";break;
            case 'H':_word += "h";break;
            case 'I':_word += "i";break;
            case 'J':_word += "j";break;
            case 'K':_word += "k";break;
            case 'L':_word += "l";break;
            case 'M':_word += "m";break;
            case 'N':_word += "n";break;
            case 'O':_word += "o";break;
            case 'P':_word += "p";break;
            case 'Q':_word += "q";break;
            case 'R':_word += "r";break;
            case 'S':_word += "s";break;
            case 'T':_word += "t";break;
            case 'U':_word += "u";break;
            case 'V':_word += "v";break;
            case 'W':_word += "w";break;
            case 'X':_word += "x";break;
            case 'Y':_word += "y";break;
            case 'Z':_word += "z";break;
            case 'a':_word += "A";break;
            case 'b':_word += "B";break;
            case 'c':_word += "C";break;
            case 'd':_word += "D";break;
            case 'e':_word += "E";break;
            case 'f':_word += "F";break;
            case 'g':_word += "G";break;
            case 'h':_word += "H";break;
            case 'i':_word += "I";break;
            case 'j':_word += "J";break;
            case 'k':_word += "K";break;
            case 'l':_word += "L";break;
            case 'm':_word += "M";break;
            case 'n':_word += "N";break;
            case 'o':_word += "O";break;
            case 'p':_word += "P";break;
            case 'q':_word += "Q";break;
            case 'r':_word += "R";break;
            case 's':_word += "S";break;
            case 't':_word += "T";break;
            case 'u':_word += "U";break;
            case 'v':_word += "V";break;
            case 'w':_word += "W";break;
            case 'x':_word += "X";break;
            case 'y':_word += "Y";break;
            case 'z':_word += "Z";break;
        }
    }
    return _word;
}

module.exports = {
    trans : trans
}

【leetcode】:NC89 字符串变形
1、使用split分割数组
2、通过sbFunction()把数组每个字符遍历,然后转制大小写
3、把数组使用reverse()调转
4、使用join(" ")将数组合并为字符串。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值