Created
January 30, 2022 12:19
-
-
Save ZakriaJanjua/ac1137631572d191e3e1b5c93b5dae18 to your computer and use it in GitHub Desktop.
Robor Coding Challenge Q1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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