Skip to main content
3 of 3
added an explanation
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 67 bytes

f=([c,...a])=>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<1\$. If c is not found in a[], a.indexOf(c) returns \$-1\$ and we just pass a[] unchanged to the next iteration.

Arnauld
  • 197.7k
  • 20
  • 179
  • 650