Skip to main content

hasOnly

Verifies all items of an array, collection or enumerable object pass the truth function.

Signature

hasOnly<T>(
list: TList<T> | undefined,
fn: (item: T) => boolean
): boolean

Parameters

NameTypeOptionalDescription
listT[] | undefinedNoSpecifies the array, collection or enumerable object to iterate through.
fn(item: T) => booleanNoSpecifies the truth function. Each item is supplied to the function, passing the item as argument. The function should return a boolean value with the individual verification result.

Return value

Returns true when all items pass the verification test.

Example

import { hasOnly } from "@tripetto/runner";

hasOnly<number>([1, 2, 3], (nItem: number) => nItem > 0); // Returns `true`
hasOnly<number>([1, 2, 3], (nItem: number) => nItem > 1); // Returns `false`