Skip to content

Instantly share code, notes, and snippets.

@getaclue00
Created March 22, 2020 15:02
Show Gist options
  • Save getaclue00/839bb0816780f852e5ab320a3cdb70f4 to your computer and use it in GitHub Desktop.
Save getaclue00/839bb0816780f852e5ab320a3cdb70f4 to your computer and use it in GitHub Desktop.
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