Given two sorted arrays check if one is subset of another Question: Given two sorted arrays A1 and A2, check if A2 is a subset of A1. Also, assume there might be duplicates. 
Example: 
 A1 = [0,0,0,0,1], A2 = [0,1] // should return true 
 A1 = [-1,0,1,2,3,4,5], A2 = [1,2,3] // should return true

Answer: My answer is below and works, but I believe my running time is slow. Not sure if there is another algorithm I can leverage.

FYI: this is not for school or project, just curious with solving problems.

function isSubArrayOfAnother(a1, a2) {
        if (!a1 || !a2 || a1.length === 0 || a2.length === 0) { 
            return false;
        }

    let loc = a1.indexOf(a2[0]);
    let allIndexes = [];

    while(loc &gt; -1) {
        allIndexes.push(loc);
        loc = a1.indexOf(a2[0], loc + 1);
    }

    for(var i=0; i&lt;allIndexes.length; i++) {
        let isMatch = true;
        let tempIndex = allIndexes[i];
        for (var j = 0; j&lt; a2.length; j++) {
            if (a2[j] !== a1[tempIndex++]) {
                isMatch = false;
                break;
            }
        }
        if (isMatch)
            return isMatch
    }
    return false;

}
There is a O(n) solution to this.  

Finding all possible start index of the subset can be eliminated

while(loc &gt; -1) {
    allIndexes.push(loc);
    loc = a1.indexOf(a2[0], loc + 1);
}


And, there seems to be an edge case where it will attempt to access element out of the array's bounds. I mean, the input like the one below

A1 = [-1, 0, 1, 3, 1, 2], A2 = [1, 2, 3]


The below pseudocode-like is a starting point, there is still optimisations left in this algorithm. 

Given array A, find the presence of sub array B,

matchPointer = 1
for i = 1 to A.length
  if A[i] == B[matchPointer]
    if matchPointer == B.length
      "Subset Found"
    matchPointer = matchPointer + 1
  else
    matchPointer = 1;