Created
June 6, 2024 19:36
-
-
Save morenoh149/1b600f7c5f05d09a53a76b32b587d20a to your computer and use it in GitHub Desktop.
typesript, dealing with accumulating outside scope
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
/* | |
error | |
Line 6: Char 14: error TS2448: Block-scoped variable 'res' used before its declaration. | |
*/ | |
/* code */ | |
function longestCommonSubsequence(arrays: number[][]): number[] { | |
// have a ptr for each array | |
let res = new Set(); | |
let setA = new Set<number>(arrays[0]); | |
for (let i=1; i < arrays.length; i++) { | |
if (!res) { | |
res = setA; | |
} | |
let setB = new Set<number>(arrays[i]); | |
let res = res.intersection(setB) | |
} | |
console.log(res) | |
// increment each ptr keeping track of any common subsequence | |
return [3] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solution on tsplay https://tsplay.dev/Woe4pN