Skip to content

Instantly share code, notes, and snippets.

View abiiranathan's full-sized avatar
🎯
Focusing

Dr. Abiira Nathan abiiranathan

🎯
Focusing
View GitHub Profile
@tomericco
tomericco / cosine_similarity.js
Created January 26, 2019 10:58
Cosine similarity implementation in JS
const str1 = 'This is an example to test cosine similarity between two strings';
const str2 = 'This example is testing cosine similatiry for given two strings';
//
// Preprocess strings and combine words to a unique collection
//
const str1Words = str1.trim().split(' ').map(omitPunctuations).map(toLowercase);
const str2Words = str2.trim().split(' ').map(omitPunctuations).map(toLowercase);
const allWordsUnique = Array.from(new Set(str1Words.concat(str2Words)));