diff --git a/README.md b/README.md index 672a325..2f18dde 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Finds degree of similarity between two strings, based on [Dice's Coefficient](ht * [Release Notes](#release-notes) * [2.0.0](#200) * [3.0.0](#300) + * [3.0.1](#301) ## Usage @@ -119,6 +120,9 @@ stringSimilarity.findBestMatch('Olive-green table for sale, in extremely good co * The algorithm has been tweaked slightly to disregard spaces and word boundaries. This will change the rating values slightly but not enough to make a significant difference * Adding a `bestMatchIndex` to the results for `findBestMatch(..)` to point to the best match in the supplied `targetStrings` array +### 3.0.1 +* Refactoring: removed unused functions; used `substring` instead of `substr` +* Updated dependencies ![Build status](https://codeship.com/projects/2aa453d0-0959-0134-8a76-4abcb29fe9b4/status?branch=master) [![Known Vulnerabilities](https://snyk.io/test/github/aceakash/string-similarity/badge.svg)](https://snyk.io/test/github/aceakash/string-similarity) diff --git a/compare-strings.js b/compare-strings.js index 9cb5c44..094d8c2 100644 --- a/compare-strings.js +++ b/compare-strings.js @@ -15,7 +15,7 @@ function compareTwoStrings(first, second) { let firstBigrams = new Map(); for (let i = 0; i < first.length - 1; i++) { - const bigram = first.substr(i, 2); + const bigram = first.substring(i, i + 2); const count = firstBigrams.has(bigram) ? firstBigrams.get(bigram) + 1 : 1; @@ -25,7 +25,7 @@ function compareTwoStrings(first, second) { let intersectionSize = 0; for (let i = 0; i < second.length - 1; i++) { - const bigram = second.substr(i, 2); + const bigram = second.substring(i, i + 2); const count = firstBigrams.has(bigram) ? firstBigrams.get(bigram) : 0; @@ -60,10 +60,6 @@ function findBestMatch(mainString, targetStrings) { return { ratings, bestMatch, bestMatchIndex }; } -function flattenDeep(arr) { - return Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr]; -} - function areArgsValid(mainString, targetStrings) { if (typeof mainString !== 'string') return false; if (!Array.isArray(targetStrings)) return false; @@ -71,14 +67,3 @@ function areArgsValid(mainString, targetStrings) { if (targetStrings.find(s => typeof s !== 'string')) return false; return true; } - -function letterPairs(str) { - const pairs = []; - for (let i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2); - return pairs; -} - -function wordLetterPairs(str) { - const pairs = str.toUpperCase().split(' ').map(letterPairs); - return flattenDeep(pairs); -} diff --git a/package-lock.json b/package-lock.json index 51a12b4..9dab287 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "string-similarity", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -63,19 +63,19 @@ "dev": true }, "jasmine": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.3.1.tgz", - "integrity": "sha512-/vU3/H7U56XsxIXHwgEuWpCgQ0bRi2iiZeUpx7Nqo8n1TpoDHfZhkPIc7CO8I4pnMzYsi3XaSZEiy8cnTfujng==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.4.0.tgz", + "integrity": "sha512-sR9b4n+fnBFDEd7VS2el2DeHgKcPiMVn44rtKFumq9q7P/t8WrxsVIZPob4UDdgcDNCwyDqwxCt4k9TDRmjPoQ==", "dev": true, "requires": { - "glob": "^7.0.6", - "jasmine-core": "~3.3.0" + "glob": "^7.1.3", + "jasmine-core": "~3.4.0" } }, "jasmine-core": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.3.0.tgz", - "integrity": "sha512-3/xSmG/d35hf80BEN66Y6g9Ca5l/Isdeg/j6zvbTYlTzeKinzmaTM4p9am5kYqOmE05D7s1t8FGjzdSnbUbceA==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.4.0.tgz", + "integrity": "sha512-HU/YxV4i6GcmiH4duATwAbJQMlE0MsDIR5XmSVxURxKHn3aGAdbY1/ZJFmVRbKtnLwIxxMJD7gYaPsypcbYimg==", "dev": true }, "minimatch": { diff --git a/package.json b/package.json index ceffcd5..1ab353d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "string-similarity", - "version": "3.0.0", + "version": "3.0.1", "description": "Finds degree of similarity between strings, based on Dice's Coefficient, which is mostly better than Levenshtein distance.", "main": "compare-strings.js", "scripts": { @@ -29,6 +29,6 @@ "author": "Akash Kurdekar (http://untilfalse.com/)", "license": "ISC", "devDependencies": { - "jasmine": "^3.3.0" + "jasmine": "^3.4.0" } }