blob: 0223203ae6f945757f0ed52b36041f2d7f69bd8d (
plain)
1
2
3
4
5
6
7
8
9
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)
}
|