function hasOnly
hasOnly<T>(
list: T[],
...values: T[]
): boolean

Checks whether a list contains only the specified values.

The order of values does not matter, but the list must contain every specified value and must not contain any additional values. Duplicate values are ignored, since both the list and expected values are compared as sets.

Examples

Example 1

hasOnly([1, 2, 3], 1, 2, 3); // true hasOnly([1], 1, 2); // false hasOnly([2, 1], 1, 2); // true hasOnly([1, 1], 1); // true

Type Parameters

The type of values in the list.

Parameters

list: T[]

The list to compare.

...values: T[]

Return Type

boolean

true if the list contains only the specified values; otherwise, false.

Usage

import { hasOnly } from ".";