@@ -96,8 +96,8 @@ class SinglyLinkedList {
96
96
return oldHead ;
97
97
}
98
98
get ( index ) {
99
- if ( ! this . head || ( index > this . length || index < 0 ) )
100
- throw new IndexError_1 . default ;
99
+ if ( ! this . head || ( index > this . length - 1 || index < 0 ) )
100
+ throw new IndexError_1 . default ( 'list index out of range.' ) ;
101
101
let counter = 0 ;
102
102
let node = this . head ;
103
103
while ( counter < index ) {
@@ -118,8 +118,8 @@ class SinglyLinkedList {
118
118
insert ( value , index , options = { prevEnabled : false } ) {
119
119
if ( ! index )
120
120
return this . push ( value ) ;
121
- if ( index > this . length || index < 0 )
122
- throw new IndexError_1 . default ;
121
+ if ( index > this . length - 1 || index < 0 )
122
+ throw new IndexError_1 . default ( 'list index out of range.' ) ;
123
123
if ( index === 0 )
124
124
return this . unshift ( value ) ;
125
125
if ( index === this . length )
@@ -139,8 +139,8 @@ class SinglyLinkedList {
139
139
return newNode ;
140
140
}
141
141
removeIndex ( index , options = { prevEnabled : false } ) {
142
- if ( index > this . length || index < 0 )
143
- throw new IndexError_1 . default ;
142
+ if ( index > this . length - 1 || index < 0 )
143
+ throw new IndexError_1 . default ( 'list index out of range.' ) ;
144
144
if ( index === 0 )
145
145
return this . shift ( ) ;
146
146
if ( index === this . length - 1 )
@@ -161,7 +161,7 @@ class SinglyLinkedList {
161
161
log ( beginning = 0 , end = this . length - 1 ) {
162
162
if ( ( beginning > this . length - 1 || beginning < 0 )
163
163
|| ( end > this . length - 1 || end < 0 ) )
164
- throw new IndexError_1 . default ;
164
+ throw new IndexError_1 . default ( 'list index out of range.' ) ;
165
165
let node = this . get ( beginning ) ;
166
166
let count = beginning ;
167
167
while ( node ) {
@@ -177,7 +177,7 @@ class SinglyLinkedList {
177
177
toString ( beginning = 0 , end = this . length - 1 ) {
178
178
if ( ( beginning > this . length - 1 || beginning < 0 )
179
179
|| ( end > this . length - 1 || end < 0 ) )
180
- throw new IndexError_1 . default ;
180
+ throw new IndexError_1 . default ( 'list index out of range.' ) ;
181
181
let node = this . get ( beginning ) ;
182
182
while ( node ) {
183
183
console . log ( node . data ) ;
0 commit comments