Skip to main content
2 of 4
added 597 characters in body
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 56 bytes

\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)

Attempt This Online!

How?
Ungolfed code: uses the descending argument of sort to control sorting order:

f=function(e,d,l){      # e=entry, d=destination, l=list of passenger floors
    u=e<d               # u=boolean: TRUE=going up; FALSE=going down
    i=!(l>e)-u          # i=elements of l in the first direction
    c(                  # join together the first & second directions
    sort(c(d,l[i])      # sort the stops in the first direction...
                  ,!u)  # using 2nd arg of sort: descending TRUE/FALSE=!u
    ,sort(l[!i]         # sort the stops in the second direction
              ,u)       # in the other order: descending TRUE/FALSE=u
    )
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60