From 1fa9872ad4683de387b2594ed25677cf3fd99309 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 25 Jun 2023 00:06:43 -0500 Subject: add protein --- src/protein/protein.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/protein/protein.js (limited to 'src/protein/protein.js') 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) +} -- cgit v1.2.1