Update extramath.js

This commit is contained in:
Namhyeon Go 2022-11-07 01:36:54 +09:00 committed by GitHub
parent 25bedaf938
commit 58bf6b5ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,17 @@ function cos(A, B) {
return similarity;
}
// Cartesian product: https://en.wikipedia.org/wiki/Cartesian_product
function cartesianProduct(arr) {
return arr.reduce(function(a,b){
return a.map(function(x){
return b.map(function(y){
return x.concat([y]);
})
}).reduce(function(a,b){ return a.concat(b) },[])
}, [[]])
}
exports.DTM = DTM;
exports.cos = cos;
exports.measureSimilarity = function(s1, s2) {
@ -52,8 +63,9 @@ exports.measureSimilarity = function(s1, s2) {
var mat = dtm.toArray();
return cos(mat[0], mat[1]);
};
exports.cartesianProduct = cartesianProduct;
exports.VERSIONINFO = "ExtraMath module (extramath.js) version 0.0.3";
exports.VERSIONINFO = "ExtraMath module (extramath.js) version 0.0.4";
exports.AUTHOR = "catswords@protonmail.com";
exports.global = global;
exports.require = global.require;