Last active
November 20, 2020 03:52
-
-
Save tpmccallum/02eb723d4daad6b3a7b4eabee09d8c35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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