This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def word_count | |
counts = Hash.new(0) | |
words.each do |word| | |
counts[word] += 1 | |
end | |
return counts | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnagramTest < MiniTest::Unit::TestCase | |
class Anagram | |
def initialize(word) | |
@word = word | |
@anagram = Array.new | |
end | |
def match(candidates) | |
candidates.each do |candidate| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnagramTest < MiniTest::Unit::TestCase | |
class Anagram | |
def initialize(word) | |
@word = word | |
# If you create the array here, then the results will be | |
# collected over multiple calls to `match`. Not sure if that is | |
# intended or not, so I'll assume it's ok to change. | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnagramTest < MiniTest::Unit::TestCase | |
class Anagram | |
def initialize(word) | |
@word = word | |
@anagram = Array.new | |
end | |
def match(candidates) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DNATest < MiniTest::Unit::TestCase | |
class DNA | |
def initialize(string) | |
@string = string | |
@counts = {"A"=> 0, "T" => 0, "C"=> 0, "G"=> 0} | |
dna_validation | |
end | |
def count(element) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DNATest < MiniTest::Unit::TestCase | |
# You don't have to put your classes inside of the test case, but it | |
# doesn't hurt for these examples | |
class DNA | |
def initialize(string) | |
@string = string | |
# You can provide a default value for hashes. This also avoids | |
# hardcoding the letters here. | |
@counts = Hash.new(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DNATest < MiniTest::Unit::TestCase | |
class DNA | |
def initialize(strand) #initializes the original strand | |
@strand = strand | |
end | |
def hamming_distance(sample) # compares it to sample | |
0 if sample.empty? # returns 0 if sample DNA is empty | |
@strand = split(@strand) # splits the orginal DNA strand into an array | |
sample = split(sample) # splits the sample DNA strand into an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhoneNumberTest < MiniTest::Unit::TestCase | |
class PhoneNumber | |
def initialize(number) | |
@number = number | |
end | |
def number | |
number = @number.gsub(/[^0-9]/i, '') | |
validates(number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):001:0> array = ["a", "b", "c"] | |
=> ["a", "b", "c"] | |
irb(main):002:0> unless array[0] == "b" | |
irb(main):003:1> array << "d" | |
irb(main):004:1> end | |
=> ["a", "b", "c", "d"] | |
irb(main):005:0> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Numeric # converts numbers into letters | |
Alph = ("A".."Z").to_a | |
def alph | |
s, q = "", self | |
(q, r = (q - 1).divmod(26)) && s.prepend(Alph[r]) until q.zero? | |
s | |
end | |
end | |
OlderNewer