Skip to content

removeByPosition () function in linked-list.js #14

Closed
@keiseiTi

Description

@keiseiTi

https://github.com/amejiarosario/dsa.js/blob/d4a5037740b6efbd634e222fc645190e4244e40f/src/data-structures/linked-lists/linked-list.js#L225-L236

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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions