Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/madarche/array-segments

Finds element segments matches in an array
https://github.com/madarche/array-segments

Last synced: about 1 month ago
JSON representation

Finds element segments matches in an array

Awesome Lists containing this project

README

        

array-segments
==============

[![NPM version](http://img.shields.io/npm/v/array-segments.svg)](https://www.npmjs.org/package/array-segments)

Finds element segments matches in an array.

Usage
-----

```javascript
const array_segments = require('array-segments');

let res

res = array_segments.match(
['a', 'b', 'c', 'd', 'e', 'f', 'a', 'z', 'a', 'b'],
[
['c', 'd', 'e'],
['b', 'c', 'd', 'e'],
['a', 'z'],
['a', 'b'],
['a']
])

console.log(res)
// [ { segment: [ 'c', 'd', 'e' ], indices: [ 2 ] },
// { segment: [ 'a', 'z' ], indices: [ 6 ] },
// { segment: [ 'a', 'b' ], indices: [ 0, 8 ] } ]

// Case insensitive match
res = array_segments.match(
['a', 'b', 'c', 'D', 'E', 'f', 'a', 'z', 'a', 'b'],
[
['C', 'd', 'E'],
['b', 'c', 'd', 'e'],
['a', 'z'],
['a', 'b'],
['a']
],
{ignore_case: true})

console.log(res)
// [ { segment: [ 'c', 'd', 'e' ], indices: [ 2 ] },
// { segment: [ 'a', 'z' ], indices: [ 6 ] },
// { segment: [ 'a', 'b' ], indices: [ 0, 8 ] } ]
```

Contributions
-------------

Pull Requests and contributions in general are welcome as long as they follow
the [Node aesthetic].

[Node aesthetic]: http://substack.net/node_aesthetic