forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpper.js
More file actions
Latest commit
19 lines (17 loc) · 482 Bytes
/
Copy pathUpper.js
File metadata and controls
19 lines (17 loc) · 482 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* @function upper
* @description Will convert the entire string to uppercase letters.
* @param {String} str - The input string
* @return {String} Uppercase string
* @example upper("hello") => HELLO
* @example upper("He_llo") => HE_LLO
*/
constupper=(str)=>{
if(typeofstr!=='string'){
thrownewTypeError('Argument should be string')
}
returnstr.replace(/[a-z]/g,(char)=>
String.fromCharCode(char.charCodeAt()-32)
)
}
exportdefaultupper