Checks if at least one element in the array satisfies the given condition.

Similar to JavaScript's native some() method but implemented in curried form for better compatibility with functional programming style. Returns true immediately when the first element satisfying the condition is found.

  const numbers = [1, 3, 5, 7, 8, 9];
const products = [
{ name: 'Apple', price: 100, inStock: true },
{ name: 'Banana', price: 50, inStock: false },
{ name: 'Orange', price: 80, inStock: true }
];

const hasEvenNumber = ArrayUtil.has(numbers)(num => num % 2 === 0);
console.log(hasEvenNumber); // true (8 exists)

const hasExpensiveItem = ArrayUtil.has(products)(product => product.price > 90);
console.log(hasExpensiveItem); // true (Apple costs 100)

const hasOutOfStock = ArrayUtil.has(products)(product => !product.inStock);
console.log(hasOutOfStock); // true (Banana is out of stock)
  • Type Parameters

    • T

      The type of elements in the array

    Parameters

    • elements: readonly T[]

      The readonly array to check

    Returns (pred: (elem: T) => boolean) => boolean

    A function that takes a predicate and returns a boolean