DEV Community

ananthaprathyusha94
ananthaprathyusha94

Posted on

JAVASCRIPT toggle upper to lower/lower to upper

function isUpperCase(str) {
    return str === str.toUpperCase();
}

function isLowerCase(str) {
    return str === str.toLowerCase();
}


var upperLowerString  = "UpperLowerCasestring";
  upperLowerString = [...upperLowerString];  
var upperLowerStringToggled = upperLowerString.map(f => {
  if(isUpperCase(f))
    return f.toLowerCase();
  else
    return f.toUpperCase();

})
.reduce((a,b) => a+b);

console.log(upperLowerStringToggled);


Top comments (0)