programming-examples/js/String/Input a string and converts upper case letters to lower and vice versa.js

6 lines
266 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
swapcase = function swapcase(str) {
return str.replace(/([a-z]+)|([A-Z]+)/g, function(match, chr) {
return chr ? match.toUpperCase() : match.toLowerCase();
});
}
console.log(swapcase('AaBbc'));