@wordpress/interactivity-router
Version:
Package that exposes state and actions from the `core/router` store, part of the Interactivity API.
32 lines (31 loc) • 865 B
JavaScript
// packages/interactivity-router/src/assets/scs.ts
function shortestCommonSupersequence(X, Y, isEqual = (a, b) => a === b) {
const m = X.length;
const n = Y.length;
const dp = Array.from(
{ length: m + 1 },
() => Array(n + 1).fill(null)
);
for (let i = 0; i <= m; i++) {
dp[i][0] = X.slice(0, i);
}
for (let j = 0; j <= n; j++) {
dp[0][j] = Y.slice(0, j);
}
for (let i = 1; i <= m; i++) {
for (let j = 1; j <= n; j++) {
if (isEqual(X[i - 1], Y[j - 1])) {
dp[i][j] = dp[i - 1][j - 1].concat(X[i - 1]);
} else {
const option1 = dp[i - 1][j].concat(X[i - 1]);
const option2 = dp[i][j - 1].concat(Y[j - 1]);
dp[i][j] = option1.length <= option2.length ? option1 : option2;
}
}
}
return dp[m][n];
}
export {
shortestCommonSupersequence
};
//# sourceMappingURL=scs.mjs.map