MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / findSubArray

Function findSubArray

libraries/p5.js:5927–5945  ·  view source on GitHub ↗
(needle, haystack)

Source from the content-addressed store, hash-verified

5925// Finds the position of needle in haystack, or -1 if not there.
5926// Like String.indexOf(), but for arrays.
5927function findSubArray(needle, haystack) {
5928 var needleLength = needle.length;
5929 var limit = haystack.length - needleLength + 1;
5930
5931 loop:
5932 for (var pos = 0; pos < limit; pos++) {
5933 for (; pos < limit; pos++) {
5934 for (var k = 0; k < needleLength; k++) {
5935 if (haystack[pos + k] !== needle[k]) {
5936 continue loop;
5937 }
5938 }
5939
5940 return pos;
5941 }
5942 }
5943
5944 return -1;
5945}
5946
5947function addStringToPool(s, pool) {
5948 var offset = findSubArray(s, pool);

Callers 1

addStringToPoolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected