summaryrefslogtreecommitdiff
path: root/lib/internal/DoublyLinkedList.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/DoublyLinkedList.js')
-rw-r--r--lib/internal/DoublyLinkedList.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/internal/DoublyLinkedList.js b/lib/internal/DoublyLinkedList.js
index 79c3bb5..86c5cfd 100644
--- a/lib/internal/DoublyLinkedList.js
+++ b/lib/internal/DoublyLinkedList.js
@@ -23,7 +23,10 @@ DLL.prototype.removeLink = function(node) {
return node;
}
-DLL.prototype.empty = DLL;
+DLL.prototype.empty = function () {
+ while(this.head) this.shift();
+ return this;
+};
DLL.prototype.insertAfter = function(node, newNode) {
newNode.prev = node;
@@ -60,3 +63,25 @@ DLL.prototype.shift = function() {
DLL.prototype.pop = function() {
return this.tail && this.removeLink(this.tail);
};
+
+DLL.prototype.toArray = function () {
+ var arr = Array(this.length);
+ var curr = this.head;
+ for(var idx = 0; idx < this.length; idx++) {
+ arr[idx] = curr.data;
+ curr = curr.next;
+ }
+ return arr;
+}
+
+DLL.prototype.remove = function (testFn) {
+ var curr = this.head;
+ while(!!curr) {
+ var next = curr.next;
+ if (testFn(curr)) {
+ this.removeLink(curr);
+ }
+ curr = next;
+ }
+ return this;
+}