1.0.2 • Published 3 years ago

async-array-find v1.0.2

Weekly downloads
124
License
MIT
Repository
github
Last release
3 years ago

async-array-find

Searching a large array using subarray division and wrapping them in a Promise.

install

npm i async-array-find

example

function createArray(N) {
    // [0, 1, 2, ... , N]
    return Array.from(Array(N).keys())
}


function timerun() {
    const run = Date.now()

    return {
        stop: function () {
            const stop = Date.now()

            return stop - run
        }
    }
}

async function arrayFindIndex() {
    let findIndex

    const timerunCreateArray = timerun()
    const arr = createArray(100000000)
    console.log('time createArray ' + timerunCreateArray.stop())


    function callback(item) {
        return item === 99999999
    }

    const timerunArrayFindIndex = timerun()
    findIndex = arr.findIndex(callback)
    console.log('time arr.findIndex ' + timerunArrayFindIndex.stop())
    console.log('index = ' + findIndex)

    const timerunAsyncArrayFindIndex = timerun()
    findIndex = await asyncArrayFindIndex(arr, callback, 10000)
    console.log('time asyncArrayFindIndex ' + timerunAsyncArrayFindIndex.stop())
    console.log('index = ' + findIndex)
}

arrayFindIndex()
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago