Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function toLowerCase(string) {
- let valAscii;
- const table = string.split(""); // make string as an array
- for (let i = 0; i < table.length; i++) {
- if (string.charCodeAt(i) >= 65 && string.charCodeAt(i) <= 90) {
- valAscii = string.charCodeAt(i) + 32; // 32 equal to the difference in between upper and lower cases
- table[i] = String.fromCharCode(valAscii); // return table ascii valor
- }
- }
- return table.join(""); // put back the array as a string
- }
- console.log(toLowerCase("tHis is an ExaMple of a strING with lower anD UppeRCases"));
- // version noob ! //
- // const toLowerCase = (string) => {
- // const upperCase = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ']
- // const lowerCase = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ']
- // const char = string.split("");
- // const newArray = []
- // for(let i=0 ; i < char.length ; i++){
- // for(let z=0 ; z < upperCase.length ; z++) {
- // if(char[i]=== upperCase[z]){
- // newArray.push(lowerCase[z])
- // } else if (char[i]=== lowerCase[z]){
- // newArray.push(lowerCase[z])
- // }
- // }
- // }
- // const newChar = newArray.join('')
- //console.log(newChar)
- //}
- //toLowerCase("BONJOUR")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement