-
Notifications
You must be signed in to change notification settings - Fork 40
/
ToLowerCase.js
41 lines (38 loc) · 899 Bytes
/
ToLowerCase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Source : https://leetcode.com/problems/to-lower-case
// Author : Dean Shi
// Date : 2018-08-27
/***************************************************************************************
* Implement function ToLowerCase() that has a string parameter str, and returns the
* same string in lowercase.
*
* Example 1:
*
* Input: "Hello"
* Output: "hello"
*
* Example 2:
*
* Input: "here"
* Output: "here"
*
* Example 3:
*
* Input: "LOVELY"
* Output: "lovely"
*
***************************************************************************************/
/**
* @param {string} str
* @return {string}
*/
var toLowerCase = function(str) {
const result = []
for (let i = 0; i < str.length; i++) {
result.push(
'A' <= str[i] && str[i] <= 'Z'
? String.fromCharCode(str.charCodeAt(i) + 32)
: str[i]
)
}
return result.join('')
};