/javascript/hamming/hamming.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var Hamming = {
    compute: function(dna1, dna2) {
        var hamming = 0;
        var i;

        if (dna1.length != dna2.length) {
            throw new Error('DNA strands must be of equal length.');
        }

        for (i=0; i < dna1.length; i++) {
            if (dna1[i] != dna2[i]) {
                hamming++;
            }
        }

        return hamming;
    }
};

module.exports = Hamming;

Comments


You're not logged in right now. Please login via GitHub to comment