Returns the middle element or the right one when the number of elements is even.

Type signature

<T>(xs: T[]) => T | undefined

Examples

midpoint([1, 2, 3, 4, 5]);
// ⇒ 3
Try in REPL
midpoint([1, 2, 3, 4]);
// ⇒ 3
Try in REPL

Questions

  • How to get the element in the middle of an array?
  • How to get the middle element of an array?

TypeScript sourceJavaScript source