Skip to content

Instantly share code, notes, and snippets.

@omzi
Last active November 12, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omzi/58152d60f62bd2429edf2317306a2485 to your computer and use it in GitHub Desktop.
Save omzi/58152d60f62bd2429edf2317306a2485 to your computer and use it in GitHub Desktop.
Returns a string with inversed cases
/**
* Returns a string with inversed cases
* @param {String} string The 'string' to inverse the cases of its characters
*/
const caseInverse = string => {
let inversedString = '';
for (const letter of string) {
if (letter.toUpperCase() === letter) {
inversedString += letter.toLowerCase()
} else {
inversedString += letter.toUpperCase()
}
}
return inversedString;
}
module.exports = caseInverse;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment