牛客题霸--字符串变形
字符串变形
http://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 }
【乱解集合】:NC89 字符串变形
1、使用split分割数组
2、通过sbFunction()
把数组每个字符遍历,然后转制大小写
3、把数组使用reverse()
调转
4、使用join(" ")
将数组合并为字符串。