group-consecutive-numbers
v0.0.1
Published
Group all consecutive numbers in array
Downloads
80
Maintainers
Readme
group-consecutive-numbers
groups all consecutive numbers in
array
Installation
npm install group-consecutive-numbers --save
Usage
import group from 'group-consecutive-numbers'
const numbers = [1, 2, 4, 6, 8, 11, 7]
const grouped = group(numbers)
console.log(grouped)
grouped
variable would be:
[
[1, 2],
[6, 7, 8]
]
If you want to receive only groups that have 3 or more items (array.length
) you can provide second argument:
const grouped = group(numbers, 3)
This time grouped
variable would be:
[[6, 7, 8]]