File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed
Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change 11/**
22 * @function upper
33 * @description Will convert the entire string to uppercase letters.
4- * @param {String } url - The input URL string
4+ * @param {String } str - The input string
55 * @return {String } Uppercase string
66 * @example upper("hello") => HELLO
77 * @example upper("He_llo") => HE_LLO
88 */
9-
109const upper = ( str ) => {
1110 if ( typeof str !== 'string' ) {
12- throw new TypeError ( 'Invalid Input Type ' )
11+ throw new TypeError ( 'Argument should be string ' )
1312 }
1413
15- let upperString = ''
14+ return str . replace (
15+ / [ a - z ] / g,
16+ ( _ , indexOfLowerChar ) => {
17+ const asciiCode = str . charCodeAt ( indexOfLowerChar )
1618
17- for ( const char of str ) {
18- let asciiCode = char . charCodeAt ( 0 )
19- if ( asciiCode >= 97 && asciiCode <= 122 ) {
20- asciiCode -= 32
19+ return String . fromCharCode ( asciiCode - 32 )
2120 }
22- upperString += String . fromCharCode ( asciiCode )
23- }
24-
25- return upperString
21+ )
2622}
2723
2824export { upper }
You can’t perform that action at this time.
0 commit comments