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 lower
3
+ * @description Will convert the entire string to lowercase letters.
4
+ * @param {String } url - The input URL string
5
+ * @return {String } Lowercase string
6
+ * @example lower("HELLO") => hello
7
+ * @example lower("He_llo") => he_llo
8
+ */
9
+
10
+ const lower = ( str ) => {
11
+ if ( typeof str !== 'string' ) {
12
+ throw new TypeError ( 'Invalid Input Type' )
13
+ }
14
+
15
+ let lowerString = ''
16
+
17
+ for ( const char of str ) {
18
+ let asciiCode = char . charCodeAt ( 0 )
19
+ if ( asciiCode >= 65 && asciiCode <= 90 ) {
20
+ asciiCode += 32
21
+ }
22
+ lowerString += String . fromCharCode ( asciiCode )
23
+ }
24
+
25
+ return lowerString
26
+ }
27
+
28
+ export { lower }
Original file line number Diff line number Diff line change
1
+ import { lower } from '../Lower'
2
+
3
+ describe ( 'Lower' , ( ) => {
4
+ it ( 'return uppercase strings' , ( ) => {
5
+ expect ( lower ( 'hello' ) ) . toBe ( 'hello' )
6
+ expect ( lower ( 'WORLD' ) ) . toBe ( 'world' )
7
+ expect ( lower ( 'hello_WORLD' ) ) . toBe ( 'hello_world' )
8
+ } )
9
+ } )
You can’t perform that action at this time.
0 commit comments