36
\$\begingroup\$

Note: The winning answer will be selected on 4/12/17 the current winner is Jolf, 1 byte.

I'm surprised that we haven't had a what's my middle name challenge on this site yet. I did alot of searching but found nothing. If this is a dup, please flag it as such.

Your challenge

Parse a string that looks like Jo Jean Smith and return Jean.

Test cases

Input: Samantha Vee Hills
Output: Vee

Input: Bob Dillinger
Output: (empty string or newline)

Input: John Jacob Jingleheimer Schmidt
Output: Jacob Jingleheimer

Input: Jose Mario Carasco-Williams
Output: Mario

Input: James Alfred Van Allen
Output: Alfred Van 

(That last one is incorrect technically, but fixing that would be too hard.)

Notes:

  • Names will always have at least 2 space-separated parts, with unlimited middle names between them or can be a list/array of strings.
  • Names may contain the alphabet (case-insensitive) and - (0x2d)
  • You may output a trailing newline.
  • You may require input to have a trailing newline.
  • Input from STDIN, a function parameter, or command-line argument is allowed, but hard-coding it in is not allowed.
  • Standard loopholes forbidden.
  • Output may be function return value, STDOUT, STDERR, etc.
  • Trailing spaces/newlines/tabs in the output are allowed.
  • Any questions? Comment below!

This is , so the shortest anwser in bytes wins!

\$\endgroup\$
20
  • 2
    \$\begingroup\$ Can the output be a list of strings? \$\endgroup\$ Apr 2 '17 at 14:34
  • 5
    \$\begingroup\$ If other formats than a space-separated string are allowed, please edit that into the specification. \$\endgroup\$ Apr 2 '17 at 14:46
  • 5
    \$\begingroup\$ @programmer5000: if the input can be a list of strings, how about the output? Is ["John", "Jacob", "Jingleheimer", "Schmidt"] -> ["Jacob", "Jingleheimer"] a valid solution? \$\endgroup\$
    – nimi
    Apr 2 '17 at 15:17
  • 3
    \$\begingroup\$ Are leading spaces allowed? \$\endgroup\$
    – betseg
    Apr 2 '17 at 15:32
  • 4
    \$\begingroup\$ @DJ Because "Van" isn't his middle name, it's part of his last name. A particularly vexing case is David Lloyd George, whose first name is David and last name is Lloyd George. Any attempt to parse real people's names like this is doomed. In fact, you can't even tell what the first and last names are (think Li Shi). \$\endgroup\$ Apr 3 '17 at 2:16

68 Answers 68

1 2
3
0
\$\begingroup\$

JavaScript (ES6), 16 Bytes

x=>x.slice(1,-1)

Simple. Return the array passed from the second element to the second from last.

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! Nice submission! \$\endgroup\$
    – user58826
    Apr 5 '17 at 17:30
0
\$\begingroup\$

Lua, 39 bytes

print(io.read("*l"):match(" (.+) .+$"))
\$\endgroup\$
0
\$\begingroup\$

c, 53 bytes

main(a,b)char**b;{for(++b;--a>2;printf("%s ",*++b));}

Try it online

\$\endgroup\$
0
\$\begingroup\$

Noodel, 5 bytes

Input must be an array of the names.

Ẹ⁻2¤İ

Try it:)


How it works

      # Pushes the input on implicitly.
Ẹ⁻2¤İ
Ẹ     # Takes the last item of an array and pushes it to the back.
 ⁻2   # Pop the first two items off of the array.
   ¤  # Push the string "¤" onto the stack which represents a space.
    İ # Concatenates the array elements by the "¤" string.
      # Implicitly output the top of the stack to the screen.

<div id="noodel" code="Ẹ⁻2¤İ" input='["James", "Alfred", "Van", "Allen"]' cols="10" rows="2"/>

<script src="https://tkellehe.github.io/noodel/noodel-latest.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>

\$\endgroup\$
0
\$\begingroup\$

Javascript ES6 23Bytes

x=>x.pop()*x.shift()||x

use * instead of && to save 1 byte

Try it online

\$\endgroup\$
0
\$\begingroup\$

Tcl, 28 bytes

proc R n {lrange $n 1 end-1}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Japt, 7 3 bytes

s1J

Try it online!

This is essentially Input.slice(1,-1). The -1 wraps around to the last item in the input.

\$\endgroup\$
0
\$\begingroup\$

Gambit Scheme (gsi), 48 bytes

(lambda(x)(if(>(length x)2)(cadr(reverse x))""))

Try it online!

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy