Skip to content

Instantly share code, notes, and snippets.

@MikeCheng1208
Created January 21, 2019 07:54
Show Gist options
  • Save MikeCheng1208/4bbcaeca072b46f4f6496fbb13d6da1c to your computer and use it in GitHub Desktop.
Save MikeCheng1208/4bbcaeca072b46f4f6496fbb13d6da1c to your computer and use it in GitHub Desktop.
Unicode 大小寫轉換
/**
* @param {string} str
* @return {string}
*/
const toLowerCase = function(str) {
let strarr = str.split("");
let samtLetterArr = [];
let samtLetter = "";
strarr.forEach(el => {
let unicode = el.charCodeAt(0);
let letter = String.fromCharCode(unicode);
if(unicode <= 90 && unicode >=65){
letter = String.fromCharCode(unicode + 32);
}
samtLetterArr.push(letter);
});
samtLetter = samtLetterArr.join('');
return samtLetter;
};
console.log(toLowerCase('Hello'));
console.log(toLowerCase('here'));
console.log(toLowerCase('LOVELY'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment