File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+
3
+ The toLowerCase() method returns the value of the string converted to lower case.
4
+ toLowerCase() does not affect the value of the string str itself.
5
+
6
+ MDN Link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
7
+
8
+ Characters from A-Z have ASCII code from 65 - 90.
9
+ And characters from a-z have ASCII code from 97-122.
10
+ We're checking this condition to implement this function
11
+ */
12
+ String . prototype . toLowerCase = function myToLowerCase ( ) {
13
+ let lowerCaseString = '' ;
14
+ for ( let i = 0 ; i < this . length ; i += 1 ) {
15
+ const character = this [ i ] ;
16
+ const charCode = character . charCodeAt ( ) ;
17
+ if ( charCode >= 65 && charCode <= 90 ) {
18
+ lowerCaseString += String . fromCharCode ( charCode + 32 ) ;
19
+ } else {
20
+ lowerCaseString += character ;
21
+ }
22
+ }
23
+ return lowerCaseString ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments