diff --git a/pages/custommethod.md b/pages/custommethod.md index 275c51e..bef412d 100644 --- a/pages/custommethod.md +++ b/pages/custommethod.md @@ -90,6 +90,11 @@ `排位顺序`:同一时间设置多个自定义方法时,你可能需要让这些事件按一定顺序生效,这个时候就需要设置这个参数了。这个参数支持负数,数字越小,事件越早生效。 +## 快捷查询 + + + ## 我知道你还想问什么 你也许会有这种疑问:为什么官方要设置一个“调用自定义方法”,像写代码一样完成一些明明是很成熟的功能和特效?为什么不把它们也做成普通的事件直接添加就好了? diff --git a/script/custommethod-search.js b/script/custommethod-search.js new file mode 100644 index 0000000..c974ca0 --- /dev/null +++ b/script/custommethod-search.js @@ -0,0 +1,31 @@ + + + +const customMethods = [ + { type: 'mod',} +] + +const editDistance = (a, b) => { + if (a.length === 0) return b.length; + if (b.length === 0) return a.length; + const matrix = []; + for (let i = 0; i <= b.length; i++) { + matrix[i] = [i]; + } + for (let j = 0; j <= a.length; j++) { + matrix[0][j] = j; + } + for (let i = 1; i <= b.length; i++) { + for (let j = 1; j <= a.length; j++) { + if (b.charAt(i - 1) === a.charAt(j - 1)) { + matrix[i][j] = matrix[i - 1][j - 1]; + } else { + matrix[i][j] = Math.min( + matrix[i - 1][j - 1] + 1, + Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1), + ); + } + } + } + return matrix[b.length][a.length]; +} diff --git a/script/custommethod-search.ts b/script/custommethod-search.ts new file mode 100644 index 0000000..e0ca680 --- /dev/null +++ b/script/custommethod-search.ts @@ -0,0 +1,32 @@ +class CustomMethods{ + type: "mod"|"surgery"|"comment"|"custom_method"; +} + +function editDistance(a: String, b: String): number { + if (a.length === 0) return b.length; + if (b.length === 0) return a.length; + const matrix: number[][] = []; + for (let i = 0; i <= b.length; i++) { + matrix[i] = [i]; + } + for (let j = 0; j <= a.length; j++) { + matrix[0][j] = j; + } + for (let i = 1; i <= b.length; i++) { + for (let j = 1; j <= a.length; j++) { + if (b.charAt(i - 1) === a.charAt(j - 1)) { + matrix[i][j] = matrix[i - 1][j - 1]; + } else { + matrix[i][j] = Math.min( + matrix[i - 1][j - 1] + 1, + Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1), + ); + } + } + } + return matrix[b.length][a.length]; +} + + + +export { editDistance };