Skip to content

Instantly share code, notes, and snippets.

@danomanion
Created December 22, 2019 13:33
Show Gist options
  • Save danomanion/971a969d78d62dde15dc466aa2eab683 to your computer and use it in GitHub Desktop.
Save danomanion/971a969d78d62dde15dc466aa2eab683 to your computer and use it in GitHub Desktop.
Longest Common Subsequence
// This logic doesn't work.
// Clear Console
console.clear()
const myFunct = function (s1, s2) {
let a1 = s1.split("")
let a2 = s2.split("")
let result = ""
do {
if(a1[0] == a2[0]) {
result += a1[0] // A, B, A
a1.shift(0)
a2.shift(0)
} else {
a2.shift(0) // B, C,
}
} while (a2.length != 0)
console.log(result)
}
// Log
// console.log(myFunct("ABAZDC", "BACBAD"))
myFunct("ABAZDC", "BACBAD1") // ABAD
// My Tests
console.assert(myFunct("ABAZDC", "BACBAD") == "ABAD", '"ABAZDC", "BACBAD" is not ABAD')
// console.assert(myFunct("AGGTAB", "GXTXAYB") == "GTAB", '"AGGTAB", "GXTXAYB" is not GTAB')
// console.assert(myFunct("aaaa", "aa") == "aa", '"aaaaa", "aa" is not aa')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment