Skip to content

Instantly share code, notes, and snippets.

@morenoh149
Created June 6, 2024 19:36
Show Gist options
  • Save morenoh149/1b600f7c5f05d09a53a76b32b587d20a to your computer and use it in GitHub Desktop.
Save morenoh149/1b600f7c5f05d09a53a76b32b587d20a to your computer and use it in GitHub Desktop.
typesript, dealing with accumulating outside scope
/*
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]
};
@morenoh149
Copy link
Author

solution on tsplay https://tsplay.dev/Woe4pN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment