Skip to main content
2 of 4
added 19 characters in body
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 159 bytes

icuSetCollate(locale="ASCII");K=chartr;K(A,N,sort(K(N<-"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw",A<-Reduce(paste0,c(LETTERS,letters)),scan(,""))))

Try it online!

Similar to others, translate the characters in the string using chartr into an appropriate order, then translate back.

The default collation order in the R install on TIO, en_US.UTF8, is very odd: while, for instance, e comes before E, ekF comes after EgHTk (those being the translations of "and" and "begin" in the unchanged test case). So I switch to an ASCII locale, which compares by byte value instead.

Giuseppe
  • 28.8k
  • 3
  • 31
  • 105