Skip to content

Commit

Permalink
data validation added(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
varad911 committed May 14, 2019
1 parent 107a1c6 commit 1273c8b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .npmignore
@@ -0,0 +1 @@
lib/
39 changes: 22 additions & 17 deletions lib/index.ts
Expand Up @@ -4,26 +4,31 @@ export function getCoefficient(_string1: string, _string2: string): any {
let _longString: string;
let _intersection = 0;
let _coefficient: number;
_string1 = _string1.toLowerCase();
_string2 = _string2.toLowerCase();
_string1 = _string1.replace(/[^a-z0-9]/g, "");
_string2 = _string2.replace(/[^a-z0-9]/g, "");
if(_string1 && _string2) {
_string1 = _string1.toLowerCase();
_string2 = _string2.toLowerCase();
_string1 = _string1.replace(/[^a-z0-9]/g, "");
_string2 = _string2.replace(/[^a-z0-9]/g, "");

if(_string1.length < _string2.length) {
_shortString = _string1;
_longString = _string2;
} else {
_shortString = _string2;
_longString = _string1;
}

if(_string1.length < _string2.length) {
_shortString = _string1;
_longString = _string2;
} else {
_shortString = _string2;
_longString = _string1;
}

for (var i = 0; i < _shortString.length; i++) {
if(_longString.includes(_shortString[i])){
_intersection++;
for (var i = 0; i < _shortString.length; i++) {
if(_longString.includes(_shortString[i])){
_intersection++;
}
}
_coefficient = _intersection / (Math.sqrt(_longString.length * _shortString.length));
return _coefficient;
} else {
return null;
}
_coefficient = _intersection / (Math.sqrt(_longString.length * _shortString.length));
return _coefficient;

} catch (error) {
return error;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ochiai-string-similarity",
"version": "1.0.0",
"version": "1.0.2",
"description": "Finds measure of similarity between two strings using Ochiai coefficient.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 1273c8b

Please sign in to comment.