Skip to content

Split an array into multiple ones, using a custom value as the separator.

Notifications You must be signed in to change notification settings

mk-pmb/split-array-by-const-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

split-array-by-const

Split an array into multiple ones, using a custom value as the separator.

API

This module expoers one function:

splitArrayByConst(a, c)

Returns an array of (potentially empty) arrays, each with items found in a before, between, and after each occurrences of c.

Usage

from usage.js:

var split = require('split-array-by-const'), a;
a = [
  'hello', 'world', null,
  { foo: 'bar' }, null,
  [ 12, 34, null, 56 ], null,
  null,
  true, { qux: null }, null,
];
equal(split(a, null), [
  [ 'hello', 'world' ],
  [ { foo: 'bar' } ],
  [ [ 12, 34, null, 56 ] ],
  [],
  [ true, { qux: null } ],
  [],
]);

Known issues

  • Needs more/better tests and docs.

 

License

ISC

About

Split an array into multiple ones, using a custom value as the separator.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published