Implement swap encoding Swap encoding is an encoding method where you iterate through a string, reversing sections of it between pairs of identical characters.
The basic algorithm
For each character in the string:
Check: Does the string contain the character again, after the instance you found?
If so, then modify the string by reversing the section between the character and the next instance, inclusive.
Otherwise do nothing.
Example
Start with the string 'eat potatoes'.
e is found again, so reverse that section: eotatop taes
o is found again, so reverse that section (doing nothing as it is palindromic)
t is found again, so reverse that section (doing nothing as it is palindromic)
a is found again, so reverse that section: eotat potaes
t is found again, so reverse that section: eotatop taes
None of 'op taes' are found again, so eotatop taes is our final string!
Your challenge
Your challenge is to make a program or function that takes a string as input and returns it encoded as above. Capital letters and lowercase letters are treated as different, and all characters, including spaces, can be swapped.
Testcases
Sandbox for Proposed Challenges =&gt; SahC Pr foropox dbosenallednges
Collatz, Sort, Repeat =&gt; CoS ,ztrollaepeR ,tat
Write a fast-growing assembly function =&gt; Wrgnufa ylbme asa f g-tesstcnoritiwoin
Decompress a Sparse Matrix =&gt; Dera aM ssrtapmocese Sprix
Rob the King: Hexagonal Mazes =&gt; Rog: Kinob eH lagnaM thezaxes
Determine if a dot(comma) program halts =&gt; Detoc(tlamarommi finerp ha mrgod a) ets
Closest Binary Fraction =&gt; CloinosestiB Fry tcaran
Quote a rational number =&gt; Qunatebmuoiton re al ar
Solve the Alien Probe puzzle =&gt; SorP Alveht en eilzzup elobe

Yes I just took the titles of various sandboxed challenges for the testcases.
My reference implementation is available here if anyone wants it.
This is actually an encoding as reverse(swap(reverse(string))) decodes it.
JavaScript (ES6), 67 bytes

f=([c,...a])=&gt;c?c+f([...a.splice(0,a.indexOf(c)).reverse(),...a]):a

Try it online!
How?
a.splice(0, n) removes and returns the first \$n\$ entries in a[] if \$n\ge1\$ or removes nothing and returns an empty array if \$n&lt;1\$. If c is not found in a[], a.indexOf(c) returns \$-1\$ and we just pass a[] unchanged to the next iteration.