removeByPosition () function in linked-list.js
keiseiTi opened this issue · 1 comments
keiseiTi commented
The following code is correct.
removeByPosition(position = 0) {
const current = this.get(position);
if (position === 0) {
this.removeFirst();
} else if (position === this.size) {
this.removeLast();
}else if(current) {
current.previous.next = current.next;
current.next.previous = current.previous;
this.size -=1;
}
return current && current.value;
}amejiarosario commented
@yupeilin123 Can give an example where is behaving incorrectly?
I added some tests and it's working as expected. this.size - 1 is needed because the position starts with 0 and the size starts with 1.