Notorious Preying Mantis
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

first-match

0.0.1 • Public • Published

first-match Build Status

Finds the first element in an array that passes a callback test. Equivalent to _.find().

Installation

npm install first-match

Usage

first(array, [iterator], [context]). If an iterator is not passed, the method will just return the first truthy value in the array. The context defaults to the array being evaluated.

var first = require('first-match')
  , array = [0, 1, 2, 3, 4, 5]
 
first(array)                               // 1
first(array, function(n) { return n > 3 }) // 4
first(array, function(n) { return n % 2 }) // 1
first(array, function(n) { return n + 2 > this.length }) // 5

Keywords

none

install

npm i first-match

Downloadsweekly downloads

2,234

version

0.0.1

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar