Untitled

 avatar
unknown
plain_text
2 years ago
756 B
5
Indexable
function convertCase(str) {
  let convertedStr = '';
  
  for (let i = 0; i < str.length; i++) {
    const charCode = str.charCodeAt(i);
    
    if (charCode >= 65 && charCode <= 90) { // Uppercase letters (A-Z)
      const convertedChar = String.fromCharCode(charCode + 32); // Convert to lowercase
      convertedStr += convertedChar;
    } else if (charCode >= 97 && charCode <= 122) { // Lowercase letters (a-z)
      const convertedChar = String.fromCharCode(charCode - 32); // Convert to uppercase
      convertedStr += convertedChar;
    } else {
      convertedStr += str.charAt(i); // Keep non-alphabetic characters unchanged
    }
  }
  
  return convertedStr;
}

// Example usage
console.log(convertCase('HeLlo WorLD')); // Output: hElLO wORld
Editor is loading...