Checks if the given array contains exactly one element.

Type signature

<T>(xs: T[]) => boolean

Examples

single([1]);
// ⇒ true
Try in REPL
single([1, 2, 3]);
// ⇒ false
Try in REPL
single([]);
// ⇒ false
Try in REPL

Questions

  • How to check if an array contains only one element?

TypeScript sourceJavaScript source