# rotate-array

> Rotates the elements of an array in place. Supports rotation in both directions and automatically wraps rotations which are larger than the input array size.

Latest version **1.2.0** (published 2022-08-31) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install rotate-array
pnpm add rotate-array
yarn add rotate-array
bun add rotate-array
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2022-08-31 |
| First published | 2013-11-24 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Christian Tegnér |
| Maintainers | cmtegner |
| Keywords | array, rotate |

## Links

- npm: https://www.npmjs.com/package/rotate-array
- Repository: https://github.com/CMTegner/rotate-array
- Issues: https://github.com/CMTegner/rotate-array/issues
- npm.io page: https://npm.io/package/rotate-array

## Recent versions

- 1.2.0 (latest) — 2022-08-31
- 1.1.0 — 2016-01-02
- 1.0.0 — 2014-05-10
- 0.1.0 — 2013-11-24

## README

# rotate-array

Rotates the elements of an array in place. Supports rotation in both directions and automatically wraps rotations which are larger than the input array size.

[![Build status](https://travis-ci.org/CMTegner/rotate-array.svg)](http://travis-ci.org/CMTegner/rotate-array) [![devDependency status](https://david-dm.org/CMTegner/rotate-array/dev-status.svg)](https://david-dm.org/CMTegner/rotate-array#info=devDependencies) [![NPM version](https://badge.fury.io/js/rotate-array.svg)](https://npmjs.org/package/rotate-array)

[![Browser support](https://ci.testling.com/CMTegner/rotate-array.png)](https://ci.testling.com/CMTegner/rotate-array)

## Installation

```bash
npm i rotate-array
```

### Alternatives
For usage via AMD / `<script>`, download a UMD bundle from [wzrd.in](http://wzrd.in/standalone/rotate-array@latest).

## Usage

```javascript
var rotate = require('rotate-array');
```

## rotate(array, num)

Rotates the array `num` places to the left, i.e. it shifts `num` items out of the array and pushes them back on the end. The reverse is done when `num` is negative. In addition, `rotate` automatically wraps rotations which are larger than `array.length`.

Examples:

```js
var beatles = ['paul', 'john', 'ringo', 'george'];
rotate(beatles, 2);
console.log(beatles); // [ 'ringo', 'george', 'paul', 'john' ]
```

```js
var beatles = ['paul', 'john', 'ringo', 'george'];
rotate(beatles, -3);
console.log(beatles); // [ 'john', 'ringo', 'george', 'paul' ]
```

```js
var beatles = ['paul', 'john', 'ringo', 'george'];
rotate(beatles, 42);
console.log(beatles); // [ 'ringo', 'george', 'paul', 'john' ]
```

## rotate.all(array)

Returns all rotations for the given array. It does not modify the passed in array.

Example:

```js
var beatles = ['paul', 'john', 'ringo', 'george'];
console.log(rotate.all(beatles));
// [ [ 'paul', 'john', 'ringo', 'george' ],
//   [ 'john', 'ringo', 'george', 'paul' ],
//   [ 'ringo', 'george', 'paul', 'john' ],
//   [ 'george', 'paul', 'john', 'ringo' ] ]
```

---
_Source: https://npm.io/package/rotate-array · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
