Skip to content

Commit 4871716

Browse files
committed
added solution for is subsequence
1 parent 30828ea commit 4871716

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

isSubsequence.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
// write a function which takes in two strings and checks whether the characters in the first string for a subsequence of the characters in the second strind.
22
// In other words, the function should check whether the characters in the first string appear somewhere in the second string without their order changing.
3+
4+
const isSubsequence = (str1, str2) => {
5+
let pointer1 = 0;
6+
let pointer2 = str1.length;
7+
8+
while (pointer2 <= str2.length) {
9+
if (str2.substring(pointer1, pointer2) === str1) return true;
10+
else {
11+
pointer1++;
12+
pointer2++;
13+
}
14+
}
15+
return false;
16+
};

0 commit comments

Comments
 (0)