We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dd6e29b commit e52f99fCopy full SHA for e52f99f
chapter05/01-Linked-List.js
@@ -107,29 +107,14 @@ function LinkedList() {
107
this.indexOf = function(element){
108
109
var current = head,
110
- index = -1;
+ index = 0;
111
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
+ while (current) {
+ if (element === current.element) {
123
return index;
124
}
125
126
- current = current.next;
127
index++;
128
129
130
- //check last item
131
132
- return index;
+ current = current.next;
133
134
135
return -1;
0 commit comments