AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
let isSubsequence = function(s, t) {
if (s.length === 0) {
return true;
}
let pointer1 = 0;
let pointer2 = 0;
while (pointer1 < s.length && pointer2 < t.length) {
if (t.charAt(pointer2) === s.charAt(pointer1)) {
pointer1++;
}
pointer2++;
}
return pointer1 === s.length;
};