Skip to content

Instantly share code, notes, and snippets.

@tpmccallum
Last active November 22, 2020 01:13
Show Gist options
  • Save tpmccallum/48ef2f600c4364fa88c61fab13208e9a to your computer and use it in GitHub Desktop.
Save tpmccallum/48ef2f600c4364fa88c61fab13208e9a to your computer and use it in GitHub Desktop.
function isSubset(haystack, needle) {
return new Promise(function(resolve, reject) {
let n = haystack.length;
let m = needle.length;
for (let i = 0, j = 0; i < n; i++) {
if (haystack[i] === needle[j++]) {
if (j >= m) resolve("Present");
} else j = 0
}
resolve("Absent");
});
}
var buffer_1 = new ArrayBuffer(50000);
var buffer_2 = new ArrayBuffer(1000000);
var needle = new Uint8Array(buffer_1);
var haystack = new Uint8Array(buffer_2);
needle.fill(111);
haystack.fill(222);
if (needle_length < 1 || needle_length > haystack_length) {
alert("Needle length must be greater than zero and less than haystack length");
} else {
isSubset(haystack, needle)
.then(function(result) {
console.log("Result: " + result);
})
.catch(function() {
console.log("Error");
});
}
@tpmccallum
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment