[Question]
  [
Your challenge is to take a name (string) as input, like
```
Albert Einstein
```
and output:
```
Einstein, Albert
```
## Pseudocode:
```
set in to input
set arr to in split by " "
set last to the last element of arr
remove the last element of arr
set out to arr joined with " "
prepend ", " to out
prepend last to out
output out
```
## More test cases:
```
John Fitzgerald Kennedy => Kennedy, John Fitzgerald
Abraham Lincoln => Lincoln, Abraham
```
## Rules
* The input will always match the regex `^([A-Z][a-z]+ )+([A-Z][a-z]+)$`.
* You don't need to handle [weird names](https://codegolf.stackexchange.com/questions/114927/whats-my-middle-name#comment280423_114927), even if the output is technically incorrect it is fine here.
* Trailing whitespace / newline is OK.
* Any questions? Comment below!
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
### Code:
```
',ì#Áðý
```
Uses the **05AB1E** encoding. [Try it online!](https://tio.run/nexus/05ab1e#@6@uc3iN8uHGwxsO7/3/3zGpKDEjMVfBJzMvOT8nDwA "05AB1E – TIO Nexus")
### Explanation:
```
',ì         # Prepend the input to ","
   #        # Split on spaces
    Á       # Rotate every element one position to the right (wrapping)
     ðý     # Join the array by spaces
```
[Answer]
# JavaScript (ES6), 34 bytes
```
s=>s.replace(/(.+) (.+)/,'$2, $1')
```
# Demo:
```
let f = s=>s.replace(/(.+) (.+)/,'$2, $1')
;[ 'Albert Einstein', 'John Fitzgerald Kennedy', 'Abraham Lincoln' ].forEach(
  s => console.log(`${s} => ${f(s)}`)
)
```
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~19~~ ~~17~~ 16 bytes
*Edit: Thanks to Riker for saving 3 bytes*
```
(.+) (.+)
$2, $1
```
[Try it online!](https://tio.run/nexus/retina#@6@hp62pACK4VIx0FFQM///3ys/IU3DLLKlKTy1KzElR8E7Ny0tNqQQA "Retina – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
;”,Ḳṙ-K
```
[Try it online!](https://tio.run/##y0rNyan8/9/6UcNcnYc7Nj3cOVPX@//h9kdNayL//49W8srPyFNwyyypSk8tSsxJUfBOzctLTalU0lFQcsxJSi0qUXDNzCsuSc3MAwslFSVmJOYq@GTmJefn5CnFAgA "Jelly – Try It Online")
I don't know Jelly very well, but reading other answers it looked like they didn't use an optimal algorithm... so here it is:
### Explanation
```
;”,Ḳṙ-K
;”,        Append a comma to the end of the string
   Ḳ       Split on spaces
    ṙ-     Rotate the array by -1 (1 time towards the right)
      K    Join with spaces
```
[Answer]
# [V](https://github.com/DJMcMayhem/V) / vim, ~~9~~ 8 bytes
```
$bD0Pa, 
```
[Try it online!](https://tio.run/nexus/v#@6@S5GIQkKij8P@/V35GnoJbZklVempRYk6KgndqXl5qSiUA)
Saved one Byte thanks to 
Note there is a trailing space character. Leaves a trailing space, which is allowed per the rules.
Explanation:
```
$       " move the cursor to the end of the line
 b      " move the cursor to the beginning of the current word
  D     " delete to the end of the line
   0    " move the cursor to the start of the line
    P   " paste in front of the cursor.
     a  " append (enter insert mode with the cursor one character forward)
      , " Literal text, ", "
```
[Answer]
# [Python 2](https://docs.python.org/2/), 39 bytes
```
f,l=input().rsplit(' ',1);print l+',',f
```
[Try it online!](https://tio.run/nexus/python2#FcixDoIwEADQ3a@4dCnEhoQV4@Cgg/IJLgUOe8l5NMcRoz9fwxvfJxEjtN2zzIHPJHmzqm50zUxWefChrU9ZSQz46IMPcynuviSBG9nvhRp5ggeK4PR1B3fhAdXgSrIakuwzaEzxDT3JuLC4Pw "Python 2 – TIO Nexus")
Yup, `rsplit`.
[Answer]
## Mathematica, 52 40 bytes
```
StringReplace[x__~~" "~~y__:>y<>", "<>x]
```
[Answer]
# Vim, 10 bytes/keystrokes
```
v$F dA, <esc>p
```
[Try it online!](https://tio.run/nexus/v#@1@m4qaQ4qijIF3w/79XfkaegltmSVV6alFiToqCd2peXmpKJQA "V – TIO Nexus")
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 27 bytes
```
i:0(?v
" ,"~<^r/
=" ":}o!/?
```
[Try it online!](https://tio.run/nexus/fish#@59pZaBhX8alpKCjVGcTV6TPZaukoGRVm6@ob///v2NSUWJGYq6CT2Zecn5OHgA "><> – TIO Nexus")
[Answer]
# C, 45 bytes
EDIT: I just now noticed the requirement for the input possibly having more than two words. I'll leave it as-is with a note that this only works for two words.
EDIT: removed `\n`. Add 2 bytes if you consider it necessary.
```
main(a,b)int**b;{printf("%s, %s",b[2],b[1]);}
```
Compiles with `gcc name.c`, GCC 6.3.1. Ignore warnings. Usage:
```
$./a.out Albert Einstein
Einstein, Albert
```
Abuse of language:
* Implicit return type `int` of `main` and nothing returned.
* Implicit declaration of `printf`. GCC will include it anyway.
* Wrong type of `b`. Doesn't matter with `%s`
Thanks to @Khaled.K for the tips on using `main(a,b)int**b;` rather than `main(int a, int **b)`.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 22 bytes
```
->s{s[/\w+$/]+", #$`"}
```
[Try it online!](https://tio.run/nexus/ruby#S7P9r2tXXF0crR9Trq2iH6utpKOgrJKgVPu/oLSkWCEtWsm9tLgksSxfwSexILOqKlEplgsm452TWFqs4JtYlJmo4FSUmJeSWJpapBT7HwA "Ruby – TIO Nexus")
[Answer]
# sed, 19 + 1 for -E = 20 bytes
```
s/(.*) (.*)/\2, \1/
```
Must use -r (GNU) or -E (BSD, recent GNUs) to avoid having to escape the grouping parenthesis.
If written on the command-line, must be enclosed in quotes to avoid being parsed as multiple tokens by the shell :
```
sed -E 's/(.*) (.*)/\2, \1/'
```
[Answer]
# C, 68 bytes
Hope it's not wrong to add another post but here's a slightly different solution than my previously posted C solution. This one accepts any number of names.
```
main(a,b)int**b;{for(printf("%s,",b[--a]);--a;printf(" %s",*++b));}
```
Compile with `gcc name.c` (GCC 6.3.1) and ignore warnings. Usage:
```
$./a.out John Fitzgerald Kennedy
Kennedy, John Fitzgerald
```
Thanks to @Khaled.K for the tips on `main(a,b)int**b;`
Thanks for the tip on the for loop to @Alkano.
[Answer]
# Mathematica, 45 bytes
```
#/.{a__,s=" ",b__}/;{b}~FreeQ~s->{b,",",s,a}&
```
Saved a few bytes over [ngenisis's answer](https://codegolf.stackexchange.com/a/122329/56178) by taking input as a list of characters rather than as a string. Pure function that uses a pattern-replacement rule.
## Mathematica, 49 bytes
```
#~Join~{","," "}~RotateLeft~Last@Position[#," "]&
```
Another pure function taking a list of characters as input and returning a list of characters. This one appends `","` and `" "` to the input and then rotates the list of characters until the last space is at the end. (Thus the output has a trailing space, unlike the first function above.)
[Answer]
# C#, ~~76~~ 72 bytes
```
s=>System.Text.RegularExpressions.Regex.Replace(s,"(.+) (.+)","$2, $1");
```
*Saved 4 bytes with the help of @KevinCruijssen*
Old version using substrings for 76 bytes:
```
s=>s.Substring(s.LastIndexOf(' ')+1)+", "+s.Substring(0,s.LastIndexOf(' '));
```
[Answer]
# Awk, 18 characters
```
{$1=$NF", "$1}NF--
```
Sample run:
```
bash-4.4$ awk '{$1=$NF", "$1}NF--' <<< 'John Fitzgerald Kennedy'
Kennedy, John Fitzgerald
```
[Try it online!](https://tio.run/nexus/awk#@1@tYmir4uempKOgpGJY6@emq/v/v1d@Rp6CW2ZJVXpqUWJOioJ3al5eakolAA "AWK – TIO Nexus")
[Answer]
# JS (ES6), ~~52~~ 44 bytes
```
i=>(i=i.split` `,l=i.pop(),l+", "+i.join` `)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
Ḳ©Ṫ”,⁶®K
```
[Try it online!](https://tio.run/nexus/jelly#AS0A0v//4biywqnhuarigJ0s4oG2wq5L////Sm9obiBGaXR6Z2VyYWxkIEtlbm5lZHk "Jelly – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
#`',«.Áðý
```
[Try it online!](https://tio.run/nexus/05ab1e#@6@coK5zaLXe4cbDGw7v/f/fKz8jT8Ets6QqPbUoMSdFwTs1Ly81pRIA "05AB1E – TIO Nexus")
**Explanation**
```
#           # split input on spaces
 `          # push each name separately to stack
  ',«       # concatenate a comma to the last name
     .Á     # rotate stack right
       ðý   # join stack by spaces
```
[Answer]
# [Pyth](http://pyth.readthedocs.io/en/latest/index.html), 11 bytes
```
jd.>c+z\,d1
```
**Explanation:**
```
jd.>c+z\,d1
     +z\,      Append the "," to the input
    c+z\,d     Split the string on " "
  .>c+z\,d1    Rotate the array one element right
jd.>c+z\,d1    Join the array on " "
```
[Test it online!](https://pyth.herokuapp.com/?code=jd.%3Ec%2Bz%5C%2Cd1&input=John%20Fitzgerald%20Kennedy&debug=0)
[Answer]
# PHP, 45 Bytes
```
<?=preg_filter("#(.*) (.+)#","$2, $1",$argn);
```
[Try it online!](https://tio.run/nexus/php#s7EvyCjgUkksSs@zVfLKz8hTcMssqUpPLUrMSVHwTs3LS02pVLLmsrf7b2NvW1CUmh6flplTklqkoaSsoaelqaChp62prKSjpGKko6BiqKQDNknT@v9/AA "PHP – TIO Nexus")
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 26 bytes
```
echo ${!#}, ${@:1:$[$#-1]}
```
[Try it online!](https://tio.run/nexus/bash#@5@anJGvoFKtqFyrA6QcrAytVKJVlHUNY2v////vlZ@R998ts6QqPbUoMSflv3dqXl5qSiUA "Bash – TIO Nexus")
[Answer]
# MATLAB/[Octave](https://www.gnu.org/software/octave/), 37 bytes
```
@(a)regexprep(a,'(.+) (.+)','$2, $1')
```
[Try it online!](https://tio.run/nexus/octave#@@@gkahZlJqeWlFQlFqgkaijrqGnrakAItR11FWMdBRUDNU1/yfmFWuoO@YkpRaVKLhm5hWXZKbmAYUB "Octave – TIO Nexus")
Based on @ngenisis' Retina answer, we can also play the regex game in both Octave and MATLAB, saving a fair few bytes over my previous answer.
---
### Old Answer:
I'm going to leave this answer here as well considering it is a more unique way of doing it compared to a simple regex.
# [Octave](https://www.gnu.org/software/octave/), ~~49~~ 47 bytes
```
@(a)[a((b=find(a==32)(end))+1:end) ', ' a(1:b)]
```
[Old try it online!](https://tio.run/nexus/octave#@@@gkagZnaihkWSblpmXopFoa2tspKmRmpeiqaltaAWiFdR1FNQVEjUMrZJ0DTVj/yfmFWuoO@YkpRaVKLhm5hWXZKbmqWv@BwA "Octave – TIO Nexus")
An anonymous function to generate the output.
Basically the code first finds the last space in the string using `b=find(a==32)(end)`. Then It takes the end part of the string (after the space) using `a(b+1:end)`, where `b` is the output of finding the last space. It also takes the start of the string with `a(1:b-1)`, and concatenates both together with a `', '` in between.
I've already saved a few bytes vs the typical `find(a==32,1,'last')`. Not quite sure there is much more to save.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
ḲµṪ;⁾, ;K
```
## Explained, ish:
```
ḲµṪ;⁾, ;K
Ḳ           # Split the input by spaces
 µ          # Separate the link into two chains. Essentially calls the right half with the split string monadically.
  Ṫ         # The last element, (The last name), modifying the array.
   ;        # Concatenated with...
    ⁾,      # The string literal; ", "
       ;    # Concatenated with...
        K   # The rest of the array, joined at spaces.
```
[Try it online!](https://tio.run/##ATEAzv9qZWxsef//4biywrXhuao74oG@LCA7S////0pvaG4gRml0emdlcmFsZCBLZW5uZWR5 "Jelly – Try It Online")
[Try on all test cases.](https://tio.run/##y0rNyan8///hjk2Htj7cucr6UeM@HQVr7/@H2x81rYn8/z9aySs/I0/BLbOkKj21KDEnRcE7NS8vNaVSSUdByTEnKbWoRME1M6@4JDUzDyyUVJSYkZir4JOZl5yfk6cUCwA "Jelly – Try It Online")
[Answer]
# Python 3, 52 bytes
```
lambda s:s.split()[-1]+", "+" ".join(s.split()[:-1])
```
Very simple, could use golfing help. Just puts the last word at the front and joins them with ", ".
Testcase:
```
>>> f=lambda s:s.split()[-1]+", "+" ".join(s.split()[:-1])
>>> f("Monty Python")
'Python, Monty'
>>> f("Albus Percival Wulfric Brian Dumbledore")
'Dumbledore, Albus Percival Wulfric Brian'
```
[Answer]
# Japt, 14 bytes
```
U+', q'  é q' 
```
A port of [@programmer5000](https://codegolf.stackexchange.com/users/58826/programmer5000)'s [JavaScript answer](https://codegolf.stackexchange.com/a/122324/58826).
[Try it online!](https://tio.run/nexus/japt#@x@qra6jUKiuoHB4JYj6/1/JKzE3tVjBOSe1KFvBN7GiPDUnRwkA)
[Answer]
# Java, ~~110~~ 62 bytes
```
String d(String s){return s.replaceAll("(.+) (.+)","$2, $1");}
```
Non-static method.
-48 bytes thanks to Kevin Cruijssen 
[Answer]
## Perl 18+1=19 bytes
```
perl -pe '/\S+$/;$_="$&, $`"'
```
+1 for `-p`
[Answer]
# [PHP](https://php.net/), 62 59 bytes
-3 bytes, thanks Jörg
```
$a=explode(' ',$argn);echo array_pop($a).', '.join(' ',$a);
```
[Try it online!](https://tio.run/nexus/php#s7EvyCjgUkksSs@zVfdNzMovUsAg1a3/qyTaplYU5OSnpGqoK6jrgNVrWqcmZ@QrJBYVJVbGF@QXaKgkauqp6yio62XlZ@ZB1Wla//8PAA "PHP – TIO Nexus")
Old solution, 63 Bytes
Doesn't work if the person has 3 repeating names.
```
<?=($a=strrchr($argv[1]," ")).", ".str_replace($a,'',$argv[1]);
```
[Try it online](https://tio.run/nexus/php#@29jb6uhkmhbXFJUlJxRBGQWpZdFG8bqKCkoaWrqKekoKOkB5eKLUgtyEpNTgfI66uo6MFWa1v////fKz8hTcMssqUpPLUrMSVHwTs3LS02pBAA "Try it online")
[Answer]
# Vim, 6 keystrokes
```
i<C-p>, <End><C-w>
```
Leaves a trailing space character, which is allowed by the rules
Explanation:
```
i      Enter insert mode
<C-p>  Autocomplete with last word
,      Write ", "
<End>  Move the cursor to the end of the line
<C-w>  Delete the word behind the cursor
```
]