0.0.1 • Published 4 years ago

group-consecutive-numbers v0.0.1

Weekly downloads
3
License
-
Repository
-
Last release
4 years ago

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]]