mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Add playground.
This commit is contained in:
parent
0052337df9
commit
840635e613
@ -133,15 +133,19 @@ export default class LinkedList {
|
|||||||
return deletedHead;
|
return deletedHead;
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(callback) {
|
toArray() {
|
||||||
const nodeStrings = [];
|
const nodes = [];
|
||||||
|
|
||||||
let currentNode = this.head;
|
let currentNode = this.head;
|
||||||
while (currentNode) {
|
while (currentNode) {
|
||||||
nodeStrings.push(currentNode.toString(callback));
|
nodes.push(currentNode);
|
||||||
currentNode = currentNode.next;
|
currentNode = currentNode.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeStrings.toString();
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(callback) {
|
||||||
|
return this.toArray().map(node => node.toString(callback)).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user