String comparision and string similarity in javascript 1

String comparision and string similarity in javascript

Latest News
4 / 100 SEO Score

JavaScript helps to compare the two different strings. A comparison of strings in java-script is quite an easy task. In java-script string, the operation can be done using the equals to the operator. For example:

var string1 = "this is a text";
var string2 = "this is a text";
sting1 == string2  //true
For strict comparison:
string1 === string2 // true

String similarity:

JavaScript function helps to check the string similarity. For example, is string1 is sealed and string2 is healed. There is a similarity in these two strings. The value of string similarity range from 0 to 1 which indicates the degree of similarity.
For string comparison, first of all, you need to follow a few steps.

step 1:

Include
<script src=”//unpkg.com/string-similarity/umd/string-similarity.min.js”></script>
in head section.

Step 2:

stringSimilarity.compareTwoStrings(‘healed’,’sealed’);
output is 0.8

stringSimilarity.findBestMatch('red table is for sale, in good condition.', [
'For sale: red maruti suzuki, 100 miles',
'For sale: table in very good condition, red in colour.',
'Wanted: bike with at least 5 gears.'
]);

// output

{ ratings:
[ { target: 'For sale: red maruti suzuki, 100 miles',
rating: 0.3125},
{ target: 'For sale: table in very good condition, red in colour.',
rating: 0.64935 },
{ target: 'Wanted: bike with at least 5 gears.',
rating: 0.13114 } ],
bestMatch:
{ target: 'For sale: table in very good condition, red in colour.',
rating: 0.649350 },
bestMatchIndex: 1
}

This is the output so the developer can check the string similarity.

Please follow and like us:
String comparision and string similarity in javascript 2 0
20
fb-share-icon20