Skip to content

Instantly share code, notes, and snippets.

class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
@anagram = Array.new
end
def match(candidates)
@alekst
alekst / anagram.rb
Created September 3, 2013 21:51 — forked from shepmaster/anagram.rb
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
@alekst
alekst / anagram
Last active December 22, 2015 05:58
class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
@anagram = Array.new
end
def match(candidates)
candidates.each do |candidate|
@alekst
alekst / count_elements
Created August 29, 2013 13:32
Counts a number of identical elements within an array (word), returns them as a hash (counts). # {"foo" => 2, "bar" => 1}
def word_count
counts = Hash.new(0)
words.each do |word|
counts[word] += 1
end
return counts
end