How to check if second string is subsequence of first string in TypeScript

1 Answer

0 votes
const stringIsSubsequence = (first: string, second: string) => {
    let i: number = 0;
    let j: number = 0;
   
    while (i < first.length) {
        if (j === second.length) {
            return false;
        }
        if (first[i] === second[j]) {
            i++;
        }
        j++;
    };
   
    return true;
};

const first: string = "type programming";
const second: string = "typescript programming";

console.log(stringIsSubsequence(first, second));



/*
run:

true

*/

 



answered Mar 21, 2024 by avibootz

Related questions

1 answer 84 views
1 answer 121 views
1 answer 92 views
1 answer 91 views
...