Skip to main content
Corrected typo in code
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

This is the way I would do it. Not concise, but reasonably efficient and easy to understand.

middle[x_List] := Module[{s, t},
  t = Quotient[s = Length @ x, 2];
  If[EvenQ @ s, {x[[t ;; t + 1]]}, {x[[t + 1]]}]]

This is the way I would do it. Not concise, but reasonably efficient and easy to understand.

middle[x_List] := Module[{s, t},
  t = Quotient[s = Length @ x, 2];
  If[EvenQ @ s, {x[[t ;; t + 1]]}, {x[[t + 1]]}]]

This is the way I would do it. Not concise, but reasonably efficient and easy to understand.

middle[x_List] := Module[{s, t},
  t = Quotient[s = Length @ x, 2];
  If[EvenQ @ s, x[[t ;; t + 1]], {x[[t + 1]]}]]
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

This is the way I would do it. Not concise, but reasonably efficient and easy to understand.

middle[x_List] := Module[{s, t},
  t = Quotient[s = Length @ x, 2];
  If[EvenQ @ s, {x[[t ;; t + 1]]}, {x[[t + 1]]}]]