@@ -20,15 +20,13 @@ let LinkedList2 = (function () {
20
20
append ( element ) {
21
21
22
22
let node = new Node ( element ) ,
23
- current ,
24
- _head = this . getHead ( ) ;
23
+ current ;
25
24
26
- if ( _head === null ) { //first node on list
27
- _head = node ;
28
- head . set ( this , _head ) ;
25
+ if ( this . getHead ( ) === null ) { //first node on list
26
+ head . set ( this , node ) ;
29
27
} else {
30
28
31
- current = _head ;
29
+ current = this . getHead ( ) ;
32
30
33
31
//loop the list until find last item
34
32
while ( current . next ) {
@@ -51,16 +49,14 @@ let LinkedList2 = (function () {
51
49
if ( position >= 0 && position <= this . size ( ) ) {
52
50
53
51
let node = new Node ( element ) ,
54
- _head = this . getHead ( ) ,
55
- current = _head ,
52
+ current = this . getHead ( ) ,
56
53
previous ,
57
54
index = 0 ;
58
55
59
56
if ( position === 0 ) { //add on first position
60
57
61
58
node . next = current ;
62
- _head = node ;
63
- head . set ( this , _head ) ;
59
+ head . set ( this , node ) ;
64
60
65
61
} else {
66
62
while ( index ++ < position ) {
@@ -88,15 +84,13 @@ let LinkedList2 = (function () {
88
84
//check for out-of-bounds values
89
85
if ( position > - 1 && position < this . size ( ) ) {
90
86
91
- let _head = this . getHead ( ) ,
92
- current = _head ,
87
+ let current = this . getHead ( ) ,
93
88
previous ,
94
89
index = 0 ;
95
90
96
91
//removing first item
97
92
if ( position === 0 ) {
98
- _head = current . next ;
99
- head . set ( this , _head ) ;
93
+ head . set ( this , current . next ) ;
100
94
} else {
101
95
102
96
while ( index ++ < position ) {
@@ -128,8 +122,7 @@ let LinkedList2 = (function () {
128
122
129
123
indexOf ( element ) {
130
124
131
- let _head = this . getHead ( ) ,
132
- current = _head ,
125
+ let current = this . getHead ( ) ,
133
126
index = 0 ;
134
127
135
128
while ( current ) {
0 commit comments