Skip to content

Update operation.#24

Open
karastojko wants to merge 1 commit into
mourner:mainfrom
karastojko:master
Open

Update operation.#24
karastojko wants to merge 1 commit into
mourner:mainfrom
karastojko:master

Conversation

@karastojko

Copy link
Copy Markdown

No description provided.

Comment thread index.js
return this.data[0];
}

update(newValue, criteria) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

update(newValue, criteria) {
    const pos = this.data.findIndex(criteria);
    if (pos < 0) {
        return false;
    }

    this.data[pos] = newValue;
    
    const childPos = (pos << 1) + 1;
    const needsDown = (pos === 0 || (childPos < this.length && this.compare(newValue, this.data[childPos]) > 0));
    
    this[needsDown ? '_down' : '_up'](pos);

    return true;
}
Comment thread index.d.ts
@@ -1,4 +1,5 @@
export declare type Comparator<T> = (a: T, b: T) => number;
export declare type Criteria<T> = (val: T) => boolean;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export declare type Criteria<T> = (val: T) => boolean;
export declare type Criteria<T> = (val: T, index: number, values: T[]) => boolean;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants