1.0.2 • Published 6 years ago

array-split-by v1.0.2

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

Build Status Coverage Status Deps NPM version Downloads

Get help on Codementor available-for-advisory extra

Usage

Like String.prototype.split except that it works on array and accepts an iteratee which is invoked for each element in array to generate the criterion by which the separation is computed. The order of result values is determined by the order they occur in the array. The iteratee is invoked with three argument: (value, index, chunk, array)

❤️ Shameless plug

Installation

Install with npm.

npm install --save array-split-by

Example

const splitBy = require('splitby');

splitBy([1, 2, 3, "|", 4, 5, 6], val => val === "|"); // [[1, 2, 3], [4, 5, 6]]

splitBy([1, 2, 3], val => val % 2 === 0); // [[1], [3]]

splitBy([{x:0, a:true}, {x:1, a:true}, {x:2, a:false}, {x:1, a:true}], (val) => !val.a); // [[{"a": true, "x": 0}, {"a": true, "x": 1}], [{"a": true, "x": 1}]

Changelog

CI

You want to support my work?

I maintain this project in my free time, if it helped you, well, I would be grateful to buy a beer thanks to your paypal or Bitcoins, donation!

Francois-Guillaume Ribreau (npm@fgribreau.com)