UNPKG

@extra-array/cycle

Version:

Gives values that cycle through array.

53 lines (38 loc) 1.45 kB
Gives values that cycle through array. [:package:](https://www.npmjs.com/package/@extra-array/cycle) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/cycle) [:vhs:](https://asciinema.org/a/332037) [:moon:](https://www.npmjs.com/package/@extra-array/cycle.min) [:scroll:](https://unpkg.com/@extra-array/cycle/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [repeat], [cycle], [rotate], [reverse]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.cycle(x, [i], [n]); // x: an array // i: start index (0) // n: number of values (X) ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3]; array.cycle(x, 0, 2); // [ 1, 2 ] array.cycle(x, 0, 4); // [ 1, 2, 3, 1 ] array.cycle(x, 1, 6); // [ 2, 3, 1, 2, 3, 1 ] ``` <br> <br> ## References - [List-Extra.cycle: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#cycle) - [Data.List.cycle: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:cycle) [repeat]: https://github.com/nodef/extra-array/wiki/repeat [cycle]: https://github.com/nodef/extra-array/wiki/cycle [rotate]: https://github.com/nodef/extra-array/wiki/rotate [reverse]: https://github.com/nodef/extra-array/wiki/reverse