Function filterBetween

  • Yields elements from array that match a given predicate, and moreover are between the given startIndex (inclusive) and endIndex (exclusive).

    While this can be done with in the in-built array.filter function, it will needlessly iterate through the whole array. It also avoids another alternative of slicing the array before using filter.

    import { filterBetween } from 'https://unpkg.com/ixfx/dist/data.js';

    // Return 'registered' people between and including array indexes 5-10
    const filtered = [...filterBetween(people, person => person.registered, 5, 10)];

    Type Parameters

    • V

    Parameters

    • array: readonly V[] | V[]

      Array to filter

    • predicate: ((value: V, index: number, array: readonly V[] | V[]) => boolean)

      Filter function

        • (value, index, array): boolean
        • Parameters

          • value: V
          • index: number
          • array: readonly V[] | V[]

          Returns boolean

    • OptionalstartIndex: number

      Start index (defaults to 0)

    • OptionalendIndex: number

      End index (by default runs until end)

    Returns Generator<V>