File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 9
9
And characters from a-z have ASCII code from 97-122.
10
10
We're checking this condition to implement this function
11
11
*/
12
- String . prototype . toLowerCase = function myToLowerCase ( ) {
13
- return this . split ( '' ) . reduce ( ( acc , character ) => {
12
+ String . prototype . toLowerCase = function myToUpperCase ( ) {
13
+ let lowerCaseString = '' ;
14
+ for ( let i = 0 ; i < this . length ; i += 1 ) {
15
+ const character = this [ i ] ;
14
16
const charCode = character . charCodeAt ( ) ;
15
17
if ( charCode >= 65 && charCode <= 90 ) {
16
- return acc + String . fromCharCode ( charCode + 32 ) ;
18
+ lowerCaseString += String . fromCharCode ( charCode + 32 ) ;
19
+ } else {
20
+ lowerCaseString += character ;
17
21
}
18
- return acc + character ;
19
- } , '' ) ;
22
+ }
23
+ return lowerCaseString ;
20
24
} ;
You can’t perform that action at this time.
0 commit comments