ts-data-forge
    Preparing search index...
    • Counts the number of elements that satisfy a predicate.

      Type Parameters

      • const Ar extends readonly unknown[]

      Parameters

      • array: Ar
      • predicate: (value: Ar[number], index: ArrayIndex<Ar>) => boolean

      Returns Uint32

      const words = ['Ada', 'Grace', 'Linus'] as const;

      const longWords = Arr.count(words, (word) => word.length > 4);
      const withCurried = Arr.count<string>((word) => word.includes('a'))(words);

      assert(longWords === 2);
      assert(withCurried === 2);
    • Counts the number of elements that satisfy a predicate.

      Type Parameters

      • E

      Parameters

      • predicate: (value: E, index: Uint32) => boolean

      Returns (array: readonly E[]) => Uint32

      const words = ['Ada', 'Grace', 'Linus'] as const;

      const longWords = Arr.count(words, (word) => word.length > 4);
      const withCurried = Arr.count<string>((word) => word.includes('a'))(words);

      assert(longWords === 2);
      assert(withCurried === 2);