Skip to content

Find the item in an array with the highest computed value.

License

Notifications You must be signed in to change notification settings

Richienb/find-with

Repository files navigation

find-with Travis CI Build Status

Find the item in an array with the highest computed value.

NPM Badge

Install

npm install find-with

Usage

const findWith = require("find-with")

findWith(["a", "abc", "ab"], item => item.length)
//=> "abc"

findWith.multiple(["a", "abc", "abc", "ab"], item => item.length)
//=> ["abc", "abc"]

API

findWith(array, predicate)

Find the item in an array with the highest computed value.

findWith.multiple(array, predicate)

Find the items in an array with the highest computed values.

array

Type: array

The array to find the items from.

predicate

Type: (item, index, array) => number

A predicate that is provided with each item in the array.

item

The item in the array.

index

The index of the item in the array.

array

The array.