How to check if second string is subsequence of first string in Node.js

1 Answer

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

const first = "node.js programming";
const second = "node.js programming language";

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




/*
run:

true

*/

 



answered Mar 21, 2024 by avibootz

Related questions

1 answer 121 views
1 answer 117 views
1 answer 211 views
1 answer 123 views
1 answer 128 views
...