Miss any of our Open RFC calls?Watch the recordings here! »

digital-chain

3.6.0 • Public • Published

digital-chain Build Status stable

A linked list implementation

API

Table of Contents

LinkedList

index.js:5-510

a doubly linked list

push

index.js:20-35

push an item to the tail of this list

Parameters

  • item Variant any kind of item can be pushed

Returns ListNode the node wrapping the item, nodes can be used in methods such as remove()

pushAll

index.js:52-65

push all the items at the tail of the list

Parameters

  • args ...any
  • an ...[Variant] array or just arguments to be pushed to the list, the following are equivalent:```js list.pushAll(1, 2, 3) list.pushAll([1, 2], 3) list.pushAll([1, 2, 3])
     

Returns Array<ListNode>

pop

index.js:75-79

remove the tail of this list, if the list has more than 1 node in it, the previous node will become the new tail of the list

Returns Variant the data from the removed tail node or undefined if the list was empty

unshift

index.js:89-104

insert an item at the head of this list

Parameters

  • item Variant any kind of item can be inserted

Returns ListNode

unshiftAll

index.js:121-133

insert all the items at the head of the list

Parameters

  • args ...any
  • an ...[Variant] array or just arguments to be pushed to the list, the following are equivalent:```js list.unshiftAll(1, 2, 3) list.unshiftAll([1, 2], 3) list.unshiftAll([1, 2, 3])
     

Returns Array<ListNode>

shift

index.js:141-145

remove the head of this list, if the list has more than 1 node in it, the next node will become the new head of the list

Returns Variant the data from the removed head node or undefined if the list was empty

remove

index.js:153-199

Remove a node from the list

Parameters

Returns Variant the data contained in the removed node

swap

index.js:212-290

swap the positions of node A and node B inside the list

this method will throw an error if one or more of the arguments is not a Node or not a member of this list

Parameters

Returns Boolean returns true if a swap did occur

sort

index.js:306-318

Parameters

  • comparator function (Node, Node)? override the default comparator with a custom one.```js // default comparator

    function defaultComparator(a, b) {
    	if (b > a) return -1
    if (b < a) return 1
    
    return 0
    }
    
    
    

nodes

index.js:332-334

An ES6 iterator of the nodes in this list, starting from the head

for (let node of list.nodes()) {
    console.log(node.data, node.next)
}

Returns ListNodeIterator

values

index.js:348-350

An ES6 iterator of the values in this list, starting from the head

for (let value of list.values()) {
    console.log(value)
}

Returns ValueIterator

iterator

index.js:364-366

An ES6 iterator of the value and nodes in this list, starting from the head

for (let [data, node] of list) {
    console.log(data === node.data)
}

Returns EntryIterator

reverseIterator

index.js:375-377

An ES6 iterator of the value and nodes in this list, starting from the tail

Returns EntryIterator

findFirst

index.js:388-398

find the first occurrence of this piece of data in the list, equality test is performed using ===

Parameters

  • data Variant data to find

Returns ListNode the first node that contains this data

findAll

index.js:410-423

find all the occurrences of this piece of data in the list, equality test is performed using === this will traverse the entire list

Parameters

  • data Variant data to find

Returns Array<ListNode> an array of nodes that contain this data

findFirstBy

index.js:434-444

finds the first node in the list where the predicate function returns true

Parameters

  • predicate function (Variant) a function that returns true for nodes that should be included in the search results

Returns ListNode the first node that was found

findAllBy

index.js:455-468

finds the all the nodes in the list where the predicate function returns true

Parameters

  • predicate function (Variant) a function that returns true for nodes that should be included in the search results

Returns Array<ListNode> an array of nodes that were found

nodeIterator

index.js:489-498

A functional iterator over the nodes in the list, prefer the new ES6 iteration methods over this

Returns [type]

ListNode

index.js:584-589

a node in the list

Parameters

  • data
  • parent

Install

npm i digital-chain

DownloadsWeekly Downloads

0

Version

3.6.0

License

MIT

Last publish

Collaborators

  • avatar