From b800f5729c96be527354416148dc26349a606fa8 Mon Sep 17 00:00:00 2001 From: James Walker Date: Tue, 25 Sep 2018 09:26:17 -0400 Subject: [PATCH] ruby - hamming (fixes) use Enumerable.count and unless positive_conditional --- ruby/hamming/hamming.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/ruby/hamming/hamming.rb b/ruby/hamming/hamming.rb index 6d956a5..c891062 100644 --- a/ruby/hamming/hamming.rb +++ b/ruby/hamming/hamming.rb @@ -1,15 +1,7 @@ class Hamming - def self.compute(a, b) - if a.length != b.length - raise ArgumentError - end + def self.compute(strand_one, strand_two) + raise ArgumentError unless strand_one.length == strand_two.length - distance = 0 - 0.upto(a.length - 1) do |i| - if a[i] != b[i] - distance += 1 - end - end - distance + 0.upto(strand_one.length - 1).count {|i| strand_one[i] != strand_two[i] } end end