Advertisement
ggeorgiev88

ascii with obj

Mar 14th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function valueOfAString(arr) {
  2.  
  3.     let text = arr[0].split("");
  4.     let caseNeeded = arr[1];
  5.     let lowerCase = {
  6.         a: 97,
  7.         b: 98,
  8.         c: 99,
  9.         d: 100,
  10.         e: 101,
  11.         f: 102,
  12.         g: 103,
  13.         h: 104,
  14.         i: 105,
  15.         j: 106,
  16.         k: 107,
  17.         l: 108,
  18.         m: 109,
  19.         n: 110,
  20.         o: 111,
  21.         p: 112,
  22.         q: 113,
  23.         r: 114,
  24.         s: 115,
  25.         t: 116,
  26.         u: 117,
  27.         v: 118,
  28.         w: 119,
  29.         x: 120,
  30.         y: 121,
  31.         z: 122,
  32.  
  33.     }
  34.     let upperCase = {
  35.         A: 65,
  36.         B: 66,
  37.         C: 67,
  38.         D: 68,
  39.         E: 69,
  40.         F: 70,
  41.         G: 71,
  42.         H: 72,
  43.         I: 73,
  44.         J: 74,
  45.         K: 75,
  46.         L: 76,
  47.         M: 77,
  48.         N: 78,
  49.         O: 79,
  50.         P: 80,
  51.         Q: 81,
  52.         R: 82,
  53.         S: 83,
  54.         T: 84,
  55.         U: 85,
  56.         V: 86,
  57.         W: 87,
  58.         X: 88,
  59.         Y: 89,
  60.         Z: 90,
  61.     }
  62.     let sumLower = 0;
  63.     let sumUpper = 0
  64.     for (let x = 0; x < text.length; x++) {
  65.         let currLetter = text[x];
  66.         if (currLetter.charCodeAt(0) >= 65 && currLetter.charCodeAt(0) <= 90) {
  67.             //sumUpper += currLetter.charCodeAt(0)
  68.             sumUpper += upperCase[currLetter];
  69.         } else if (currLetter.charCodeAt(0) >= 97 && currLetter.charCodeAt(0) <= 122) {
  70.             //sumLower += currLetter.charCodeAt(0);
  71.             sumLower += lowerCase[currLetter];
  72.         }
  73.     }
  74.     if (caseNeeded === "UPPERCASE") {
  75.         console.log(`The total sum is: ${sumUpper}`)
  76.     } else if (caseNeeded === "LOWERCASE") {
  77.         console.log(`The total sum is: ${sumLower}`)
  78.     }
  79.  
  80. }
  81.  
  82. valueOfAString(['HelloFromMyAwesomePROGRAM',
  83.     'LOWERCASE']);
  84. console.log("--------------------------------------");
  85. valueOfAString(['AC/DC',
  86.     'UPPERCASE'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement