Skip to content

abhisekp/cyclic-next

Repository files navigation

cyclic-next

npm license github-issues Build Status coveralls codecov commitizen friendly

Finds the cyclic next integer of a given number given the maximum bound.

e.g. Given a maximum bound of 5

   1
 /   \
0     2
 \   /
  4-3

cyclic next of 0 will be 1
cyclic next of 1 will be 2
cyclic next of 3 will be 4
cyclic next of 4 will be 0

Install

# yarn add cyclic-next
npm install --save cyclic-next # npm i -S cyclic-next

API

cyclicNext(
  max: number,
  curr: number = 0,
  inc: number = 1
): number

max - The Maximum number to cycle around {number}
[curr=0] - Current number {number}
[inc=1] - Increment amount {number}
- Return The cyclic next number {number}

Usage

// import { cyclicNext } from 'cyclic-next';
const { cyclicNext } = require('cyclic-next');

cyclicNext(5, 0); //=> 1
cyclicNext(5, 1); //=> 2
cyclicNext(5, 2); //=> 3
cyclicNext(5, 3); //=> 4
cyclicNext(5, 4); //=> 0
cyclicNext(5, 4, 1); //=> 0
cyclicNext(5, 4, 3); //=> 2

Author

Abhisek Pattnaik

License

MIT © Abhisek Pattnaik

Contributing

Contributions are highly welcome! This repo is commitizen friendly — please read about it here.