Skip to content

Commit 37e3576

Browse files
committed
Add concatenation to toString()
A number of different routes could be taken to print out the list. This change will concatenate the string to print each element on a separate line.
1 parent 87e9c04 commit 37e3576

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

chapter05/01-Linked-List.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function LinkedList() {
138138
string = '';
139139

140140
while (current) {
141-
string = current.element;
141+
string += current.element + (current.next ? '\n' : '');
142142
current = current.next;
143143
}
144144
return string;
@@ -148,4 +148,4 @@ function LinkedList() {
148148
this.print = function(){
149149
console.log(this.toString());
150150
};
151-
}
151+
}

0 commit comments

Comments
 (0)