String abcd123abcd456 How to convert to abcd321abcd654//number to reverse lowercase to uppercase, uppercase to lowercase Array.prototype.reverse = function () {var tmp; for (var i = 0, j = this.length-1; I < J; i++, j--) {tmp = this[i]; This[i] = This[j]; THIS[J] = tmp; } return this;}; function foo (s) {var code, a = [], b, last = 0;//0 1:alpha 2:num for (var i = 0; i < s.length; i++) { Code = s.charcodeat (i); if ((<= code && code <= 97 + 26-1) | | (<= code && code <= 65 + 26-1)) {if (last!== 1) {b = [], B.push (code), A.push (b); } else {A[a.length-1].push (code); } last = 1; } else if (<= code && code <= + 9) {if (last!== 2) {b = [], B.push (code), A.push (b); } else {A[a.length-1].push (code); } last = 2; } else {if (last!== 0) { b = [], B.push (code), A.push (b); } else {A[a.length-1].push (code); } last = 0; }} s = A.map (function (a) {var c = a[0]; if (<= c && C <= + 9) {return a.reverse (); } else if (<= C && C <= + 26-1) {return A.map (function (c) {return (c &am P;= 0XDF); }); } else if (<= C && C <= + 26-1) {return A.map (function (c) {return (c |= 0x20); }); } return A; }). map (function (a) {return A.map (function (c) {return String.fromCharCode (c); }). Join ('); }). Join ('); return s;} var s = "abcd123abcd456"; Console.log (foo (s));
> Node Char.js
abcd321abcd654
JavaScript string Numeric reversal letter case Interchange