Skip to content

Shouldn't SortedArray replace elements upon push or unshift if unique? #35

@Swoorup

Description

@Swoorup
interface TimestampedData {
  ts: UTCTimestamp;
}

// @ts-ignore
export class MarketDataArray<T extends TimestampedData> extends SortedArray<T> {
  override unique = true;

  static override compare<T extends TimestampedData>(a: T, b: T): 0 | -1 | 1 {
    if (b.ts == a.ts) return 0;
    else if (b.ts - a.ts > 0) return -1;
    else return 1;
  }
}
const seedData = [{ ts: 0 as UTCTimestamp, value: 1}];
const data = MarketDataArray.from(seedData);
data.push({ ts: 0 as UTCTimestamp, value: 999 }); // value is still 1

If the data is new but is unique by for example timestamp, it appears that there isn't much way around to replacing it using push or unshift?

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