Socket
Socket
Sign inDemoInstall

array-reverser

Package Overview
Dependencies
0
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-reverser


Version published
Weekly downloads
282
decreased by-26.94%
Maintainers
0
Created
Weekly downloads
 

Readme

Source

array-reverser CI

Seamlessly reverse arrays or segments with ease

array-reverser is a lightweight, easy-to-use npm package designed to reverse arrays or specific portions of arrays with precision and efficiency. Whether you need to invert the entire array or just a segment, array-reverser handles it effortlessly.

Features

  • Flexible: Reverse entire arrays or specify start and end indices for partial reversal.
  • Type-Safe: Written in TypeScript, providing type safety for TypeScript projects.
  • Error Handling: Robust error handling for invalid inputs and parameters.
  • Immutability: Ensures immutability by returning a new array instance, preserving the original array.
  • Easy to Use: Simple, intuitive API that integrates seamlessly into any project.

Install

npm install array-reverser

Or with yarn:

yarn add array-reverser

Usage

Import array-reverser into your project:

import arrayReverser from "array-reverser";

Reverse an entire array:

const array = [1, 2, 3, 4, 5];
const reversedArray = arrayReverser(array);
console.log(reversedArray);
//=> [5, 4, 3, 2, 1]

Reverse a segment of an array:

const array = [1, 2, 3, 4, 5];
const reversedArray = arrayReverser(array, 1, 4);
console.log(reversedArray);
//=> [1, 4, 3, 2, 5]

Return a new array instance and preserve the original array:

const array = [1, 2, 3, 4, 5];
const reversedArray = arrayReverser(array);

reversedArray[0] = 10; // Mutate the reversed array
console.log(array[0]); //=> 1

API

arrayReverser(array, start?, end?)

array

Type: Array
The array to reverse.

start

Type: number
Default: 0

The index at which to start reversing the array. If not provided, the array will be reversed from the beginning. This index is inclusive and will be included in the reversed array.

end

Type: number
Default: array.length

The index at which to stop reversing the array. This index is exclusive and will not be included in the reversed array. If not provided, defaults to arr.length, and the element at the end index is included in the reversal and the array will be reversed from the start index to the end of the array.

License

MIT © Palash Mondal

Keywords

FAQs

Last updated on 05 Jul 2024

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc