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

broken vdom indexOf ? #17

Closed
WebReflection opened this issue Sep 12, 2018 · 3 comments
Closed

broken vdom indexOf ? #17

WebReflection opened this issue Sep 12, 2018 · 3 comments
Labels

Comments

@WebReflection
Copy link

The following would log -1 in console, instead of 6:

function indexOf(a, suba, aStart, aEnd, subaStart, subaEnd, eq) {
  var j = subaStart,
    k = -1;
  var subaLen = subaEnd - subaStart + 1;
  while (aStart <= aEnd && aEnd - aStart + 1 >= subaLen) {
    if (eq(a[aStart], suba[j])) {
      if (k < 0) k = aStart;
      j++;
      if (j > subaEnd) return k;
    } else {
      k = -1;
      j = subaStart;
    }
    aStart++;
  }
  return -1;
}

var slong = 'happy cat in the black';
var sshort = 'cat in the';

indexOf(
  slong,
  sshort,
  0,
  slong.length - 1,
  0,
  sshort.length - 1,
  (a, b) => a === b
);

However, with slong = 'cat in the' and sshort = 'in' the result is 4.

The reason is that the char by char parse stops when a match is found but, while keep looping, aEnd - aStart + 1 >= subaLen becomes false so that last part of the string is never checked if the right boundary is not as long as the searched string itself.

Is this meant to behave this way? If that's the case, wouldn't be wiser to call the function halfIndexOf ?

Thanks for any sort of clarification

@WebReflection
Copy link
Author

is this project abandoned ?

@yelouafi
Copy link
Owner

Sorry for the delay. This is much likely a bug. Will checkout

@yelouafi yelouafi added the bug label Sep 16, 2018
@yelouafi
Copy link
Owner

fixed in v0.2.2

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

No branches or pull requests

2 participants