Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stake.getMax() might be missing something #1

Open
AndrejMitrovic opened this issue May 14, 2019 · 1 comment
Open

Stake.getMax() might be missing something #1

AndrejMitrovic opened this issue May 14, 2019 · 1 comment

Comments

@AndrejMitrovic
Copy link

if (this.getBalance(address) > balance) {

I think this:

 getMax(addresses) {
    let balance = -1;
    let leader = undefined;
    addresses.forEach(address => {
      if (this.getBalance(address) > balance) {
        leader = address;
      }
    });
    return leader;
  }

Should actually be:

 getMax(addresses) {
    let balance = -1;
    let leader = undefined;
    addresses.forEach(address => {
      let address_balance = this.getBalance(address);
      if (address_balance > balance) {
        leader = address;
        balance = address_balance;
      }
    });
    return leader;
  }

Otherwise getMax will just return the last address that has a balance greater than -1.

@kashishkhullar
Copy link
Owner

Create a PR and ill merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants