@corefunc/corefunc
Advanced tools
Comparing version 0.0.71 to 0.0.72
@@ -17,15 +17,15 @@ { | ||
"devDependencies": { | ||
"@babel/core": "7.9.6", | ||
"@babel/core": "7.10.0", | ||
"@babel/plugin-proposal-class-properties": "7.8.3", | ||
"@babel/preset-env": "7.9.6", | ||
"@types/node": "13.13.5", | ||
"@typescript-eslint/eslint-plugin": "2.32.0", | ||
"@typescript-eslint/parser": "2.32.0", | ||
"@babel/preset-env": "7.10.0", | ||
"@types/node": "14.0.5", | ||
"@typescript-eslint/eslint-plugin": "3.0.2", | ||
"@typescript-eslint/parser": "3.0.2", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-eslint": "10.1.0", | ||
"eslint": "7.0.0", | ||
"eslint": "7.1.0", | ||
"eslint-config-prettier": "6.11.0", | ||
"eslint-config-standard": "14.1.1", | ||
"eslint-plugin-import": "2.20.2", | ||
"eslint-plugin-jsdoc": "25.2.0", | ||
"eslint-plugin-jsdoc": "25.4.3", | ||
"eslint-plugin-node": "11.1.0", | ||
@@ -39,3 +39,3 @@ "eslint-plugin-prettier": "3.1.3", | ||
"tslint-config-standard": "9.0.0", | ||
"typescript": "3.8.3" | ||
"typescript": "3.9.3" | ||
}, | ||
@@ -69,3 +69,3 @@ "directories": { | ||
}, | ||
"version": "0.0.71" | ||
"version": "0.0.72" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function stringSimilarity(alpha, beta) { | ||
const strFirst = alpha.replace(/\s+/g, ""); | ||
const strSecond = beta.replace(/\s+/g, ""); | ||
if (!strFirst.length && !strSecond.length) { | ||
return 1; | ||
} | ||
if (!strFirst.length || !strSecond.length) { | ||
return 0; | ||
} | ||
if (strFirst === strSecond) { | ||
return 1; | ||
} | ||
if (strFirst.length === 1 && strSecond.length === 1) { | ||
return 0; | ||
} | ||
if (strFirst.length < 2 || strSecond.length < 2) { | ||
return 0; | ||
} | ||
const firstBigRams = new Map(); | ||
for (let index = 0; index < strFirst.length - 1; index++) { | ||
const bigRam = strFirst.substring(index, index + 2); | ||
const count = firstBigRams.has(bigRam) ? firstBigRams.get(bigRam) + 1 : 1; | ||
firstBigRams.set(bigRam, count); | ||
} | ||
let intersectionSize = 0; | ||
for (let index = 0; index < strSecond.length - 1; index++) { | ||
const bigRam = strSecond.substring(index, index + 2); | ||
const count = firstBigRams.has(bigRam) ? firstBigRams.get(bigRam) : 0; | ||
if (count > 0) { | ||
firstBigRams.set(bigRam, count - 1); | ||
intersectionSize++; | ||
const strFirst = alpha.replace(/\s+/g, ""); | ||
const strSecond = beta.replace(/\s+/g, ""); | ||
if (!strFirst.length && !strSecond.length) { | ||
return 1; | ||
} | ||
} | ||
return (2.0 * intersectionSize) / (strFirst.length + strSecond.length - 2); | ||
if (!strFirst.length || !strSecond.length) { | ||
return 0; | ||
} | ||
if (strFirst === strSecond) { | ||
return 1; | ||
} | ||
if (strFirst.length === 1 && strSecond.length === 1) { | ||
return 0; | ||
} | ||
if (strFirst.length < 2 || strSecond.length < 2) { | ||
return 0; | ||
} | ||
const firstBigRams = new Map(); | ||
for (let index = 0; index < strFirst.length - 1; index++) { | ||
const bigRam = strFirst.substring(index, index + 2); | ||
const count = firstBigRams.has(bigRam) ? firstBigRams.get(bigRam) + 1 : 1; | ||
firstBigRams.set(bigRam, count); | ||
} | ||
let intersectionSize = 0; | ||
for (let index = 0; index < strSecond.length - 1; index++) { | ||
const bigRam = strSecond.substring(index, index + 2); | ||
const count = firstBigRams.has(bigRam) ? firstBigRams.get(bigRam) : 0; | ||
if (count > 0) { | ||
firstBigRams.set(bigRam, count - 1); | ||
intersectionSize++; | ||
} | ||
} | ||
return (2.0 * intersectionSize) / (strFirst.length + strSecond.length - 2); | ||
} | ||
exports.default = stringSimilarity; |
237179
498
7709