-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoLowerCase.js
39 lines (31 loc) · 960 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
const toLowerCase = str => {
const arr = [];
for (let i = 0; i < str.length; i++) {
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
arr.push(String.fromCharCode(str.charCodeAt(i) + 32));
} else {
arr.push(str.charAt(i));
}
}
return arr.join('');
}
// specification
// input: string
// output: string with all characters in lower case
// constraints:
// edge cases:
// justification
// to convert a string into all lower case
// explanation
// the characters in the input string will determine which character need to be converted to lower case in the output string
// visualization
// approximation
// declare empty array to store converted characters
// loop through string
// use charCodeAt difference to convert charaters
// return output array joined by empty space
// verification
// implementation
console.log(toLowerCase('Hello'));
console.log(toLowerCase('here'));
console.log(toLowerCase('LOVELY'));