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
Maintainers
1
Created

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

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 } from "datastructskit";

Linked lists {#linkedlists}

supported methods:
  • add: Adds a new node to the end of the linked list.
  • insert: Inserts a new node at a specified position in the linked list.
  • toArray: Returns an array of all the values in the linked list.
  • has: Returns true if the specified value is found in the linked list, false otherwise.
  • delete: Deletes the node at the specified index in the linked list.

You can then create a new linked list by calling the LinkedList constructor:

const linkedList = new LinkedList("head");

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

The LinkedList 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 {#linkedlist-add}

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

linkedList.add("new tail");
insert {#linkedlist-insert}

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

linkedList.insert(1, "new node");
toArray {#linkedlist-toarray}

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

const values = linkedList.toArray();
has {#linkedlist-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 {#linkedlist-delete}

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

linkedList.delete(1);
Datatypes

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

license

The MIT license, Full license is here

Keywords

FAQs

Last updated on 16 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