Skip to content

Commit 0852027

Browse files
committed
simplified toString method
1 parent 54da31a commit 0852027

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

chapter05/01-Linked-List.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ function LinkedList() {
149149

150150
this.toString = function(){
151151

152-
var current = head,
153-
s = current.element;
152+
var current = head,
153+
string = '';
154154

155-
while(current.next){
155+
while (current) {
156+
string = current.element;
156157
current = current.next;
157-
s += ', ' + current.element;
158158
}
159+
return string;
159160

160-
return s.toString();
161161
};
162162

163163
this.print = function(){

0 commit comments

Comments
 (0)