forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLower.js
More file actions
Latest commit
20 lines (17 loc) · 477 Bytes
/
Copy pathLower.js
File metadata and controls
20 lines (17 loc) · 477 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* @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
*/
constlower=(str)=>{
if(typeofstr!=='string'){
thrownewTypeError('Invalid Input Type')
}
returnstr.replace(/[A-Z]/g,(char)=>
String.fromCharCode(char.charCodeAt()+32)
)
}
exportdefaultlower