A Pen by Dano Manion on CodePen.
Created
December 22, 2019 13:36
-
-
Save danomanion/716822b3cc121b531f5a217046b515c2 to your computer and use it in GitHub Desktop.
Practice
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
// Clear Console | |
console.clear() | |
const myFunct = function (s1, s2) { | |
let longest | |
let shortest | |
let result = "" | |
if (s1.length > s2.length) { | |
longest = s1 | |
shortest = s2 | |
} else { | |
longest = s2 | |
shortest = s1 | |
} | |
longest = longest.split("") | |
shortest = shortest.split("") | |
longest = longest[Symbol.iterator]() | |
shortest = shortest[Symbol.iterator]() | |
var x = longest.next(); | |
var y = shortest.next(); | |
console.log(x) | |
console.log(y) | |
do { | |
if (x.value == y.value) { | |
result += x.value | |
x = longest.next(); | |
y = shortest.next(); | |
} | |
y = shortest.next(); | |
} while (!y.done) | |
console.log(result) | |
} | |
// Log | |
// console.log(myFunct("ABAZDC", "BACBAD")) | |
myFunct("ABAZDC", "BACBAD") // 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