Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. function toLowerCase(string) {
  2. let valAscii;
  3. const table = string.split(""); // make string as an array
  4. for (let i = 0; i < table.length; i++) {
  5. if (string.charCodeAt(i) >= 65 && string.charCodeAt(i) <= 90) {
  6. valAscii = string.charCodeAt(i) + 32; // 32 equal to the difference in between upper and lower cases
  7. table[i] = String.fromCharCode(valAscii); // return table ascii valor
  8. }
  9. }
  10. return table.join(""); // put back the array as a string
  11. }
  12. console.log(toLowerCase("tHis is an ExaMple of a strING with lower anD UppeRCases"));
  13.  
  14.  
  15. // version noob ! //
  16.  
  17. // const toLowerCase = (string) => {
  18. // 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',' ']
  19. // 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',' ']
  20.  
  21. // const char = string.split("");
  22.  
  23. // const newArray = []
  24.  
  25. // for(let i=0 ; i < char.length ; i++){
  26. // for(let z=0 ; z < upperCase.length ; z++) {
  27. // if(char[i]=== upperCase[z]){
  28. // newArray.push(lowerCase[z])
  29. // } else if (char[i]=== lowerCase[z]){
  30. // newArray.push(lowerCase[z])
  31. // }
  32. // }
  33. // }
  34. // const newChar = newArray.join('')
  35. //console.log(newChar)
  36. //}
  37.  
  38. //toLowerCase("BONJOUR")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement