Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/repetition-ranges
Get start/end positions where a given value consecutively appears in the array
https://github.com/shinnn/repetition-ranges
Last synced: 27 days ago
JSON representation
Get start/end positions where a given value consecutively appears in the array
- Host: GitHub
- URL: https://github.com/shinnn/repetition-ranges
- Owner: shinnn
- License: isc
- Created: 2016-12-26T09:42:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-01T04:40:51.000Z (about 6 years ago)
- Last Synced: 2024-10-11T22:47:29.698Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://npm.runkit.com/repetition-ranges
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# repetition-ranges
[![npm version](https://img.shields.io/npm/v/repetition-ranges.svg)](https://www.npmjs.com/package/repetition-ranges)
[![Build Status](https://travis-ci.org/shinnn/repetition-ranges.svg?branch=master)](https://travis-ci.org/shinnn/repetition-ranges)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/repetition-ranges.svg)](https://coveralls.io/github/shinnn/repetition-ranges)Get start/end positions where a given value consecutively appears in the array
```javascript
import repetitionRanges from 'repetition-ranges';repetitionRanges(['a', 'b', 'a', 'a', 'b', 'a', 'a', 'a'], 'a');
//=> [{start: 2, end: 3}, {start: 5, end: 7}]
```| index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| :--------------------------|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| array | a | b | a | a | b | a | a | a |
| (`a` appeared) | ○ | | ○ | ○ | | ○ | ○ | ○ |
| `a` consecutively appeared | | | ○ | ○ | | ○ | ○ | ○ |## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install repetition-ranges
```## API
```javascript
import repetitionRanges from 'repetition-ranges';
```### repetitionRanges(*array*, *searchValue*)
*array*: `Array`
*searchValue*: any type (the value to resolve its repetition ranges)
Return: `Array` of objects with `start` and `end` properties```javascript
repetitionRanges([1, 1, 1], 1); //=> [{start: 0, end: 2}]
repetitionRanges([1, 1, '1', 1, 1, Symbol('1')], 1); //=> [{start: 0, end: 1}, {start: 3, end: 4}]repetitionRanges(['a', 'b'], 'c'); //=> []
repetitionRanges(['a', 'b', 'a'], 'a'); //=> []
repetitionRanges([], 'a']); //=> []
```## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe