Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
2
Indexable
Never
function convertCase(lowercaseString, uppercaseString) {
  var convertedLower = "";
  var convertedUpper = "";
  
  var lowercaseCharCodeDiff = "a".charCodeAt(0) - "A".charCodeAt(0);
  
  for (var i = 0; i < lowercaseString.length; i++) {
    var char = lowercaseString[i];
    var charCode = char.charCodeAt(0);
    
    if (charCode >= 97 && charCode <= 122) {
      // Convert lowercase to uppercase
      char = String.fromCharCode(charCode - lowercaseCharCodeDiff);
    }
    
    convertedLower += char;
  }
  
  var uppercaseCharCodeDiff = "A".charCodeAt(0) - "a".charCodeAt(0);
  
  for (var j = 0; j < uppercaseString.length; j++) {
    var char = uppercaseString[j];
    var charCode = char.charCodeAt(0);
    
    if (charCode >= 65 && charCode <= 90) {
      // Convert uppercase to lowercase
      char = String.fromCharCode(charCode + uppercaseCharCodeDiff);
    }
    
    convertedUpper += char;
  }
  
  return [convertedLower, convertedUpper];
}

var lower = "hello";
var upper = "WORLD";
var result = convertCase(lower, upper);

console.log("Converted Lowercase: " + result[0]);  // Output: "HELLO"
console.log("Converted Uppercase: " + result[1]);  // Output: "world"