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

@tanishqvyas/dsa

v2.0.1

Published

A simple implementation of Data Structures in JavaScript

Downloads

5

Readme

Data Structures and Algorithms

A simple implementation of most commonly used Data Structures in JavaScript.

Installation

To install the package simply run the below command

npm install @tanishqvyas/dsa

Table of Contents

  1. Singly Linked List
  2. Trie

Singly Linked List

A simple implementation of Singly Linked List that supports the following operations:

  • push(): Adds an element at the end of the linked list.

  • pop(): Removes an element from the end of the linked list and returns it.

  • shift(): Removes an element from the beginning of the linked list and returns it.

  • unshift(): Adds an element in the beginning of the linked list.

  • getMiddle(): Returns the middle node of the linked list. If it does not exists then returns null.

  • display(): Displays the contents of the linked list as strings.

  • reverse(): Reverses the linked list.

Singly Linked List Example

import { SinglyLinkedList } from "@tanishqvyas/dsa"

const mySinglyLinkedList = SinglyLinkedList();

mySinglyLinkedList.push(1);
mySinglyLinkedList.unshift(2);
mySinglyLinkedList.push(3);

mySinglyLinkedList.getMiddle(); // returns 1

mySinglyLinkedList.pop(); // returns 3
mySinglyLinkedList.shift(); // returns 2

mySinglyLinkedList.display(); // shows 2

mySinglyLinkedList.push(1);
mySinglyLinkedList.reverse();

mySinglyLinkedList.display(); // shows 1 2

Trie

A simple implementation of Trie aka Prefix Tree.

  • add(): A method that takes in a string and adds it to the trie

  • delete(): A method that takes in a string and removes it from the Trie. If the string is not present it does nothing.

  • contains(): A method that takes in a string and checks whether it is present in the Trie.

Example of Trie

import { Trie } from "@tanishqvyas/dsa"

const myTrie = new Trie(['apple', 'banana']); // Optionally an array can be passed to prefill the Trie with these words

myTrie.add('Hello');

myTrie.contains('hello'); // false
myTrie.contains('apple'); // true

myTrie.contains('Hello'); // true

myTrie.delete('hello'); // does nothing

myTrie.delete('Hello'); // removes Hello from Trie
myTrie.delete('banana'); // removes banana from Trie

myTrie.contains('Hello'); // false;
myTrie.contains('banana'); // false;
myTrie.contains('apple'); // true;

Contributions

For contributions to this package, please open a PR in @tanishqvyas/dsa Github.