Skip to content

Commit 5ee64ce

Browse files
committed
Add TSDoc for shortestCommonSupersequence
1 parent 00933a6 commit 5ee64ce

File tree

1 file changed

+22
-0
lines changed
  • packages/interactivity-router/src/assets

1 file changed

+22
-0
lines changed

packages/interactivity-router/src/assets/scs.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* Calculate the Shortest Common Supersequence (SCS) of two sequences.
3+
*
4+
* A supersequence is a sequence that contains both input sequences as subsequences.
5+
* The shortest common supersequence is the shortest possible such sequence.
6+
*
7+
* This implementation uses dynamic programming with a time complexity of O(mn)
8+
* and space complexity of O(mn), where m and n are the lengths of sequences X and Y.
9+
*
10+
* @example
11+
* ```ts
12+
* const seq1 = [1, 3, 5];
13+
* const seq2 = [2, 3, 4];
14+
* const scs = shortestCommonSupersequence(seq1, seq2); // [1, 2, 3, 4, 5]
15+
* ```
16+
*
17+
* @param X The first sequence.
18+
* @param Y The second sequence.
19+
* @param isEqual Optional equality function to compare elements.
20+
* Defaults to strict equality (===).
21+
* @return The shortest common supersequence of X and Y.
22+
*/
123
export function shortestCommonSupersequence< E = unknown >(
224
X: E[],
325
Y: E[],

0 commit comments

Comments
 (0)