@nodescript/core
Version:
Visual programming language for Browser and Node
46 lines • 1.21 kB
JavaScript
export function eqeqeq(a, B) {
return a === B;
}
export function seqStartsWith(haystack, needle, eq = eqeqeq) {
if (haystack.length < needle.length) {
return false;
}
for (let i = 0; i < needle.length; i++) {
if (!eq(haystack[i], needle[i])) {
return false;
}
}
return true;
}
export function seqEndsWith(haystack, needle, eq = eqeqeq) {
if (haystack.length < needle.length) {
return false;
}
for (let i = 0; i < needle.length; i++) {
const j = haystack.length - needle.length + i;
if (!eq(haystack[j], needle[i])) {
return false;
}
}
return true;
}
export function seqContains(haystack, needle, eq = eqeqeq) {
let start = 0;
while (start <= haystack.length - needle.length) {
let match = true;
for (let i = 0; i < needle.length; i++) {
const hs = haystack[start + i];
const nl = needle[i];
if (!eq(hs, nl)) {
match = false;
start += 1;
break;
}
}
if (match) {
return true;
}
}
return false;
}
//# sourceMappingURL=seq.js.map