Swap case of characters in a string
JavaScript
const swapCase = (str) => str
.split('')
.map((c) => (c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase()))
.join('')
Examples
swapCase('Hello World') // 'hELLO wORLD'
const swapCase = (str) => str
.split('')
.map((c) => (c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase()))
.join('')
swapCase('Hello World') // 'hELLO wORLD'