Skip to content

Commit e52f99f

Browse files
committed
simplified some methods
1 parent dd6e29b commit e52f99f

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

chapter05/01-Linked-List.js

+4-19
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,14 @@ function LinkedList() {
107107
this.indexOf = function(element){
108108

109109
var current = head,
110-
index = -1;
110+
index = 0;
111111

112-
//check first item
113-
if (element == current.element){
114-
return 0;
115-
}
116-
117-
index++;
118-
119-
//check in the middle of the list
120-
while(current.next){
121-
122-
if (element == current.element){
112+
while (current) {
113+
if (element === current.element) {
123114
return index;
124115
}
125-
126-
current = current.next;
127116
index++;
128-
}
129-
130-
//check last item
131-
if (element == current.element){
132-
return index;
117+
current = current.next;
133118
}
134119

135120
return -1;

0 commit comments

Comments
 (0)