2.0.0 • Published 1 year ago

reduce-first v2.0.0

Weekly downloads
10
License
MIT
Repository
github
Last release
1 year ago

If I should maintain this repo, please ⭐️

DM me on Twitter if you have questions or suggestions.


Array.prototype.find returns the element from an array, and Array.prototype.reduce allows you to map to antother value. reduceFirst combines these to return a transformation of the first item that returns a value.

Installation

yarn add reduce-first
npm install reduce-first
pnpm add reduce-first

Usage

import reduceFirst from "reduce-first";

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

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

const result2 = reduceFirst(list, (value, index, arr) => {
  if(value === "x") {
    return `found ${value}`;
  }
});
// result2 === undefined
  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

MIT - MIT License