Skip to content

Instantly share code, notes, and snippets.

@tpmccallum
Last active November 20, 2020 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpmccallum/02eb723d4daad6b3a7b4eabee09d8c35 to your computer and use it in GitHub Desktop.
Save tpmccallum/02eb723d4daad6b3a7b4eabee09d8c35 to your computer and use it in GitHub Desktop.
function isSubset(_haystack, _needle, _haystack_length, _needle_length) {
return new Promise(function(resolve, reject) {
var i = 0;
var j = 0;
for (i = 0; i < _needle_length; i++) {
for (j = 0; j < _haystack_length; j++) {
if (_needle[i] == _haystack[j]) {
break;
}
}
if (j == _haystack_length) {
resolve("Absent");
}
}
resolve("Present");
});
}
var buffer_1 = new ArrayBuffer(20000);
var buffer_2 = new ArrayBuffer(1000000);
var needle = new Uint8Array(buffer_1);
var haystack = new Uint8Array(buffer_2);
needle.fill(222)
haystack.fill(111)
needle_length = needle.length;
haystack_length = haystack.length;
isSubset(haystack, needle, haystack_length, needle_length)
.then(function(result) {
console.log("Result: " + result);
})
.catch(function() {
console.log("Error");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment