https://github.com/tomeraberbach/partition-interval
Partitions an interval as evenly as possible.
https://github.com/tomeraberbach/partition-interval
interval nodejs npm-module npm-package partitioning-algorithms
Last synced: about 1 year ago
JSON representation
Partitions an interval as evenly as possible.
- Host: GitHub
- URL: https://github.com/tomeraberbach/partition-interval
- Owner: TomerAberbach
- License: apache-2.0
- Created: 2024-03-25T02:49:23.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T03:35:35.000Z (over 1 year ago)
- Last Synced: 2025-03-18T16:13:25.095Z (over 1 year ago)
- Topics: interval, nodejs, npm-module, npm-package, partitioning-algorithms
- Language: TypeScript
- Homepage: https://npm.im/partition-interval
- Size: 647 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license-apache
Awesome Lists containing this project
README
partition-interval
Partitions an interval as evenly as possible.
## Features
- **Lazy:** returns an `Iterable` for the common case of not needing everything
in memory at once
- **Small:** just ~260 B minzipped
- **Robust:** property-based testing with
[`fast-check`](https://github.com/dubzzz/fast-check)
## Install
```sh
$ npm i partition-interval
```
## Usage
```js
import partitionInterval from 'partition-interval'
// Lazily iterate over the returned iterable.
for (const interval of partitionInterval([0, 99], 4)) {
console.log(interval)
}
//=> [ 0, 24 ]
//=> [ 25, 49 ]
//=> [ 50, 74 ]
//=> [ 75, 99 ]
// Collect the returned iterable into an array.
const intervals = [...partitionInterval([-31, 89], 5)]
console.log(intervals)
//=> [ [-31, -8], [-7, 16], [17, 40], [41, 64], [65, 89] ]
```
## Contributing
Stars are always welcome!
For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/partition-interval/issues/new).
## License
[MIT](https://github.com/TomerAberbach/partition-interval/blob/main/license) ©
[Tomer Aberbach](https://github.com/TomerAberbach) \
[Apache 2.0](https://github.com/TomerAberbach/partition-interval/blob/main/license-apache)
© [Google](https://github.com/TomerAberbach/partition-interval/blob/main/notice-apache)