group-consecutive-numbers

0.0.1 • Public • Published

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

Package Sidebar

Install

npm i group-consecutive-numbers

Weekly Downloads

2

Version

0.0.1

License

none

Unpacked Size

4.71 kB

Total Files

11

Last publish

Collaborators

  • andreystepanov