https://github.com/strarsis/group-numbers
Partitions an array of numbers into continuous groups.
https://github.com/strarsis/group-numbers
Last synced: about 2 months 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 (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-24T16:18:44.000Z (over 9 years ago)
- Last Synced: 2025-04-22T10:17:09.484Z (3 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- 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.[](https://david-dm.org/strarsis/group-numbers)
[](https://travis-ci.org/strarsis/group-numbers)
[](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.