Skip to content

Instantly share code, notes, and snippets.

@ZakriaJanjua
Created January 30, 2022 12:19
Show Gist options
  • Save ZakriaJanjua/ac1137631572d191e3e1b5c93b5dae18 to your computer and use it in GitHub Desktop.
Save ZakriaJanjua/ac1137631572d191e3e1b5c93b5dae18 to your computer and use it in GitHub Desktop.
Robor Coding Challenge Q1.
s1 = "abcd"
s2 = "abdc"
function isChild(str1, str2) {
let result = []
let count = 0
for (let i = 0; i < str1.length; i++) {
if (str1[i] === str2[count]) {
result.push(str2[count])
count++
} else {
while((str1[i] !== str2[count]) && (str2[count] !== undefined)) {
count++
}
if (str1[i] === str2[count]) {
result.push(str2[count])
}
}
}
return result.length
}
console.log(isChild(s1, s2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment