mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
21 lines
478 B
JavaScript
21 lines
478 B
JavaScript
/**
|
|
* @function lower
|
|
* @description Will convert the entire string to lowercase letters.
|
|
* @param {String} str - The input string
|
|
* @returns {String} Lowercase string
|
|
* @example lower("HELLO") => hello
|
|
* @example lower("He_llo") => he_llo
|
|
*/
|
|
|
|
const lower = (str) => {
|
|
if (typeof str !== 'string') {
|
|
throw new TypeError('Invalid Input Type')
|
|
}
|
|
|
|
return str.replace(
|
|
/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt() + 32)
|
|
)
|
|
}
|
|
|
|
export default lower
|