|
|
@@ -6,12 +6,15 @@ mod tests {
|
|
6
|
6
|
}
|
|
7
|
7
|
}
|
|
8
|
8
|
pub fn hamming_distance(s1: &str, s2: &str) -> Result<usize, String> {
|
|
|
9
|
+ //Check if the given Strings are of different length
|
|
9
|
10
|
if s1.len() != s2.len() {
|
|
10
|
11
|
return Err("Strings must be of equal length!".to_string());
|
|
11
|
12
|
}
|
|
12
|
13
|
let mut dist: usize = 0;
|
|
13
|
14
|
for i in 0..s1.len() {
|
|
|
15
|
+ //Compare each character of the Strings
|
|
14
|
16
|
if s1.chars().nth(i) != s2.chars().nth(i) {
|
|
|
17
|
+ //If they don't match, increment hamming distance
|
|
15
|
18
|
dist += 1
|
|
16
|
19
|
}
|
|
17
|
20
|
}
|