(a, b)
| 31 | * @returns {number} the similarity as number |
| 32 | */ |
| 33 | const similarity = (a, b) => { |
| 34 | const l = Math.min(a.length, b.length); |
| 35 | let dist = 0; |
| 36 | for (let i = 0; i < l; i++) { |
| 37 | const ca = a.charCodeAt(i); |
| 38 | const cb = b.charCodeAt(i); |
| 39 | dist += Math.max(0, 10 - Math.abs(ca - cb)); |
| 40 | } |
| 41 | return dist; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * Returns the common part and a single char for the difference. |
no outgoing calls
no test coverage detected