Goal
This is a simple challenge. Your goal is to unscramble a string by swapping each letter with the next letter of the same case, while leaving non-letter characters unchanged.
Step by step explanation
The first character is a
E. We look for the next letter in upper case: it's aC. We swap these characters, which leads toCdoE!.We advance to the next character: this is a
d. We look for the next letter in lower case: it's ao. We swap these characters, which leads toCodE!.We advance to the next character: this is the
dthat we've just moved here. We ignore it, because it has already been processed.We advance to the next character: this is the
Ethat was moved here at step #1. We ignore it, because it has already been processed.We advance to the next character: this is a
!. We ignore it, because it's not a letter.
Rules
You can assume that the input string is made exclusively of printable ASCII characters, in the range 32 - 126.
You may write either a full program or a function, which either prints or returns the result.
If the input string contains an odd number of letters, the last remaining letter can't be swapped with another one and should remain in place, no matter its case. The same logic applies if the string contains an even number of letters, but an odd number of uppercase letters and an odd number of lowercase letters.
This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.
Test cases
Input : lLEhW OroLd!
Output: hELlO WorLd!
Input : rpGOZmaimgn uplRzse naC DEoO LdGf
Output: prOGRamming puzZles anD COdE GoLf
Input : eIt uqHKC RBWOO xNf ujPMO SzRE HTL EOvd yAg
Output: tHe quICK BROWN fOx juMPS OvER THE LAzy dOg
Input : NraWgCi: Nsas-eNEiTIsev rNsiTG!!
Output: WarNiNg: Case-sENsITive sTriNG!!
Not-so-random test cases:
Input : (^_^)
Output: (^_^)
Input : AWCTY HUOS RETP
Output: WATCH YOUR STEP
Input : hwn oeesd acsp nawyya
Output: who needs caps anyway
Input : SpMycaeIesKyBorekn
Output: MySpaceKeyIsBroken
Input : D's mroyr, Ivam. I'e faardi I act'n od htta.
Output: I'm sorry, Dave. I'm afraid I can't do that.

