@thi.ng/dcons
Advanced tools
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.3.0"></a> | ||
# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/dcons@0.2.0...@thi.ng/dcons@0.3.0) (2018-04-22) | ||
### Features | ||
* **dcons:** add asHead()/asTail() ([19f7e76](https://github.com/thi-ng/umbrella/commit/19f7e76)) | ||
<a name="0.2.0"></a> | ||
@@ -8,0 +19,0 @@ # [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/dcons@0.1.19...@thi.ng/dcons@0.2.0) (2018-04-10) |
@@ -52,4 +52,6 @@ import * as api from "@thi.ng/api/api"; | ||
reverse(): this; | ||
asHead(cell: ConsCell<T>): this; | ||
asTail(cell: ConsCell<T>): this; | ||
toString(): any; | ||
toJSON(): T[]; | ||
} |
24
index.js
@@ -436,2 +436,26 @@ "use strict"; | ||
} | ||
asHead(cell) { | ||
if (cell === this.head) { | ||
return this; | ||
} | ||
this.remove(cell); | ||
this.head.prev = cell; | ||
cell.next = this.head; | ||
cell.prev = undefined; | ||
this.head = cell; | ||
this._length++; | ||
return this; | ||
} | ||
asTail(cell) { | ||
if (cell === this.tail) { | ||
return this; | ||
} | ||
this.remove(cell); | ||
this.tail.next = cell; | ||
cell.prev = this.tail; | ||
cell.next = undefined; | ||
this.tail = cell; | ||
this._length++; | ||
return this; | ||
} | ||
toString() { | ||
@@ -438,0 +462,0 @@ let res = []; |
{ | ||
"name": "@thi.ng/dcons", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Comprehensive doubly linked list structure w/ iterator support", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
31368
2.93%531
5.15%