Given two strings a sequence string and a key string. create a function determine if characters of key appear in order in the sequence string. "arcata" & "cat" or "c1a2t3" & "cat" will return true while "cta" will return false
created a nested loop to create a new str and then compared the new str to the key.
function sequenceSearch(sequence, key) {
var str = "";
for (var i = 0; i < key.length; i++) {
var keyChar = key[i]
for (var j = 0; j < sequence.length; j++) {
var char = sequence[j];
if (char === keyChar) {
if (str.indexOf(char) === -1) {
str += char;
}
}
}
}
return str === key;
}
"c1a2t3" & "cat" should be true but i get false; "cta", "cat" should be false but i get true