SIGN IN SIGN UP

Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.

34084 0 0 JavaScript
2021-12-06 21:26:14 +05:30
/**
* @function upper
* @description Will convert the entire string to uppercase letters.
* @param {String} str - The input string
2021-12-06 21:26:14 +05:30
* @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')
2021-12-06 21:26:14 +05:30
}
return str.replace(/[a-z]/g, (char) =>
String.fromCharCode(char.charCodeAt() - 32)
)
2021-12-06 21:26:14 +05:30
}
export default upper