Title: String Similarity in JavaScript - Runnable Code Snippet
Open Graph Title: String Similarity in JavaScript - Runnable Code Snippet
X Title: String Similarity in JavaScript - Runnable Code Snippet
Description: Calculate the similarity percentage between two strings based on edit distance. Runnable JavaScript snippet with live execution.
Open Graph Description: Calculate the similarity percentage between two strings based on edit distance. Runnable JavaScript snippet with live execution.
X Description: Calculate the similarity percentage between two strings based on edit distance. Runnable JavaScript snippet with live execution.
Keywords:
Opengraph URL: https://tempercode.dev/snippets/string-similarity-javascript
Domain: tempercode.dev
{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"String Similarity","description":"Calculate the similarity percentage between two strings based on edit distance.","programmingLanguage":"JavaScript","text":"const m = a.length, n = b.length;\nconst dp = Array.from({ length: m + 1 }, (_, i) =>\n Array.from({ length: n + 1 }, (_, j) => i === 0 ? j : j === 0 ? i : 0)\n);\nfor (let i = 1; i <= m; i++) {\n for (let j = 1; j <= n; j++) {\n dp[i][j] = a[i-1] === b[j-1] ? dp[i-1][j-1] : 1 + Math.min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]);\n }\n}\nreturn Math.round((1 - dp[m][n] / Math.max(m, n)) * 100);"}
| theme-color | #0c0d12 |
| color-scheme | dark |
| author | Temper |
| creator | Temper |
| publisher | Temper |
| og:image | https://tempercode.dev/og-image.png |
| og:type | article |
| twitter:card | summary_large_image |
| twitter:image | https://tempercode.dev/og-image.png |
Links:
Viewport: width=device-width, initial-scale=1