-
Notifications
You must be signed in to change notification settings - Fork 2
/
listProper.html
45 lines (45 loc) · 1.08 KB
/
listProper.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Linked List with proper iterator</title>
</head>
<body>
<h1>Linked List with proper iterator</h1>
<script type="application/javascript;version=1.7">
function LinkedList() {
}
LinkedList.prototype = {
add(value) {
const prev = this._tail;
this._tail = {
value
};
if (prev) {
prev.next = this._tail;
} else {
this._head = this._tail;
}
return this;
},
[Symbol.iterator]() {
let current = this._head;
return {
next() {
if (!current) {
return {
done: true
};
}
const {value} = current;
current = current.next;
return {
value
};
}
};
}
};
</script>
</body>
</html>