Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/sequence-positions
Resolve all start/end positions at which a given sequence of elements can be found in the array
https://github.com/shinnn/sequence-positions
Last synced: 27 days ago
JSON representation
Resolve all start/end positions at which a given sequence of elements can be found in the array
- Host: GitHub
- URL: https://github.com/shinnn/sequence-positions
- Owner: shinnn
- Created: 2016-12-21T11:30:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-28T05:13:33.000Z (over 7 years ago)
- Last Synced: 2024-04-24T18:09:23.906Z (7 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sequence-positions
[![NPM version](https://img.shields.io/npm/v/sequence-positions.svg)](https://www.npmjs.com/package/sequence-positions)
[![Bower version](https://img.shields.io/bower/v/sequence-positions.svg)](https://github.com/shinnn/sequence-positions/releases)
[![Build Status](https://travis-ci.org/shinnn/sequence-positions.svg?branch=master)](https://travis-ci.org/shinnn/sequence-positions)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/sequence-positions.svg)](https://coveralls.io/r/shinnn/sequence-positions)Resolve all start/end positions at which a given sequence of elements can be found in the array
```javascript
import sequencePositions from 'sequence-positions';sequencePositions(['a', 'b', 'a', 'b', 'c', 'd', 'a', 'b', 'c'], ['a', 'b', 'c']);
//=> [{start: 2, end: 4}, {start: 6, end: 8}]
```|index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|:------|---|---|---|---|---|---|---|---|---|
|array | a | b | a | b | c | d | a | b | c |
|matched| | | ○ | ○ | ○ | | ○ | ○ | ○ |## Installation
### [npm](https://www.npmjs.com/)
```
npm install sequence-positions
```### [bower](https://bower.io/)
```
bower install sequence-positions
```## API
### sequencePositions(*array*, *searchArray* [, *fromIndex*])
*array*: `Array`
*searchArray*: `Array` (the sequence of values to search for)
*fromIndex*: `Number` (index in the array where to begin searching)
Return: `Array` of objects with `start` and `end` properties```javascript
indexOfSequence([1, '1', true, '1', 1, Buffer.from('1'), '1', 1, '1'], [1, '1']);
//=> [{start: 0, end: 1}, {start: 7, end: 8}]
indexOfSequence([1, '1', true, '1', 1, Buffer.from('1'), '1', 1, '1'], [1, '1'], 1);
//=> [{start: 7, end: 8}]indexOfSequence(['a'], ['b']); //=> []
indexOfSequence(['a'], []); //=> []
indexOfSequence([], ['b']); //=> []
```## License
[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed)