Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bgoodman/rotate-array

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bgoodman/rotate-array

Rotate 1D and 2D arrays by +/- n steps.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

rotate-array

Installation

yarn add @bgoodman/rotate-array

Usage

Import package

import rotateArray from "@bgoodman/rotate-array";

Run tests

yarn test

API

rotateArray

Rotate a 1D or 2D array by n steps. Use n < 0 for left rotations and n > 0 for right rotations.

Throws error if attempting to rotate a jagged array.

rotateArray: <T>(array: Array<T> | Array<Array<T>>, steps: number) => Array<T> | Array<Array<T>>
Example
  • rotate a 1D array right
rotateArray([1,2,3,4], 1)
//[4,1,2,3]
  • Rotate a 1D array left
rotateArray([1,2,3,4], -1)
//[2,3,4,1]
  • Rotate a 2D array right
rotateArray([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], 1)
//([[10,7,4,1], [11,8,5,2], [12,9,6,3]])
  • Rotate a 2D array left
rotateArray([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
//[[3,6,9,12], [2,5,8,11], [1,4,7,10]]

FAQs

Package last updated on 23 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc