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

javascript-stack

v1.4.3

Published

Implementing Stack Data Structure in Javascript

Downloads

176

Readme

npm version license

Javascript Stack

Cerebrum.js logo

Javascript-stack is a package used for implementing Stack Data Structure in Javascript.

Description

This package is a javascript implementation of the dynamic data structure known as a stack. It includes all functions for how a stack works, which includes basic stack functions like push, pop, peek and so on.

In live projects, the usage of stacks is very common because it has a lot of benefits due to feature LIFO(Last in First Out) below are some practical applications of stack data structure.

  • In compilers sometimes function call required to be maintained this could be achieved by stack opertations.

  • We commonly use undo and redo options which could be done by stack easily.

  • In code editors opening and closing of the bracket also could be done using stack.

  • The forward and backward in the browser could be done by the stack.

  • Reversing a word could also be done by stack

Environment:

  • Node.js
  • React.js

Basic Usage

Install with npm :

npm i javascript-stack

Basic usage example below. Note: it does not cover all the available methods, rather just highlights the main functionality to get up and running with this data structure. For a description of all the methods, see the API section.

const Stack = require("javascript-stack");
 
// Create new stack
const stackOne = new Stack();

// Pushing element to the stack
stackOne.push(10); 
stackOne.push(20);

// Getting top element
const topElement = stackOne.peek();

// Removing an element from stack
stackOne.pop();

// Prints all the element in the stack
const stackElements = stackOne.showStack();

API

Available methods for a stack instance:

Method Name | Return | Description --- | --- | --- push() | No | Pushes an element to the top of the stack. pop() | No | Removes the last element from the stack. peek() | Yes | Returns the top element of the stack. showStack() | Yes | Prints all the element in the stack. isEmpty() | Yes | Return a boolean value whether the stack is empty or not. size() | Yes | Return the total size of the stack. clear() | No | Clear all the values in the stack. maximumElement() | Yes | Return the maximum integer element in the stack. minimumElement() | Yes | Return the minimum integer element in the stack. toArray() | Yes | Converte the stack into an array. reverseStack() | No | Reverse the stack data. search() | Yes | Check whether value found in the stack. cumilativeSum() | Yes | Return the total sum of the values in a stack. sortStackAsce() | No | This function will sort the array in ascending order. sortStackDesc() | No | This function will sort the array in descending order.

Contributing

If you would like to contribute to this project, take a clone from the main branch and create a new branch, make your changes, and raise a pull request to the main branch by describing the changes. Our team will review the changes and merge them into the main branch.

License

MIT © Krishnanunny H