Struqt is a JavaScript (ES2015) library implementing commonly used data structures.
Its sole dependency is lodash.isequal
, used for deep equality comparison of JavaScript objects.
Install via npm with the following command.
npm install --save struqt
SinglyLinkedList
and DoublyLinkedList
.
list.add(element)
adds a newelement
(of any type) as a node to the list.list.addAll(elements)
inserts each members of anelements
array into list.list.get(index)
returns the node at the givenindex
.list.remove(index)
removes and return the node at a givenindex
.list.removeFirstOccurrence(element)
scans list from left to right and remove and returns the first node holding the givenelement
as data; returns null if none was found.list.removeLastOccurrence(element)
scans list from left to right and remove and returns the last node holding the givenelement
as data; returns null if none was found.list.addAtIndex(index, element)
adds a newelement
in place of the givenindex
in the list.list.addAllAtIndex(index, elements)
inserts each members of anelements
array into list, starting from the givenindex
in it.list.contains(data)
returns a boolean value stating whether or not the list contains a node holding the specifieddata
(uses deep equality comparison).list.shift()
returns and removes thehead
of the list.list.pop()
returns and removes thetail
of the list.list.set(index, element)
replaces the data held by the node at a givenìndex
with the givenelement
.list.clone()
returns a shallow copy of the list.list.toArray()
returns an array of data compiled from the nodes in the list.list.clear()
resets the list.
Documentation for the library can be generated using JSDoc.
Run the following command to dump a small HTML-based documentation in a docs
directory.
npm run doc
Run Mocha/Chai tests with the following command.
npm test
TBA