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
28 lines (23 loc) · 624 Bytes
/
Copy pathLower.js
File metadata and controls
28 lines (23 loc) · 624 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @function lower
* @description Will convert the entire string to lowercase letters.
* @param {String} url - The input URL string
* @return {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')
}
let lowerString = ''
for (const char of str) {
let asciiCode = char.charCodeAt(0)
if (asciiCode >= 65 && asciiCode <= 90) {
asciiCode += 32
}
lowerString += String.fromCharCode(asciiCode)
}
return lowerString
}
export { lower }