1.0.0 • Published 3 years ago

@datastructures/linked-list v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

@datastructures/linked-list ⛓

Typed with TypeScript npm version

A minimal functional typed implementation of a linked list. 🦄

Linked lists are a linear structure of items. Each item is a seperate object. Each item is made with a relationship to its next item.


Install

yarn add @datastructures/linked-list -D

Usage

import { list } from '@datastructures/linked-list'

const items = [ { name: 'foo',  data: { foo: 'bar'} }, { name: 'bar', data: { biz: 'baz', }}]
const tree = list.create(items)
// output
const arrayList = list.toArray(tree)
// array  [ { name: 'foo',  data: { foo: 'bar'} }, { name: 'bar', data: { biz: 'baz', }}]
// from here feel free to add other testable methods to satify your interviewer 🙋

API

Items

Items are optional objects constructed using an item function. Optionally, to create a list of items, an array of items can be passed into a list.create() method.

name: when adding a list a string is always required

data: a data {object} for containing useful data with a Node

ex: const node = item('foo', { foo: "bar" }); const linkedList = list.create(node)


Methods

create(items) creates a list from an array of items with a name and an optional data {object}

ex: list.create([ { name: 'foo', data: { foo: 'bar'} }, { name: 'bar', data: { biz: 'baz', }}])

toArray(items) creates an array of items with a name and an optional data {object} from a list

ex: list.toArray(someLinkedList)


Data Structures 🦄

Basic. Functional. Typed. Data Structures.

Functional typed data structures offering structure clarity and simplicity.


View other data structures.