From 7a2e16d714c4086895258262e9d2d1c2d2ae3e7f Mon Sep 17 00:00:00 2001 From: OLDREDSTONE Date: Sat, 1 Nov 2025 18:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A3=80=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=8E=A5=E5=8F=A3=20#35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/custommethod.md | 5 +++++ script/custommethod-search.js | 31 +++++++++++++++++++++++++++++++ script/custommethod-search.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 script/custommethod-search.js create mode 100644 script/custommethod-search.ts 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 };