> outer: for (var i = 0, j = 0; i < nlen; i++) {
> var nch = needle.charCodeAt(i);
> while (j < hlen) {
> if (haystack.charCodeAt(j++) === nch) {
> continue outer;
> }
> }
Oh my god, you can label loops?
> var nch = needle.charCodeAt(i);
> while (j < hlen) {
> if (haystack.charCodeAt(j++) === nch) {
> continue outer;
> }
> }
Oh my god, you can label loops?
I wonder what else is in the JS syntax that I've been missing out on!
Like this
Or rather outer: for (var i = 0, j = 0; i < nlen; i++) {
var nch = needle.charCodeAt(i);
while (j < hlen) {
if (haystack.charCodeAt(j++) === nch) {
continue outer;
}
}
return false;
} function fuzzysearch(needle, haystack) {
var hlen = haystack.length;
var nlen = needle.length;
if (nlen > hlen) return false;
if (nlen === hlen) return needle === haystack;
for (var i = 0, j = 0; i < nlen; ++i, ++j) {
while (j < hlen && needle.charCodeAt(i) !== haystack.charCodeAt(j)) ++j;
if (j === hlen) return false;
}
return true;
}To be honest reasoning about the loop with continue is actually easier than about one without.
break $n;
isn't valid since PHP 5.4