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
+ The toUpperCase() method returns the value of the string converted to uppercase.
3
+ This method does not affect the value of the string itself since JavaScript strings are immutable.
4
+
5
+
6
+ MDN Link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
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 . toUpperCase = function myToUpperCase ( ) {
13
+ let upperCaseString = '' ;
14
+ for ( let i = 0 ; i < this . length ; i += 1 ) {
15
+ const character = this [ i ] ;
16
+ const charCode = character . charCodeAt ( ) ;
17
+ if ( charCode >= 97 && charCode <= 122 ) {
18
+ upperCaseString += String . fromCharCode ( charCode - 32 ) ;
19
+ } else {
20
+ upperCaseString += character ;
21
+ }
22
+ }
23
+ return upperCaseString ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments