@bemoje/arr-index-of-first-where

    1.0.1 • Public • Published

    @bemoje/arr-index-of-first-where

    Return the index of the first element of an array where the callback returns true. Returns -1 if none do.

    Version

    NPM version

    Travis CI

    dependencies

    Dependencies

    dependencies

    Stats

    NPM downloads Forks

    Donate

    Buy Me A Beer donate button PayPal donate button

    Installation

    npm install @bemoje/arr-index-of-first-where
    npm install --save @bemoje/arr-index-of-first-where
    npm install --save-dev @bemoje/arr-index-of-first-where

    Usage

    import arrIndexOfFirstWhere from '@bemoje/arr-index-of-first-where'
     
    const arr = [1, 2, 3, 4, 5]
     
    arrIndexOfFirstWhere(arr, (element) => {
        return element >= 3
    })
    //=> 2
     
    arrIndexOfFirstWhere(arr, (element) => {
        return element >= 6
    })
    //=> -1
     

    Tests

    Uses Jest to test module functionality. Run tests to get coverage details.

    npm run test

    API

    arrIndexOfFirstWhere

    Return the index of the first element of an array where the callback returns true. Returns -1 if none do.

    Parameters
    • arr Array The array to iterate

    • callback predicate The callback(element, index, array): boolean

    Returns

    any The first element to satisfy the condition

    predicate

    Type: Function

    Parameters
    • element any The current array element

    • index number The current index

    • array Array The array being itereated

    Returns

    boolean

    Install

    npm i @bemoje/arr-index-of-first-where

    DownloadsWeekly Downloads

    5

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    9.79 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar