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

Bug in iterate function? #34

Closed
mauricedoepke opened this issue May 24, 2019 · 1 comment
Closed

Bug in iterate function? #34

mauricedoepke opened this issue May 24, 2019 · 1 comment

Comments

@mauricedoepke
Copy link

It looks to me like the iterate function contains a bug. If one returns a segment to replace the old one from an Iterator function, every member of the new segment array is added individually to the segments array instead of adding it as a whole:

  newSegments = [];

  for (i = 0; i < segments.length; i++) {
    if (typeof replacements[i] !== 'undefined') {
      for (j = 0; j < replacements[i].length; j++) {
        newSegments.push(replacements[i][j]);
      }
    } else {
      newSegments.push(segments[i]);
    }
  }

  this.segments = newSegments;

Should instead be:

  newSegments = [];

  for (i = 0; i < segments.length; i++) {
    if (typeof replacements[i] !== 'undefined') {
      newSegments.push(replacements[i]);
    } else {
      newSegments.push(segments[i]);
    }
  }

  this.segments = newSegments;

in my opinion.

@puzrin
Copy link
Member

puzrin commented May 24, 2019

Where should be true copy, not reference.

@puzrin puzrin closed this as completed May 24, 2019
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