Skip to content

Instantly share code, notes, and snippets.

@ThiefMaster
Last active December 10, 2015 14:28
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 ThiefMaster/4447446 to your computer and use it in GitHub Desktop.
Save ThiefMaster/4447446 to your computer and use it in GitHub Desktop.
Uint8Array.prototype.indexOfMulti = function(searchElements, fromIndex) {
fromIndex = fromIndex || 0;
var index = Array.prototype.indexOf.call(this, searchElements[0], fromIndex);
if(searchElements.length === 1 || index === -1) {
// Not found or no other elements to check
return index;
}
for(var i = index, j = 0; j < searchElements.length && i < this.length; i++, j++) {
if(this[i] !== searchElements[j]) {
return this.indexOfMulti(searchElements, index + 1);
}
}
return (i === index + searchElements.length) ? index : -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment