I am developing a custom function that determines whether a specific sequence is present within a given text. Unlike traditional methods that check for substring inclusion, this function does not require the characters to be adjacent. For instance, in the string "Lord Of The Rings," the substrings "LOTR" or "other" should return true as they can be found within the string.
function checkSequence(text, sequence) {
if (text.indexOf(sequence) !== -1){
return true;
}
return false;
}
console.log(checkSequence("lord of the rings", "")); // True
console.log(checkSequence("lord of the rings", "lord")); // True
console.log(checkSequence("lord of the rings", "lens")); // True
console.log(checkSequence("lord of the rings", "other")); // True
console.log(checkSequence("lord of the rings", "l o t r")); // True
console.log(checkSequence("lord of the rings", "Lord")); // False
console.log(checkSequence("lord of the rings", "orks")); // False
console.log(checkSequence("lord of the rings", "z")); // False
However, the typical approach using indexOf() method might give incorrect results when checking for "LOTR" or "something." The code snippet provided showcases some examples I am currently testing with.
Thank you!