Skip to content

Commit

Permalink
Updated readme and return
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGeorg committed May 19, 2021
1 parent 65ed7e4 commit d8a53de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

The trigram-similarity module provides functions and operators for determining the similarity of alphanumeric text based on trigram matching.
This is the JavaScript implementation of Postgres [pg_trgm](https://www.postgresql.org/docs/13/pgtrgm.html) and returns a number that indicates how
similar the two arguments are. The range of the result is zero (indicating that the two strings are completely dissimilar) to one (indicating
similar the two arguments are.

The range of the result is **zero** (indicating that the two strings are completely dissimilar) to **one** (indicating
that the two strings are identical).

If you want to learn more about the concept see [this post](https://stackoverflow.com/a/43158586/1410482).
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { trigram } from '@drorgl/n-gram';
* Two blank spaces are added at the beginning, and one at the end,
* and single spaces are replaced by double ones.
* @param {string} input
* @returns string
* @returns {string}
*/
const convertString = (input = '') => {
if (!input.trim()) return '';
Expand Down Expand Up @@ -41,9 +41,9 @@ const trigramSimilarity = (input1 = '', input2 = '') => {
if (trigrams2.includes(trigramItem)) common.push(trigramItem);
});

if (total.length === 0) return 0;

return common.length / total.length;
return (total.length === 0)
? 0
: common.length / total.length;
};

export default trigramSimilarity;
Expand Down

0 comments on commit d8a53de

Please sign in to comment.