montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.1k stars 184 forks source link

SortedArray is not stable #213

Open MiloBem opened 6 years ago

MiloBem commented 6 years ago

Stable SortedArray should always add a new element at the end of the subsequence of elements for which compare to returns 0. It doesn't:

    let a = new SortedArray(null, null, function(a, b) {
        return a.k - b.k;
    });
    a.push({ k: 5, v: "a" });
    a.push({ k: 5, v: "c" });
    a.push({ k: 5, v: "e" });
    console.log("bla:" + JSON.stringify(a.toArray()));

result: [{"k":5,"v":"c"},{"k":5,"v":"e"},{"k":5,"v":"a"}]