Skip to content

Incorrect length after insert #2

@zyedidia

Description

@zyedidia

The length of a node needs to be recalculated after the second condition in the insert function, at https://github.com/component/rope/blob/master/index.js#L136.

I think it should be this instead:

var leftLength = this._left.length;
if (position < leftLength) {
  this._left.insert(position, value);
} else {
  this._right.insert(position - leftLength, value);
}
this.length = this._left.length + this._right.length;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions