mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Add playground.
This commit is contained in:
parent
0052337df9
commit
840635e613
@ -133,15 +133,19 @@ export default class LinkedList {
|
||||
return deletedHead;
|
||||
}
|
||||
|
||||
toString(callback) {
|
||||
const nodeStrings = [];
|
||||
toArray() {
|
||||
const nodes = [];
|
||||
|
||||
let currentNode = this.head;
|
||||
while (currentNode) {
|
||||
nodeStrings.push(currentNode.toString(callback));
|
||||
nodes.push(currentNode);
|
||||
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