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

R, 47 bytes

\(e,d,l,m=c(d,l))m[order(!(m<e)-(e<d),(m-e)^2)]

Attempt This Online!

Approach copied from Jonah's answer - upvote that one!


Previously: 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!

Uses the decreasing argument of sort to control sorting order.

Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60