Skip to content

Sets up a counter function that rotates through the range provided by a length property as though it were an array index (i.e., returned values will be between zero and length - 1))

License

Notifications You must be signed in to change notification settings

stevenharderjr/closureCounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

closureCounter

Sets up a counter function that rotates through the range provided by a length property as though it were an array index (i.e., returned values will be between 0 and length - 1))

Examples

const nextIndex = closureCounter(3);

nextIndex(); // 0
nextIndex(); // 1
nextIndex(); // 2
nextIndex(); // 0

const prevIndex = closureCounter(3, -1);

prevIndex(); // 2
prevIndex(); // 1
prevIndex(); // 0
prevIndex(); // 2

const everyOtherIndex = closureCounter(6, 2);

everyOtherIndex(); // 0
everyOtherIndex(); // 2
everyOtherIndex(); // 4
everyOtherIndex(); // 0

About

Sets up a counter function that rotates through the range provided by a length property as though it were an array index (i.e., returned values will be between zero and length - 1))

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published