R, 49 bytes
function(w,a,`[`=chartr)"a-z"[a,sort(a["a-z",w])]
Try it online!
Translates words from given alphabet to a-z
, then sorts and then translates back.
Uses flexible I/O rules (vector of words and alphabet as string).
With strict I/O rules it goes up by a lot (R is not very good with strings):
R, 112 bytes
function(s,`/`=strsplit,t=el(s/" "))paste(chartr("a-z",t[2],sort(chartr(t[2],"a-z",el(t[1]/",")))),collapse=",")
Try it online!
Here we do the splitting of the input string inside the function.
First, we redefine /
to be strsplit
. It always returns a list, so we will need to extract the first element (which is shortest done by el
). We split the words from the alphabet on
and then the words themselves on ,
.
Then we do the same trick as in the main answer.
At the end we collapse the whole vector with ,
using paste
.
With many strange function redefinitions:
R, 111 bytes
function(s,`?`=el,`[`=chartr,`/`=strsplit,t=?s/" ")paste("a-z"[t?2,sort((t?2)["a-z",?(t?1)/","])],collapse=",")
Try it online!
Here we also redefine [
to be chartr
, so we cannot use [
to subscript t
anymore, but we can use el
for this purpose.
This leads us also to redefining ?
to be el
(after some trial and error with operator precedence). It is worth noting, that ?
can act as binary and unary operator and has the lowest precedence of all.
Sort by custom alphabet
or something more creative? \$\endgroup\$