位运算
大写变小写、小写变大写 : ASCII码 ^= 32
大写变小写、小写变小写 : ASCII码 |= 32
小写变大写、大写变大写 : ASCII码 &= -33
/**
* @param {string} str
* @return {string}
*/
var toLowerCase = function(str) {
let result = ‘‘;
for(let i = 0;i < str.length;i++){
result += String.fromCharCode(str.charCodeAt(i) | 32);
}
return result;
};
原文:https://www.cnblogs.com/njuwyx/p/12014071.html