JSPM

@strong-roots-capital/slices-of

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q30528F
  • License ISC

Generate all slices of given length out of an array

Package Exports

  • @strong-roots-capital/slices-of

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@strong-roots-capital/slices-of) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 ] ]
  • atlas-for-window
    • does not include lists of partial length
    • optimized for speed
    • not a generator
    • no static types