Skip to content

iterate(start, end) does not behave properly if start == 0 #200

@hhanh00

Description

@hhanh00
let set = new SortedSet([-10, 5])
let iterable = {
  [Symbol.iterator]: () => set.iterate(0, 4)
}
for (const a of iterable) {
  console.log(a)
}

shows -10

This is because of

function Iterator(set, start, end) {
    this.set = set;
    this.prev = null;
    this.end = end;
    if (start) { // <- it is false when start == 0
        var next = this.set.findLeastGreaterThanOrEqual(start);
        if (next) {
            this.set.splay(next.value);
            this.prev = next.getPrevious();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions