This is due to the definition of upcase!
and downcase!
. Here's upcase!
Upcases the contents of str, returning nil if no changes were made. Note: case replacement is effective only in ASCII region.
Notice that it returns nil
if no changes were made. In this case, if the character you are iterating over is already in the correct case, it'll return nil
and effectively remove the character from the string as part of your map
function.
In your specific example, you'll notice every other character is being removed because it's already in lower case and downcase!
is returning nil
.