1 | Rotates values in array.
|
2 | [:package:](https://www.npmjs.com/package/@extra-array/rotate)
|
3 | [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
|
4 | [:running:](https://npm.runkit.com/@extra-array/rotate)
|
5 | [:vhs:](https://asciinema.org/a/332121)
|
6 | [:moon:](https://www.npmjs.com/package/@extra-array/rotate.min)
|
7 | [:scroll:](https://unpkg.com/@extra-array/rotate/)
|
8 | [:newspaper:](https://nodef.github.io/extra-array/)
|
9 | [:blue_book:](https://github.com/nodef/extra-array/wiki/)
|
10 |
|
11 | > Alternatives: [rotate], [rotate$].<br>
|
12 | > Similar: [repeat], [cycle], [rotate], [reverse].
|
13 |
|
14 | > This is part of package [extra-array].
|
15 |
|
16 | [extra-array]: https://www.npmjs.com/package/extra-array
|
17 |
|
18 | <br>
|
19 |
|
20 | ```javascript
|
21 | array.rotate(x, [n]);
|
22 | // x: an array
|
23 | // n: rotate amount (+ve: left, -ve: right)
|
24 | ```
|
25 |
|
26 | ```javascript
|
27 | const array = require("extra-array");
|
28 |
|
29 | var x = [1, 2, 3, 4];
|
30 | array.rotate(x, 1);
|
31 | // [ 2, 3, 4, 1 ]
|
32 |
|
33 | array.rotate(x, 2);
|
34 | // [ 3, 4, 1, 2 ]
|
35 |
|
36 | array.rotate(x, -1);
|
37 | // [ 4, 1, 2, 3 ]
|
38 | ```
|
39 |
|
40 | <br>
|
41 | <br>
|
42 |
|
43 |
|
44 | ## References
|
45 |
|
46 | - [Collections.rotate: Java](https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#rotate(java.util.List,%20int))
|
47 | - [arr-rotate: @kevva](https://www.npmjs.com/package/arr-rotate)
|
48 |
|
49 | [rotate]: https://github.com/nodef/extra-array/wiki/rotate
|
50 | [rotate$]: https://github.com/nodef/extra-array/wiki/rotate$
|
51 | [repeat]: https://github.com/nodef/extra-array/wiki/repeat
|
52 | [cycle]: https://github.com/nodef/extra-array/wiki/cycle
|
53 | [reverse]: https://github.com/nodef/extra-array/wiki/reverse
|