Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strarsis/group-numbers
Partitions an array of numbers into continuous groups.
https://github.com/strarsis/group-numbers
Last synced: 13 days ago
JSON representation
Partitions an array of numbers into continuous groups.
- Host: GitHub
- URL: https://github.com/strarsis/group-numbers
- Owner: strarsis
- License: mit
- Created: 2015-10-26T14:08:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-24T16:18:44.000Z (almost 9 years ago)
- Last Synced: 2024-10-18T23:55:14.451Z (about 1 month ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# group-numbers
Partitions an array of numbers into continuous groups.[![david](https://david-dm.org/strarsis/group-numbers.svg)](https://david-dm.org/strarsis/group-numbers)
[![Build Status](https://travis-ci.org/strarsis/group-numbers.svg)](https://travis-ci.org/strarsis/group-numbers)
[![NPM](https://nodei.co/npm/group-numbers.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/group-numbers/)
Usage
-----
````
npm install group-numbers
````
````
numberRange([ 43, 44, 45, 46, 51, 53, 54 ]);
=> [ [ 43, 44, 45, 46 ], 51, [ 53, 54 ] ]
````For having single elements in array, too:
````
numberRange([ 43, 44, 45, 46, 51, 53, 54 ], false);
=> [ [ 43, 44, 45, 46 ], [ 51 ], [ 53, 54 ] ]
````Arguments
---------
### numbers
The array of numbers to be grouped.### returnSingleElements
Whether to return single elements in the array as single elements or in an array (of a single element). Defaults to true.
(Passed to underlying arr-group method)Note
----
The numbers in the passed array are sorted naturally first in order for grouping to work properly.