Categorize scripts

This commit is contained in:
Tay Yang Shun
2017-09-20 15:29:22 +08:00
parent 2182a70770
commit 671b874b43
16 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,19 @@
function isSubsequence(s, t) {
if (s.length > t.length) {
return false;
}
let matchedLength = 0;
for (let i = 0; i < t.length; i++) {
if (matchedLength < s.length && s[matchedLength] === t[i]) {
matchedLength += 1;
}
}
return matchedLength === s.length;
}
console.log(isSubsequence('abc', 'abcde') === true);
console.log(isSubsequence('abd', 'abcde') === true);
console.log(isSubsequence('abf', 'abcde') === false);
console.log(isSubsequence('abef', 'abcde') === false);
console.log(isSubsequence('abcdef', 'abcde') === false);
console.log(isSubsequence('a', 'abcde') === true);