Socket
Socket
Sign inDemoInstall

datastructskit

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    datastructskit

DataStructuresJSKit is an easy-to-use package that adds essential data structures to your JavaScript code. With support for Typescript.


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
11.8 kB
Created
Weekly downloads
 

Readme

Source

DataStructsKit

The DataStructsKit package provides a simple implementation of a collection of data structure. The package is designed to be lightweight and easy to use, and currently supports the following data structures:

  • linked lists & doubly linked lists

Installation

npm install datastructskit

Usage

To use the DataStructsKit package, simply import the data structure you want to use from the package:

import {
  LinkedListNode,
  LinkedList,
  DoublyLinkedList,
  DoublyLinkedListNode,
} from "datastructskit";

Linked lists & Doubly linked lists

You can create a new linked list(singly) or a doubly linked list by calling the LinkedList or DoublyLinkedList constructor:

const linkedList = new LinkedList("head");
const doublyLinkedList = new DoublyLinkedList("head");

This creates a new linked list with a single node, with the value "head".

The generated list has the following properties:
  • head: A reference to the first node in the linked list.
  • tail: A reference to the last node in the linked list.
  • length: The number of nodes in the linked list.
And the following methods:
add

The add method adds a new node to the end of the linked list.

linkedList.add("new tail");
insert

The insert method inserts a new node at a specified position in the linked list.

linkedList.insert(1, "new node");
toArray

The toArray method returns an array of all the values in the linked list.

const values = linkedList.toArray();
has

The has method returns true if the specified value is found in the linked list, false otherwise.

const hasValue = linkedList.has("new tail");
delete

The delete method deletes the node at the specified index in the linked list.

linkedList.delete(1);
Datatypes

Note that the LinkedList and the DoublyLinkedList support any datatype, and not just strings or numbers. You can use any valid JavaScript datatype as the value for a node in the list.

license

The MIT license, Full license is here

Keywords

FAQs

Last updated on 21 Apr 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc