npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

array-reverser

v1.0.1

Published

Seamlessly reverse arrays or segments with ease

Downloads

1,316

Readme

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