reduce-first
Return early from reduce
Last updated 6 years ago by bconnorwhite .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install reduce-first 
SYNC missed versions from official npm registry.

reduce-first

npm typescript GitHub stars Twitter Follow

Return early from reduce.

.find() returns the element from an array, and .reduce() loops over every element. reduceFirst combines these to return a transformation of the first item that returns a value.

Installation

yarn add reduce-first
npm install reduce-first

API

import reduceFirst from "reduce-first";

const list = ["a", "b", "c", "d", "e"];

reduceFirst(list, (value, index, arr) => {
  if(value === "c") {
    return `found ${value}`;
  }
}); // "found c"

reduceFirst(list, (value, index, arr) => {
  if(value === "x") {
    return `found ${value}`;
  }
}); // undefined

Dev DependenciesDavid

License license

MIT

Current Tags

  • 1.0.1                                ...           latest (6 years ago)

2 Versions

  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |