Created
March 22, 2020 15:02
-
-
Save getaclue00/839bb0816780f852e5ab320a3cdb70f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toLowerCase = function(str) { | |
// let result = []; | |
var result = ``; | |
str.split('').forEach(char => { | |
// find current position | |
let current = char.charCodeAt(0); | |
if ('A'.charCodeAt(0) <= current) { | |
if (current <= 'Z'.charCodeAt(0)) { | |
let next = current - 'A'.charCodeAt(0); | |
let newCharIndex = 'a'.charCodeAt(0) + next; | |
let newChar = String.fromCharCode(newCharIndex); | |
result = result + newChar; | |
} else { | |
result = result + char; | |
} | |
} else { | |
result = result + char; | |
} | |
}); | |
return result; | |
}; | |
module.exports = { | |
toLowerCase | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment