We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0052337 commit 840635eCopy full SHA for 840635e
src/data-structures/linked-list/LinkedList.js
@@ -133,15 +133,19 @@ export default class LinkedList {
133
return deletedHead;
134
}
135
136
- toString(callback) {
137
- const nodeStrings = [];
+ toArray() {
+ const nodes = [];
138
139
let currentNode = this.head;
140
while (currentNode) {
141
- nodeStrings.push(currentNode.toString(callback));
+ nodes.push(currentNode);
142
currentNode = currentNode.next;
143
144
145
- return nodeStrings.toString();
+ return nodes;
146
+ }
147
+
148
+ toString(callback) {
149
+ return this.toArray().map(node => node.toString(callback)).toString();
150
151
0 commit comments