1.0.1 • Published 6 years ago

filter-and-transform v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

filter-and-transform Build Status

This package exports a HoF that takes two parameters:

  • filterFn: Predicate with filter criteria
  • transformFn: Function with transformation logic

It returns a function that receives a single parameter:

  • collection: The collection to reduce

and reduces it returning an array of values resulting of running thru the transformFn the elements that returned truthy for the filterFn.

Example

const filterAndTransform = require('filter-and-transform');

const isOdd = number => ((number % 2) === 1);

const addOne = number => number + 1;

const getOddNumbersAndAddOne = filterAndTransform(isOdd, addOne);

getOddNumbersAndAddOne([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); // [2, 4, 6, 8, 10]

Requirements

Node >= v8.11.3