Creates a string with uppercase characters converted to lowercase and vice versa.
...
) to convert str
into an array of characters.String.prototype.toLowerCase()
and String.prototype.toUpperCase()
to convert lowercase characters to uppercase and vice versa.Array.prototype.map()
to apply the transformation to each character, Array.prototype.join()
to combine back into a string.swapCase(swapCase(str)) === str
.const swapCase = str =>
[...str]
.map(c => (c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase()))
.join('');
swapCase('Hello world!'); // 'hELLO WORLD!'
JavaScript, String
Creates a new string with the results of calling a provided function on every character in the given string.
JavaScript, String
Converts a string to an array of characters.
JavaScript, String
Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row.