const solution = string => string .split('') .map(char => char.search(/[a-z]/) !== -1 ? char.toUpperCase() : char.toLowerCase(), ) .join(''); const result = solution('StuDY'); console.log(result);