mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
20 lines
483 B
JavaScript
20 lines
483 B
JavaScript
/**
|
|
* @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
|
|
*/
|
|
const upper = (str) => {
|
|
if (typeof str !== 'string') {
|
|
throw new TypeError('Argument should be string')
|
|
}
|
|
|
|
return str.replace(
|
|
/[a-z]/g, (char) => String.fromCharCode(char.charCodeAt() - 32)
|
|
)
|
|
}
|
|
|
|
export default upper
|