summaryrefslogtreecommitdiff
path: root/src/protein/protein.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-06-25 00:06:43 -0500
committersanine <sanine.not@pm.me>2023-06-25 00:06:43 -0500
commit1fa9872ad4683de387b2594ed25677cf3fd99309 (patch)
tree003cb57e325d6423387deb0de8a3fa3ac79ca56c /src/protein/protein.js
parent9f233aa540f01848fea62f6f5031142c6e96621a (diff)
add protein
Diffstat (limited to 'src/protein/protein.js')
-rw-r--r--src/protein/protein.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/protein/protein.js b/src/protein/protein.js
new file mode 100644
index 0000000..0223203
--- /dev/null
+++ b/src/protein/protein.js
@@ -0,0 +1,10 @@
+const xnor = (a, b) => a === b ? 1 : 0;
+
+export function compare(pa, pb) {
+ if (pa.length !== pb.length) {
+ throw new Error(`attempted to compare proteins with different lengths: ${pa.length} vs ${pb.length}`);
+ }
+ return (1/pa.length) * pa
+ .map((_, i) => xnor(pa[i], pb[i]))
+ .reduce((acc, val) => acc + val, 0)
+}