Package Exports
- double-linked-list
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (double-linked-list) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Double Linked List
A JavaScript implementation of a double linked list. Much faster than the native JS array if your focus is adding and removing from large data sets.
Slow if you need to randomly access elements from within the data set.
Installation
$ npm install double-linked-list
Use
var LinkedList = require('double-linked-list');
var list = new LinkedList();
Documentation
Method reference
#push
list.push(item);
Add an item to the end of the list.
list.push('one');
list.push('two');
list.push('three');
console.log(list.last()); // 'three'
console.log(list.first()); // 'one'
#unShift
list.unShift(item);
Add an item to the start of the list.
list.unShift('one');
list.unShift('two');
list.unShift('three');
console.log(list.first()); // 'three'
console.log(list.last()); // 'one'
#pop
list.pop();
Remove the item at the end of the list, returning the removed item.
Returns null
if the list is empty.
list.push('one');
list.push('two');
list.push('three');
var item = list.pop();
console.log(item); // 'three'
#shift
list.shift();
Remove the item at the start of the list, returning the removed item.
Returns null
if the list is empty.
list.push('one');
list.push('two');
list.push('three');
var item = list.shift();
console.log(item); // 'one'
#first
list.first();
Returns the item at the start of the list.
Returns null
if the list is empty.
list.push('one');
list.push('two');
list.push('three');
console.log(list.first()); // 'one'
#last
list.last();
Returns the item at the end of the list.
Returns null
if the list is empty.
list.push('one');
list.push('two');
list.push('three');
console.log(list.last()); // 'three'
.length
list.length;
Returns the length of the list.
list.push('one');
list.push('two');
list.push('three');
console.log(list.length); // 3
Changelog
- 1.1.3 - 31/07/2015:
- Add navigation to the README.
- 1.1.2 - 30/07/2015:
- Small change to some errors in the README.
- 1.1.1 - 30/07/2015:
- Add unShift function to the documentation.
- 1.1.0 - 30/07/2015:
- + # unShift
- + # unShift tests
- 1.0.0 - 30/07/2015:
- Rename all function names:
- # add -> # push
- # removeFromStart -> # shift
- # removeFromEnd -> # pop
- # getStart -> # first
- # getEnd -> # last
- Update the README formatting and information within.
- Rename all function names:
- 0.1.1 - 30/07/2015:
- Added git remotes and issues to the package.json.
- 0.1.0 - 30/07/2015:
- Initial implementation with:
- Constructor
- # add
- # removeFromStart
- # removeFromEnd
- # getStart
- # getEnd
- .length
- Passing tests
- Initial implementation with:
- 0.0.0 - 30/07/2015 - Initial publish with no contents.