File tree 2 files changed +37
-0
lines changed 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @function upper
3
+ * @description Will convert the entire string to uppercase letters.
4
+ * @param {String } url - The input URL string
5
+ * @return {String } Uppercase string
6
+ * @example upper("hello") => HELLO
7
+ * @example upper("He_llo") => HE_LLO
8
+ */
9
+
10
+ const upper = ( str ) => {
11
+ if ( typeof str !== 'string' ) {
12
+ throw new TypeError ( 'Invalid Input Type' )
13
+ }
14
+
15
+ let upperString = ''
16
+
17
+ for ( const char of str ) {
18
+ let asciiCode = char . charCodeAt ( 0 )
19
+ if ( asciiCode >= 97 && asciiCode <= 122 ) {
20
+ asciiCode -= 32
21
+ }
22
+ upperString += String . fromCharCode ( asciiCode )
23
+ }
24
+
25
+ return upperString
26
+ }
27
+
28
+ export { upper }
Original file line number Diff line number Diff line change
1
+ import { upper } from '../Upper'
2
+
3
+ describe ( 'Upper' , ( ) => {
4
+ it ( 'return uppercase strings' , ( ) => {
5
+ expect ( upper ( 'hello' ) ) . toBe ( 'HELLO' )
6
+ expect ( upper ( 'WORLD' ) ) . toBe ( 'WORLD' )
7
+ expect ( upper ( 'hello_WORLD' ) ) . toBe ( 'HELLO_WORLD' )
8
+ } )
9
+ } )
You can’t perform that action at this time.
0 commit comments