to-rotated
Rotate an array by a given number of steps
Last updated 6 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install to-rotated 
SYNC missed versions from official npm registry.

to-rotated

Rotate an array by a given number of steps

Array rotation shifts the elements left or right by a certain number of steps. Elements that move past the end reappear at the beginning. For example, rotating [1, 2, 3, 4, 5] by 2 steps to the right results in [4, 5, 1, 2, 3].

Install

npm install to-rotated

Usage

import toRotated from 'to-rotated';

console.log(toRotated([1, 2, 3, 4, 5], 2));
//=> [4, 5, 1, 2, 3]

console.log(toRotated([1, 2, 3, 4, 5], -2));
//=> [3, 4, 5, 1, 2]

API

toRotated(array, steps)

Returns a new array that is rotated by the given number of steps.

Current Tags

  • 1.0.0                                ...           latest (6 months ago)

1 Versions

  • 1.0.0                                ...           6 months ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE