Created
January 21, 2019 07:54
-
-
Save MikeCheng1208/4bbcaeca072b46f4f6496fbb13d6da1c to your computer and use it in GitHub Desktop.
Unicode 大小寫轉換
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
/** | |
* @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