UNPKG

@extra-array/rotate

Version:
54 lines (39 loc) 1.5 kB
Rotates values in array. [:package:](https://www.npmjs.com/package/@extra-array/rotate) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/rotate) [:vhs:](https://asciinema.org/a/332121) [:moon:](https://www.npmjs.com/package/@extra-array/rotate.min) [:scroll:](https://unpkg.com/@extra-array/rotate/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [rotate], [rotate$].<br> > Similar: [repeat], [cycle], [rotate], [reverse]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.rotate(x, [n]); // x: an array // n: rotate amount (+ve: left, -ve: right) ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4]; array.rotate(x, 1); // [ 2, 3, 4, 1 ] array.rotate(x, 2); // [ 3, 4, 1, 2 ] array.rotate(x, -1); // [ 4, 1, 2, 3 ] ``` <br> <br> ## References - [Collections.rotate: Java](https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#rotate(java.util.List,%20int)) - [arr-rotate: @kevva](https://www.npmjs.com/package/arr-rotate) [rotate]: https://github.com/nodef/extra-array/wiki/rotate [rotate$]: https://github.com/nodef/extra-array/wiki/rotate$ [repeat]: https://github.com/nodef/extra-array/wiki/repeat [cycle]: https://github.com/nodef/extra-array/wiki/cycle [reverse]: https://github.com/nodef/extra-array/wiki/reverse