Skip to content

Commit b7cdd20

Browse files
committed
add better solution for 709
1 parent 9e95284 commit b7cdd20

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

algorithms/toLowerCase/Solution.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33
* @return {string}
44
*/
55
var toLowerCase = function(s) {
6-
return s.toLowerCase()
6+
const sb = [];
7+
for (let ch of s) {
8+
if (ch.charCodeAt() >= 65 && ch.charCodeAt() <= 90) {
9+
// 直接+32也可以
10+
// ch = String.fromCharCode(ch.charCodeAt() + 32);
11+
ch = String.fromCharCode(ch.charCodeAt() | 32);
12+
13+
}
14+
sb.push(ch);
15+
}
16+
return sb.join('');
717
};

0 commit comments

Comments
 (0)