function caseConvert(str) { return str.replace(/([a-z]*)([A-Z]*)/g,(m,s1,s2)=>{ return `${s1.toUpperCase()}${s2.toLowerCase()}` }) } function upperStr(str){ let strArr = [...str]; let arrCase = "" for(var key in strArr) { if(/[a-z]/.test(strArr[key])) { arrCase += strArr[key].toUpperCase(); } else { arrCase += strArr[key].toLowerCase(); } } console.log(arrCase) } upperStr('aBcDeFJ') console.log(caseConvert('aBcDsf1w33e34wefeFJ'))