@strong-roots-capital/slices-of
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

slices-of Build status npm version codecov

Generate all slices of given length out of an array

Install

npm install @strong-roots-capital/slices-of

Use

import { slicesOf } from '@strong-roots-capital/slices-of'

const array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

const slices = slicesOf(4, array)
for (const slice of slices) {
    console.log(slice)
}
//=>[ 0 ]
//=>[ 0, 1 ]
//=>[ 0, 1, 2 ]
//=>[ 0, 1, 2, 3 ]
//=>[ 1, 2, 3, 4 ]
//=>[ 2, 3, 4, 5 ]
//=>[ 3, 4, 5, 6 ]
//=>[ 4, 5, 6, 7 ]
//=>[ 5, 6, 7, 8 ]
//=>[ 6, 7, 8, 9 ]
//=>[ 7, 8, 9, 10 ]


console.log(allSlicesOf(3, array))
//=>[ [ 0 ],
//=>  [ 0, 1 ],
//=>  [ 0, 1, 2 ],
//=>  [ 1, 2, 3 ],
//=>  [ 2, 3, 4 ],
//=>  [ 3, 4, 5 ],
//=>  [ 4, 5, 6 ],
//=>  [ 5, 6, 7 ],
//=>  [ 6, 7, 8 ],
//=>  [ 7, 8, 9 ],
//=>  [ 8, 9, 10 ] ]

Related

  • atlas-for-window
    • does not include lists of partial length
    • optimized for speed
    • not a generator
    • no static types

Readme

Keywords

Package Sidebar

Install

npm i @strong-roots-capital/slices-of

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

8.97 kB

Total Files

4

Last publish

Collaborators

  • amchelle
  • hamroctopus